use of com.searchcode.app.util.CodeAnalyzer in project searchcode-server by boyter.
the class CodeIndexer method deleteByReponame.
/**
* Deletes all files that belong to a repository.
* TODO I don't think this clears anything from the facets, which it should
*/
public synchronized void deleteByReponame(String repoName) throws IOException {
Directory dir = FSDirectory.open(Paths.get(Properties.getProperties().getProperty(Values.INDEXLOCATION, Values.DEFAULTINDEXLOCATION)));
Analyzer analyzer = new CodeAnalyzer();
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
IndexWriter writer = new IndexWriter(dir, iwc);
writer.deleteDocuments(new Term(Values.REPONAME, repoName));
writer.close();
}
use of com.searchcode.app.util.CodeAnalyzer in project searchcode-server by boyter.
the class CodeIndexer method indexDocuments.
/**
* Given a queue of documents to index, index them by popping the queue limited to default of 1000 items.
* This method must be synchronized as we have not added any logic to deal with multiple threads writing to the
* index.
* TODO investigate how Lucene deals with multiple writes
*/
public synchronized void indexDocuments(Queue<CodeIndexDocument> codeIndexDocumentQueue) throws IOException {
Directory indexDirectory = FSDirectory.open(this.INDEX_LOCATION);
Directory facetDirectory = FSDirectory.open(this.FACET_LOCATION);
Analyzer analyzer = new CodeAnalyzer();
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
FacetsConfig facetsConfig;
indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
IndexWriter writer = new IndexWriter(indexDirectory, indexWriterConfig);
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(facetDirectory);
try {
CodeIndexDocument codeIndexDocument = codeIndexDocumentQueue.poll();
int count = 0;
while (codeIndexDocument != null) {
Singleton.getLogger().info("Indexing file " + codeIndexDocument.getRepoLocationRepoNameLocationFilename());
this.sharedService.decrementCodeIndexLinesCount(codeIndexDocument.getCodeLines());
facetsConfig = new FacetsConfig();
facetsConfig.setIndexFieldName(Values.LANGUAGENAME, Values.LANGUAGENAME);
facetsConfig.setIndexFieldName(Values.REPONAME, Values.REPONAME);
facetsConfig.setIndexFieldName(Values.CODEOWNER, Values.CODEOWNER);
Document doc = this.buildDocument(codeIndexDocument);
writer.updateDocument(new Term(Values.PATH, codeIndexDocument.getRepoLocationRepoNameLocationFilename()), facetsConfig.build(taxonomyWriter, doc));
count++;
if (count >= INDEX_QUEUE_BATCH_SIZE) {
codeIndexDocument = null;
} else {
codeIndexDocument = codeIndexDocumentQueue.poll();
}
}
} finally {
try {
writer.close();
} finally {
taxonomyWriter.close();
}
Singleton.getLogger().info("Closing writers");
}
}
Aggregations