Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 313509a

Browse files
committed
Add ability to control what appears in all index #179
1 parent 5477b21 commit 313509a

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

searchcode.properties.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ log_indexed=false
4444
follow_links=false
4545
deep_guess_files=false
4646
host_name=localhost:8080
47+
index_all_fields=content,filename,filenamereverse,path,interesting
4748
# The below will probably be moved into the settings page at some point in the
4849
# future.
4950
password=Adm1n234

src/main/java/com/searchcode/app/config/Values.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public class Values {
111111
public static final String DEFAULT_HOST_NAME = "localhost:8080";
112112
public static final String DELETE_REPO_AFTER_PROCESS = "delete_repo_after_process";
113113
public static final String DEFAULT_DELETE_REPO_AFTER_PROCESS = "false";
114+
public static final String INDEX_ALL_FIELDS = "index_all_fields";
115+
public static final String DEFAULT_INDEX_ALL_FIELDS = "content,filename,filenamereverse,path,interesting";
114116

115117
// Lucene stored values for indexing / searching
116118
public static final String CONTENTS = "contents";

src/main/java/com/searchcode/app/service/IndexService.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public class IndexService implements IIndexService {
8686
private boolean repoJobExit = false; // Controls if repo indexing jobs should exit instantly
8787
private int codeIndexLinesCount = 0;
8888

89+
private List<String> indexAllFields; // Contains the fields that should be added to the all portion of the index
90+
8991
///////////////////////////////////////////////////////////////////////
9092
// The below store state for when the reindexing + flip should occur
9193
//////////////////////////////////////////////////////////////////////
@@ -115,6 +117,8 @@ public IndexService(Data data, StatsService statsService, SearchCodeLib searchco
115117
this.MAX_INDEX_SIZE = this.helpers.tryParseInt(Properties.getProperties().getProperty(Values.MAXDOCUMENTQUEUESIZE, Values.DEFAULTMAXDOCUMENTQUEUESIZE), Values.DEFAULTMAXDOCUMENTQUEUESIZE);
116118
this.MAX_LINES_INDEX_SIZE = this.helpers.tryParseInt(Properties.getProperties().getProperty(Values.MAXDOCUMENTQUEUELINESIZE, Values.DEFAULTMAXDOCUMENTQUEUELINESIZE), Values.DEFAULTMAXDOCUMENTQUEUELINESIZE);
117119

120+
this.indexAllFields = Arrays.asList(Properties.getProperties().getProperty(Values.INDEX_ALL_FIELDS, Values.DEFAULT_INDEX_ALL_FIELDS).split(","));
121+
118122
// Locations that should never change once class created
119123
this.INDEX_A_LOCATION = Paths.get(Properties.getProperties().getProperty(Values.INDEXLOCATION, Values.DEFAULTINDEXLOCATION) + "/" + Values.INDEX_A);
120124
this.INDEX_B_LOCATION = Paths.get(Properties.getProperties().getProperty(Values.INDEXLOCATION, Values.DEFAULTINDEXLOCATION) + "/" + Values.INDEX_B);
@@ -266,20 +270,33 @@ public Document buildDocument(CodeIndexDocument codeIndexDocument) {
266270
document.add(new SortedSetDocValuesFacetField(Values.SOURCE, codeIndexDocument.getSource()));
267271
}
268272

269-
270273
this.searchcodeLib.addToSpellingCorrector(codeIndexDocument.getContents());
271274

272275
// This is the main pipeline for making code searchable and probably the most important
273276
// part of the indexer codebase
274-
String indexContents = this.searchcodeLib.codeCleanPipeline(codeIndexDocument.getFileName()) + " " +
275-
new StringBuilder(codeIndexDocument.getFileName()).reverse().toString() + " " +
276-
this.searchcodeLib.splitKeywords(codeIndexDocument.getFileName(), true) + " " +
277-
codeIndexDocument.getFileLocationFilename() + " " +
278-
codeIndexDocument.getFileLocation() + " " +
279-
this.searchcodeLib.splitKeywords(codeIndexDocument.getContents(), true) + " " +
280-
this.searchcodeLib.codeCleanPipeline(codeIndexDocument.getContents()) + " " +
281-
this.searchcodeLib.findInterestingKeywords(codeIndexDocument.getContents()) + " " +
282-
this.searchcodeLib.findInterestingCharacters(codeIndexDocument.getContents()).toLowerCase();
277+
StringBuilder indexBuilder = new StringBuilder();
278+
279+
if (this.indexAllFields.contains("filename")) {
280+
indexBuilder.append(this.searchcodeLib.codeCleanPipeline(codeIndexDocument.getFileName())).append(" ");
281+
}
282+
if (this.indexAllFields.contains("filenamereverse")) {
283+
indexBuilder.append(new StringBuilder(codeIndexDocument.getFileName()).reverse().toString()).append(" ");
284+
}
285+
if (this.indexAllFields.contains("path")) {
286+
indexBuilder.append(this.searchcodeLib.splitKeywords(codeIndexDocument.getFileName(), true)).append(" ");
287+
indexBuilder.append(codeIndexDocument.getFileLocationFilename()).append(" ");
288+
indexBuilder.append(codeIndexDocument.getFileLocation()).append(" ");
289+
}
290+
if (this.indexAllFields.contains("content")) {
291+
indexBuilder.append(this.searchcodeLib.splitKeywords(codeIndexDocument.getContents(), true)).append(" ");
292+
indexBuilder.append( this.searchcodeLib.codeCleanPipeline(codeIndexDocument.getContents())).append(" ");
293+
}
294+
if (this.indexAllFields.contains("interesting")) {
295+
indexBuilder.append(this.searchcodeLib.findInterestingKeywords(codeIndexDocument.getContents())).append(" ");
296+
indexBuilder.append(this.searchcodeLib.findInterestingCharacters(codeIndexDocument.getContents())).append(" ");
297+
}
298+
299+
String indexContents = this.searchcodeLib.codeCleanPipeline(indexBuilder.toString());
283300

284301
document.add(new TextField(Values.REPONAME, codeIndexDocument.getRepoName().replace(" ", "_"), Field.Store.YES));
285302
document.add(new TextField(Values.REPO_NAME_LITERAL, this.helpers.replaceForIndex(codeIndexDocument.getRepoName()).toLowerCase(), Field.Store.NO));

0 commit comments

Comments
 (0)