예제 #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");
        }
예제 #2
0
        public static void UpdateIndex(string luceneIndex, Term term, Document document)
        {
            luceneIndex.RequireNotNullOrEmpty(nameof(luceneIndex));
            term.RequireNotNull(nameof(term));
            document.RequireNotNull(nameof(document));

            LucenePool.UpdateIndex(luceneIndex, term, document);
        }