Ejemplo n.º 1
0
        static void UpdateHintWordsAndSaveIndex(CodeIndexConfiguration config, string[] words, ILog log, int batchSize = -1, bool needSaveIndex = true)
        {
            var totalUpdate = 0;

            log?.Info($"Update hint index start, words count {words.Length}");

            foreach (var word in words)
            {
                var document = new Document
                {
                    new StringField(nameof(CodeWord.Word), word, Field.Store.YES),
                    new StringField(nameof(CodeWord.WordLower), word.ToLowerInvariant(), Field.Store.YES)
                };

                LucenePool.UpdateIndex(config.LuceneIndexForHint, new Lucene.Net.Index.Term(nameof(CodeWord.Word), word), document);

                totalUpdate++;

                if (needSaveIndex && batchSize > 0 && totalUpdate > batchSize)
                {
                    totalUpdate = 0;
                    LucenePool.SaveResultsAndClearLucenePool(config.LuceneIndexForHint);
                }
            }

            if (needSaveIndex && batchSize > 0 && totalUpdate > 0)
            {
                LucenePool.SaveResultsAndClearLucenePool(config.LuceneIndexForHint);
            }

            log?.Info($"Update hint index finished");
        }
Ejemplo n.º 2
0
 static void BuildIndex(CodeIndexConfiguration config, bool triggerMerge, bool applyAllDeletes, List <Document> documents, bool needFlush, ILog log)
 {
     log?.Info($"Build index start, documents count {documents.Count}");
     LucenePool.BuildIndex(config.LuceneIndexForHint, triggerMerge, applyAllDeletes, documents, needFlush);
     LucenePool.SaveResultsAndClearLucenePool(config.LuceneIndexForHint);
     log?.Info($"Build index finished");
 }