本文整理汇总了C#中Lucene.Net.Index.IndexWriter.SetMergeFactor方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Index.IndexWriter.SetMergeFactor方法的具体用法?C# Lucene.Net.Index.IndexWriter.SetMergeFactor怎么用?C# Lucene.Net.Index.IndexWriter.SetMergeFactor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了Lucene.Net.Index.IndexWriter.SetMergeFactor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(System.String[] args)
{
try
{
System.DateTime start = System.DateTime.Now;
System.String tempFileName = System.IO.Path.GetTempFileName();
System.String tempDirectory = System.IO.Path.GetDirectoryName(tempFileName);
tempFileName = System.IO.Path.GetFileName(tempFileName);
IndexWriter writer = new IndexWriter(System.IO.Path.Combine(tempDirectory, "luceneTest") + tempFileName + ".idx", new SimpleAnalyzer(), true);
writer.SetMergeFactor(20);
IndexDocs(writer, new System.IO.FileInfo("/tmp"));
writer.Optimize();
writer.Close();
System.DateTime end = System.DateTime.Now;
System.Console.Out.Write(end.Ticks - start.Ticks);
System.Console.Out.WriteLine(" total milliseconds");
System.Diagnostics.Process runtime = System.Diagnostics.Process.GetCurrentProcess();
// System.Console.Out.Write(java.lang.Runtime.freeMemory()); // {{Aroush}} how do we get freeMemory() in .NET?
System.Console.Out.WriteLine(" free memory before gc");
// System.Console.Out.Write(java.lang.Runtime.totalMemory()); // {{Aroush}} how do we get totalMemory() in .NET?
System.Console.Out.WriteLine(" total memory before gc");
System.GC.Collect();
// System.Console.Out.Write(java.lang.Runtime.freeMemory()); // {{Aroush}} how do we get freeMemory() in .NET?
System.Console.Out.WriteLine(" free memory after gc");
// System.Console.Out.Write(java.lang.Runtime.totalMemory()); // {{Aroush}} how do we get totalMemory() in .NET?
System.Console.Out.WriteLine(" total memory after gc");
}
catch (System.Exception e)
{
System.Console.Out.WriteLine(" caught a " + e.GetType() + "\n with message: " + e.Message);
}
}
示例2: GetFullStrings
private IndexSearcher GetFullStrings()
{
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
writer.SetMaxBufferedDocs(4);
writer.SetMergeFactor(97);
for (int i = 0; i < NUM_STRINGS; i++)
{
Document doc = new Document();
System.String num = GetRandomCharString(GetRandomNumber(2, 8), 48, 52);
doc.Add(new Field("tracer", num, Field.Store.YES, Field.Index.NO));
//doc.add (new Field ("contents", Integer.toString(i), Field.Store.NO, Field.Index.ANALYZED));
doc.Add(new Field("string", num, Field.Store.NO, Field.Index.NOT_ANALYZED));
System.String num2 = GetRandomCharString(GetRandomNumber(1, 4), 48, 50);
doc.Add(new Field("string2", num2, Field.Store.NO, Field.Index.NOT_ANALYZED));
doc.Add(new Field("tracer2", num2, Field.Store.YES, Field.Index.NO));
doc.SetBoost(2); // produce some scores above 1.0
writer.SetMaxBufferedDocs(GetRandomNumber(2, 12));
writer.AddDocument(doc);
}
//writer.optimize ();
//System.out.println(writer.getSegmentCount());
writer.Close();
return new IndexSearcher(indexStore);
}
示例3: GetIndex
// create an index of all the documents, or just the x, or just the y documents
private Searcher GetIndex(bool even, bool odd)
{
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
writer.SetMaxBufferedDocs(2);
writer.SetMergeFactor(1000);
for (int i = 0; i < data.Length; ++i)
{
if (((i % 2) == 0 && even) || ((i % 2) == 1 && odd))
{
Document doc = new Document();
doc.Add(new Field("tracer", data[i][0], Field.Store.YES, Field.Index.NO));
doc.Add(new Field("contents", data[i][1], Field.Store.NO, Field.Index.ANALYZED));
if (data[i][2] != null)
doc.Add(new Field("int", data[i][2], Field.Store.NO, Field.Index.NOT_ANALYZED));
if (data[i][3] != null)
doc.Add(new Field("float", data[i][3], Field.Store.NO, Field.Index.NOT_ANALYZED));
if (data[i][4] != null)
doc.Add(new Field("string", data[i][4], Field.Store.NO, Field.Index.NOT_ANALYZED));
if (data[i][5] != null)
doc.Add(new Field("custom", data[i][5], Field.Store.NO, Field.Index.NOT_ANALYZED));
if (data[i][6] != null)
doc.Add(new Field("i18n", data[i][6], Field.Store.NO, Field.Index.NOT_ANALYZED));
if (data[i][7] != null)
doc.Add(new Field("long", data[i][7], Field.Store.NO, Field.Index.NOT_ANALYZED));
if (data[i][8] != null)
doc.Add(new Field("double", data[i][8], Field.Store.NO, Field.Index.NOT_ANALYZED));
if (data[i][9] != null)
doc.Add(new Field("short", data[i][9], Field.Store.NO, Field.Index.NOT_ANALYZED));
if (data[i][10] != null)
doc.Add(new Field("byte", data[i][10], Field.Store.NO, Field.Index.NOT_ANALYZED));
if (data[i][11] != null)
doc.Add(new Field("parser", data[i][11], Field.Store.NO, Field.Index.NOT_ANALYZED));
doc.SetBoost(2); // produce some scores above 1.0
writer.AddDocument(doc);
}
}
//writer.optimize ();
writer.Close();
IndexSearcher s = new IndexSearcher(indexStore);
s.SetDefaultFieldSortScoring(true, true);
return s;
}
示例4: IndexDictionary
/// <summary> Index a Dictionary</summary>
/// <param name="dict">the dictionary to index
/// </param>
/// <throws> IOException </throws>
public virtual void IndexDictionary(Dictionary dict)
{
IndexReader.Unlock(spellindex);
IndexWriter writer = new IndexWriter(spellindex, new WhitespaceAnalyzer(), !IndexReader.IndexExists(spellindex));
writer.SetMergeFactor(300);
writer.SetMaxBufferedDocs(150);
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();
// close reader
reader.Close();
reader = null;
}
示例5: Index
/// <summary> Forms a Lucene index based on the 2 maps.
///
/// </summary>
/// <param name="indexDir">the direcotry where the index should be created
/// </param>
/// <param name="">word2Nums
/// </param>
/// <param name="">num2Words
/// </param>
private static void Index(System.String indexDir, System.Collections.IDictionary word2Nums, System.Collections.IDictionary num2Words)
{
int row = 0;
int mod = 1;
// override the specific index if it already exists
IndexWriter writer = new IndexWriter(indexDir, ana, true);
writer.SetUseCompoundFile(true); // why?
// blindly up these parameters for speed
writer.SetMergeFactor(writer.GetMergeFactor() * 2);
writer.SetMaxBufferedDocs(writer.GetMaxBufferedDocs() * 2);
System.Collections.IEnumerator i1 = word2Nums.Keys.GetEnumerator();
while (i1.MoveNext())
// for each word
{
System.String g = (System.String) i1.Current;
Document doc = new Document();
int n = Index(word2Nums, num2Words, g, doc);
if (n > 0)
{
doc.Add(new Field(F_WORD, g, Field.Store.YES, Field.Index.UN_TOKENIZED));
if ((++row % mod) == 0)
{
o.WriteLine("\trow=" + row + "/" + word2Nums.Count + " doc= " + doc);
mod *= 2;
}
writer.AddDocument(doc);
} // else degenerate
}
o.WriteLine("Optimizing..");
writer.Optimize();
writer.Close();
}
示例6: 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(Dictionary dict, int mergeFactor, int ramMB)
{
lock (modifyCurrentIndexLock)
{
EnsureOpen();
Directory dir = this.spellindex;
IndexWriter writer = new IndexWriter(spellindex, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
writer.SetMergeFactor(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);
}
}