public void Commit() { CodeIndexPool.Commit(); HintIndexPool.Commit(); }
void BuildIndex(bool needCommit, bool triggerMerge, bool applyAllDeletes, List <Document> codeDocuments, HashSet <string> newHintWords, CancellationToken cancellationToken, bool brandNewBuild) { cancellationToken.ThrowIfCancellationRequested(); Log.LogInformation($"{Name}: Build code index start, documents count {codeDocuments.Count}"); Parallel.ForEach( codeDocuments, () => new List <Document>(), (codeDocument, status, documentLists) => { documentLists.Add(codeDocument); return(documentLists); }, documentLists => { if (documentLists.Count > 0) { CodeIndexPool.BuildIndex(documentLists, needCommit, triggerMerge, applyAllDeletes); } }); Log.LogInformation($"{Name}: Build code index finished"); Log.LogInformation($"{Name}: Build {(brandNewBuild ? "brand New" : "exist")} hint index start, documents count {newHintWords.Count}"); if (brandNewBuild) { Parallel.ForEach( newHintWords, () => new List <Document>(), (word, status, documentLists) => { documentLists.Add(new Document { new StringField(nameof(CodeWord.Word), word, Field.Store.YES), new StringField(nameof(CodeWord.WordLower), word.ToLowerInvariant(), Field.Store.YES) }); return(documentLists); }, documentLists => { if (documentLists.Count > 0) { HintIndexPool.BuildIndex(documentLists, needCommit, triggerMerge, applyAllDeletes); } }); } else { Parallel.ForEach(newHintWords, word => { HintIndexPool.UpdateIndex(new Term(nameof(CodeWord.Word), word), new Document { new StringField(nameof(CodeWord.Word), word, Field.Store.YES), new StringField(nameof(CodeWord.WordLower), word.ToLowerInvariant(), Field.Store.YES) }); }); if (needCommit || triggerMerge || applyAllDeletes) { HintIndexPool.Commit(); } } Log.LogInformation($"{Name}: Build hint index finished"); }