| | |
| | | * @param repository
|
| | | * the repository object
|
| | | */
|
| | | protected void index(RepositoryModel model, Repository repository) {
|
| | | private void index(RepositoryModel model, Repository repository) {
|
| | | try {
|
| | | if (shouldReindex(repository)) {
|
| | | // (re)build the entire index
|
| | |
| | | * @return tree
|
| | | * @throws IOException
|
| | | */
|
| | | protected RevTree getTree(final RevWalk walk, final RevCommit commit)
|
| | | private RevTree getTree(final RevWalk walk, final RevCommit commit)
|
| | | throws IOException {
|
| | | final RevTree tree = commit.getTree();
|
| | | if (tree != null) {
|
| | |
| | | * @param repository
|
| | | * @return true of the on-disk index format is different than INDEX_VERSION
|
| | | */
|
| | | protected boolean shouldReindex(Repository repository) {
|
| | | private boolean shouldReindex(Repository repository) {
|
| | | try {
|
| | | FileBasedConfig config = getConfig(repository);
|
| | | config.load();
|
| | |
| | | * @param repository
|
| | | * @return IndexResult
|
| | | */
|
| | | protected IndexResult updateIndex(RepositoryModel model, Repository repository) {
|
| | | private IndexResult updateIndex(RepositoryModel model, Repository repository) {
|
| | | IndexResult result = new IndexResult();
|
| | | try {
|
| | | FileBasedConfig config = getConfig(repository);
|
| | |
| | | Fragmenter fragmenter = new SimpleSpanFragmenter(scorer, fragmentLength);
|
| | |
|
| | | // use an artificial delimiter for the token
|
| | | String termTag = "<!--[";
|
| | | String termTagEnd = "]-->";
|
| | | String termTag = "!!--[";
|
| | | String termTagEnd = "]--!!";
|
| | | SimpleHTMLFormatter formatter = new SimpleHTMLFormatter(termTag, termTagEnd);
|
| | | Highlighter highlighter = new Highlighter(formatter, scorer);
|
| | | highlighter.setTextFragmenter(fragmenter);
|
| | |
| | |
|
| | | if (SearchObjectType.blob == result.type) {
|
| | | // count lines as offset into the content for this fragment
|
| | | int line = StringUtils.countLines(content.substring(0, pos));
|
| | | int line = Math.max(1, StringUtils.countLines(content.substring(0, pos)));
|
| | |
|
| | | // create fragment tag with line number and language
|
| | | String lang = "";
|
| | |
| | | sb.append(tag);
|
| | |
|
| | | // replace the artificial delimiter with html tags
|
| | | String html = fragment.replace(termTag, "<span class=\"highlight\">").replace(termTagEnd, "</span>");
|
| | | String html = StringUtils.escapeForHtml(fragment, false);
|
| | | html = html.replace(termTag, "<span class=\"highlight\">").replace(termTagEnd, "</span>");
|
| | | sb.append(html);
|
| | | sb.append("</pre>");
|
| | | if (i < len - 1) {
|