@@ -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 ));
0 commit comments