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

Commit 35cc0c3

Browse files
authored
Merge pull request #182 from boyter/issue179
Issue179
2 parents 5477b21 + c819c76 commit 35cc0c3

File tree

6 files changed

+35
-11
lines changed

6 files changed

+35
-11
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()));
297+
}
298+
299+
String indexContents = 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));

src/main/java/com/searchcode/app/service/route/AdminRouteService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public Map<String, Object> adminPage(Request request, Response response) {
144144
map.put(Values.FOLLOW_LINKS, Properties.getProperties().getProperty(Values.FOLLOW_LINKS, Values.DEFAULT_FOLLOW_LINKS));
145145
map.put(Values.DEEP_GUESS_FILES, Properties.getProperties().getProperty(Values.DEEP_GUESS_FILES, Values.DEFAULT_DEEP_GUESS_FILES));
146146
map.put(Values.HOST_NAME, Properties.getProperties().getProperty(Values.HOST_NAME, Values.DEFAULT_HOST_NAME));
147+
map.put(Values.INDEX_ALL_FIELDS, Properties.getProperties().getProperty(Values.INDEX_ALL_FIELDS, Values.DEFAULT_INDEX_ALL_FIELDS));
147148

148149

149150
map.put("repoCount", this.getStat("repoCount"));

src/main/resources/spark/template/freemarker/admin.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ default_and_match=${default_and_match}
190190
log_indexed=${log_indexed}
191191
follow_links=${follow_links}
192192
deep_guess_files=${deep_guess_files}
193-
host_name=${host_name}</textarea>
193+
host_name=${host_name}
194+
index_all_fields=${index_all_fields}</textarea>
194195
</div>
195196

196197
<div style="width:100%; display: inline-block;">

src/main/resources/spark/template/freemarker/documentation.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ String myHmac = HmacUtils.hmacSha512Hex(MYPRIVATEKEY, PARAMSTOHMAC);</textarea>
750750
<dd>Boolean value true or false. If set to true when a file is encountered that cannot be classified though naming conventions its keywords will be analysed and a best guess made. This can be CPU heavy or incorrectly classify some files. Defaults to false.</dd>
751751
<dt>host_name</dt>
752752
<dd>String value. Set this to the expected DNS host name for your searchcode server instance. This will allow things like RSS links to work.</dd>
753+
<dt>index_all_fields</dt>
754+
<dd>A list of file content that will be added to the all portion of the index. You could use this to exclude filename or paths. Defaults to index_all_fields=content,filename,filenamereverse,path,interesting</dd>
753755
</dl>
754756
</p>
755757

0 commit comments

Comments
 (0)