本文整理汇总了C#中IndexWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.Close方法的具体用法?C# IndexWriter.Close怎么用?C# IndexWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IndexWriter
的用法示例。
在下文中一共展示了IndexWriter.Close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertAgainstRAMDirectory
/**
* Build a randomish document for both RAMDirectory and MemoryIndex,
* and run all the queries against it.
*/
public void AssertAgainstRAMDirectory()
{
var fooField = new StringBuilder();
var termField = new StringBuilder();
// add up to 250 terms to field "foo"
for (int i = 0; i < random.Next(250); i++)
{
fooField.Append(" ");
fooField.Append(RandomTerm());
}
// add up to 250 terms to field "term"
for (int i = 0; i < random.Next(250); i++)
{
termField.Append(" ");
termField.Append(RandomTerm());
}
var ramdir = new RAMDirectory();
var analyzer = RandomAnalyzer();
var writer = new IndexWriter(ramdir, analyzer,
IndexWriter.MaxFieldLength.UNLIMITED);
var doc = new Document();
var field1 = new Field("foo", fooField.ToString(), Field.Store.NO, Field.Index.ANALYZED);
var field2 = new Field("term", termField.ToString(), Field.Store.NO, Field.Index.ANALYZED);
doc.Add(field1);
doc.Add(field2);
writer.AddDocument(doc);
writer.Close();
var memory = new MemoryIndex();
memory.AddField("foo", fooField.ToString(), analyzer);
memory.AddField("term", termField.ToString(), analyzer);
AssertAllQueries(memory, ramdir, analyzer);
}
示例2: GenerateHighlights
/// <summary>
/// Annotates the given sequence of <see cref="Document"/> objects by adding a <b>_highlight</b> field;
/// the <b>_highlight</b> field will contain the best matching text fragment from the <see cref="Document"/>
/// object's full-text field.
/// </summary>
/// <param name="hits">The sequence of <see cref="Document"/> objects.</param>
/// <param name="criteria">The search criteria that produced the hits.</param>
/// <returns>
/// The original sequence of Document objects, with a <b>_highlight</b> field added to each Document.
/// </returns>
public static IEnumerable<Document> GenerateHighlights(this IEnumerable<Document> hits, SearchCriteria criteria)
{
if (hits == null)
throw new ArgumentNullException(nameof(hits));
if (criteria == null)
throw new ArgumentNullException(nameof(criteria));
if (String.IsNullOrWhiteSpace(criteria.Query))
throw new ArgumentException("SearchCriteria.Query cannot be empty");
var documents = hits.ToList();
try
{
var indexDirectory = new RAMDirectory();
var analyzer = new FullTextAnalyzer();
var config = new IndexWriterConfig(analyzer).SetRAMBufferSizeMB(_ramBufferSizeMB);
var writer = new IndexWriter(indexDirectory, config);
BuidIndex(documents, writer);
GenerateHighlights(documents, writer, criteria);
writer.DeleteAll();
writer.Commit();
writer.Close();
indexDirectory.Close();
}
catch (Exception ex)
{
_log.Error(ex);
}
return documents;
}
示例3: ClearIndex
/// <summary>
/// Removes all terms from the spell check index.
/// </summary>
public virtual void ClearIndex()
{
lock (modifyCurrentIndexLock)
{
EnsureOpen();
Directory dir = this.spellindex;
IndexWriter writer = new IndexWriter(dir, null, true, IndexWriter.MaxFieldLength.UNLIMITED);
writer.Close();
SwapSearcher(dir);
}
}
示例4: IndexDictionary
/// <summary> Index a Dictionary</summary>
/// <param name="dict">the dictionary to index</param>
/// <param name="mergeFactor">mergeFactor to use when indexing</param>
/// <param name="ramMB">the max amount or memory in MB to use</param>
/// <throws> IOException </throws>
/// <throws>AlreadyClosedException if the Spellchecker is already closed</throws>
public virtual void IndexDictionary(IDictionary dict, int mergeFactor, int ramMB)
{
lock (modifyCurrentIndexLock)
{
EnsureOpen();
Directory dir = this.spellindex;
IndexWriter writer = new IndexWriter(spellindex, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
writer.MergeFactor = mergeFactor;
writer.SetMaxBufferedDocs(ramMB);
System.Collections.IEnumerator iter = dict.GetWordsIterator();
while (iter.MoveNext())
{
System.String word = (System.String)iter.Current;
int len = word.Length;
if (len < 3)
{
continue; // too short we bail but "too long" is fine...
}
if (this.Exist(word))
{
// if the word already exist in the gramindex
continue;
}
// ok index the word
Document doc = CreateDocument(word, GetMin(len), GetMax(len));
writer.AddDocument(doc);
}
// close writer
writer.Optimize();
writer.Close();
// also re-open the spell index to see our own changes when the next suggestion
// is fetched:
SwapSearcher(dir);
}
}
示例5: SetSpellIndex
/// <summary>
/// Use a different index as the spell checker index or re-open
/// the existing index if <c>spellIndex</c> is the same value
/// as given in the constructor.
/// </summary>
/// <param name="spellIndexDir">spellIndexDir the spell directory to use </param>
/// <throws>AlreadyClosedException if the Spellchecker is already closed</throws>
/// <throws>IOException if spellchecker can not open the directory</throws>
virtual public void SetSpellIndex(Directory spellIndexDir)
{
// this could be the same directory as the current spellIndex
// modifications to the directory should be synchronized
lock (modifyCurrentIndexLock)
{
EnsureOpen();
if (!IndexReader.IndexExists(spellIndexDir))
{
var writer = new IndexWriter(spellIndexDir, null, true,
IndexWriter.MaxFieldLength.UNLIMITED);
writer.Close();
}
SwapSearcher(spellIndexDir);
}
}