本文整理汇总了C#中Lucene.Net.Index.IndexWriter.Optimize方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Index.IndexWriter.Optimize方法的具体用法?C# Lucene.Net.Index.IndexWriter.Optimize怎么用?C# Lucene.Net.Index.IndexWriter.Optimize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了Lucene.Net.Index.IndexWriter.Optimize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
public override void SetUp()
{
base.SetUp();
System.String[] data = new System.String[]{"A 1 2 3 4 5 6", "Z 4 5 6", null, "B 2 4 5 6", "Y 3 5 6", null, "C 3 6", "X 4 5 6"};
index = new RAMDirectory();
IndexWriter writer = new IndexWriter(index, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
for (int i = 0; i < data.Length; i++)
{
Document doc = new Document();
doc.Add(new Field("id", System.Convert.ToString(i), Field.Store.YES, Field.Index.NOT_ANALYZED)); //Field.Keyword("id",String.valueOf(i)));
doc.Add(new Field("all", "all", Field.Store.YES, Field.Index.NOT_ANALYZED)); //Field.Keyword("all","all"));
if (null != data[i])
{
doc.Add(new Field("data", data[i], Field.Store.YES, Field.Index.ANALYZED)); //Field.Text("data",data[i]));
}
writer.AddDocument(doc);
}
writer.Optimize();
writer.Close();
r = IndexReader.Open(index, true);
s = new IndexSearcher(r);
//System.out.println("Set up " + getName());
}
示例2: SetUp
public virtual void SetUp()
{
// Create an index writer.
directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
// oldest doc:
// Add the first document. text = "Document 1" dateTime = Oct 10 03:25:22 EDT 2007
writer.AddDocument(CreateDocument("Document 1", 633275835220000000L));
// Add the second document. text = "Document 2" dateTime = Oct 10 03:25:26 EDT 2007
writer.AddDocument(CreateDocument("Document 2", 633275835260000000L));
// Add the third document. text = "Document 3" dateTime = Oct 11 07:12:13 EDT 2007
writer.AddDocument(CreateDocument("Document 3", 633276835330000000L));
// Add the fourth document. text = "Document 4" dateTime = Oct 11 08:02:09 EDT 2007
writer.AddDocument(CreateDocument("Document 4", 633276865290000000L));
// latest doc:
// Add the fifth document. text = "Document 5" dateTime = Oct 12 13:25:43 EDT 2007
writer.AddDocument(CreateDocument("Document 5", 633277923430000000L));
//// oldest doc:
//// Add the first document. text = "Document 1" dateTime = Oct 10 03:25:22 EDT 2007
//writer.AddDocument(CreateDocument("Document 1", 1192001122000L));
//// Add the second document. text = "Document 2" dateTime = Oct 10 03:25:26 EDT 2007
//writer.AddDocument(CreateDocument("Document 2", 1192001126000L));
//// Add the third document. text = "Document 3" dateTime = Oct 11 07:12:13 EDT 2007
//writer.AddDocument(CreateDocument("Document 3", 1192101133000L));
//// Add the fourth document. text = "Document 4" dateTime = Oct 11 08:02:09 EDT 2007
//writer.AddDocument(CreateDocument("Document 4", 1192104129000L));
//// latest doc:
//// Add the fifth document. text = "Document 5" dateTime = Oct 12 13:25:43 EDT 2007
//writer.AddDocument(CreateDocument("Document 5", 1192209943000L));
writer.Optimize();
writer.Close();
}
示例3: Main
public static void Main(System.String[] args)
{
System.String usage = typeof(IndexFiles) + " <root_directory>";
if (args.Length == 0)
{
System.Console.Error.WriteLine("Usage: " + usage);
System.Environment.Exit(1);
}
System.DateTime start = System.DateTime.Now;
try
{
IndexWriter writer = new IndexWriter("index", new StandardAnalyzer(), true);
IndexDocs(writer, new System.IO.FileInfo(args[0]));
writer.Optimize();
writer.Close();
System.DateTime end = System.DateTime.Now;
System.Console.Out.Write(end.Ticks - start.Ticks);
System.Console.Out.WriteLine(" total milliseconds");
}
catch (System.IO.IOException e)
{
System.Console.Out.WriteLine(" caught a " + e.GetType() + "\n with message: " + e.Message);
}
}
示例4: CreateRandomTerms
public virtual void CreateRandomTerms(int nDocs, int nTerms, double power, Directory dir)
{
int[] freq = new int[nTerms];
for (int i = 0; i < nTerms; i++)
{
int f = (nTerms + 1) - i; // make first terms less frequent
freq[i] = (int) System.Math.Ceiling(System.Math.Pow(f, power));
terms[i] = new Term("f", System.Convert.ToString((char) ('A' + i)));
}
IndexWriter iw = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
for (int i = 0; i < nDocs; i++)
{
Document d = new Document();
for (int j = 0; j < nTerms; j++)
{
if (r.Next(freq[j]) == 0)
{
d.Add(new Field("f", terms[j].Text(), Field.Store.NO, Field.Index.UN_TOKENIZED));
//System.out.println(d);
}
}
iw.AddDocument(d);
}
iw.Optimize();
iw.Close();
}
示例5: SearchFiltered
public void SearchFiltered(IndexWriter writer, Directory directory, Filter filter, bool optimize)
{
try
{
for (int i = 0; i < 60; i++)
{//Simple docs
Document doc = new Document();
doc.Add(new Field(FIELD, i.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
writer.AddDocument(doc);
}
if (optimize)
writer.Optimize();
writer.Close();
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.Add(new TermQuery(new Term(FIELD, "36")), Occur.SHOULD);
IndexSearcher indexSearcher = new IndexSearcher(directory);
ScoreDoc[] hits = indexSearcher.Search(booleanQuery, filter, 1000).ScoreDocs;
Assert.AreEqual(1, hits.Length, "Number of matched documents");
}
catch (System.IO.IOException e)
{
Assert.Fail(e.Message);
}
}
示例6: Main
public static void Main(System.String[] args)
{
System.DateTime start = System.DateTime.Now;
try
{
var writer = new Lucene.Net.Index.IndexWriter(Lucene.Net.Store.FSDirectory.Open(INDEX_DIR),
new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT),
true,
Lucene.Net.Index.IndexWriter.MaxFieldLength.LIMITED);
System.Console.Out.WriteLine("Indexing to directory '" + INDEX_DIR + "'...");
// want to clean up if indexing gets "cancelled"
try {
parse_email_messages(writer);
}
catch (Exception e)
{
System.Console.Out.WriteLine(" caught a " + e.GetType() + "\n with message: " + e.Message);
}
System.Console.Out.WriteLine(System.DateTime.Now.Millisecond - start.Millisecond + "ms inserting docs");
System.Console.Out.WriteLine("Optimizing...");
writer.Optimize();
writer.Close();
System.Console.Out.WriteLine(System.DateTime.Now.Millisecond - start.Millisecond + "ms total");
}
catch (System.IO.IOException e)
{
System.Console.Out.WriteLine(" caught a " + e.GetType() + "\n with message: " + e.Message);
}
}
示例7: TestPhrasePrefix
public virtual void TestPhrasePrefix()
{
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Document doc1 = new Document();
Document doc2 = new Document();
Document doc3 = new Document();
Document doc4 = new Document();
Document doc5 = new Document();
doc1.Add(new Field("body", "blueberry pie", Field.Store.YES, Field.Index.ANALYZED));
doc2.Add(new Field("body", "blueberry strudel", Field.Store.YES, Field.Index.ANALYZED));
doc3.Add(new Field("body", "blueberry pizza", Field.Store.YES, Field.Index.ANALYZED));
doc4.Add(new Field("body", "blueberry chewing gum", Field.Store.YES, Field.Index.ANALYZED));
doc5.Add(new Field("body", "piccadilly circus", Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc1);
writer.AddDocument(doc2);
writer.AddDocument(doc3);
writer.AddDocument(doc4);
writer.AddDocument(doc5);
writer.Optimize();
writer.Close();
IndexSearcher searcher = new IndexSearcher(indexStore);
//PhrasePrefixQuery query1 = new PhrasePrefixQuery();
MultiPhraseQuery query1 = new MultiPhraseQuery();
//PhrasePrefixQuery query2 = new PhrasePrefixQuery();
MultiPhraseQuery query2 = new MultiPhraseQuery();
query1.Add(new Term("body", "blueberry"));
query2.Add(new Term("body", "strawberry"));
System.Collections.ArrayList termsWithPrefix = new System.Collections.ArrayList();
IndexReader ir = IndexReader.Open(indexStore);
// this TermEnum gives "piccadilly", "pie" and "pizza".
System.String prefix = "pi";
TermEnum te = ir.Terms(new Term("body", prefix + "*"));
do
{
if (te.Term().Text().StartsWith(prefix))
{
termsWithPrefix.Add(te.Term());
}
}
while (te.Next());
query1.Add((Term[]) termsWithPrefix.ToArray(typeof(Term)));
query2.Add((Term[]) termsWithPrefix.ToArray(typeof(Term)));
ScoreDoc[] result;
result = searcher.Search(query1, null, 1000).scoreDocs;
Assert.AreEqual(2, result.Length);
result = searcher.Search(query2, null, 1000).scoreDocs;
Assert.AreEqual(0, result.Length);
}
示例8: TestBefore
public virtual void TestBefore()
{
// create an index
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true);
long now = (long) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;
Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
// add time that is in the past
doc.Add(new Field("datefield", Lucene.Net.Documents.DateTools.TimeToString(now - 1000 * 100000, Lucene.Net.Documents.DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.Add(new Field("body", "Today is a very sunny day in New York City", Field.Store.YES, Field.Index.TOKENIZED));
writer.AddDocument(doc);
writer.Optimize();
writer.Close();
IndexSearcher searcher = new IndexSearcher(indexStore);
// filter that should preserve matches
//DateFilter df1 = DateFilter.Before("datefield", now);
RangeFilter df1 = new RangeFilter("datefield", Lucene.Net.Documents.DateTools.TimeToString(now - 2000 * 100000, Lucene.Net.Documents.DateTools.Resolution.MILLISECOND), Lucene.Net.Documents.DateTools.TimeToString(now, Lucene.Net.Documents.DateTools.Resolution.MILLISECOND), false, true);
// filter that should discard matches
//DateFilter df2 = DateFilter.Before("datefield", now - 999999);
RangeFilter df2 = new RangeFilter("datefield", Lucene.Net.Documents.DateTools.TimeToString(0, Lucene.Net.Documents.DateTools.Resolution.MILLISECOND), Lucene.Net.Documents.DateTools.TimeToString(now - 2000 * 100000, Lucene.Net.Documents.DateTools.Resolution.MILLISECOND), true, false);
// search something that doesn't exist with DateFilter
Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));
// search for something that does exists
Query query2 = new TermQuery(new Term("body", "sunny"));
Hits result;
// ensure that queries return expected results without DateFilter first
result = searcher.Search(query1);
Assert.AreEqual(0, result.Length());
result = searcher.Search(query2);
Assert.AreEqual(1, result.Length());
// run queries with DateFilter
result = searcher.Search(query1, df1);
Assert.AreEqual(0, result.Length());
result = searcher.Search(query1, df2);
Assert.AreEqual(0, result.Length());
result = searcher.Search(query2, df1);
Assert.AreEqual(1, result.Length());
result = searcher.Search(query2, df2);
Assert.AreEqual(0, result.Length());
}
示例9: TestBefore
public virtual void TestBefore()
{
// create an index
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
long now = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
Document doc = new Document();
// add time that is in the past
doc.Add(new Field("datefield", DateTools.TimeToString(now - 1000, DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.Add(new Field("body", "Today is a very sunny day in New York City", Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
writer.Optimize();
writer.Close();
IndexSearcher searcher = new IndexSearcher(indexStore, true);
// filter that should preserve matches
//DateFilter df1 = DateFilter.Before("datefield", now);
TermRangeFilter df1 = new TermRangeFilter("datefield", DateTools.TimeToString(now - 2000, DateTools.Resolution.MILLISECOND), DateTools.TimeToString(now, DateTools.Resolution.MILLISECOND), false, true);
// filter that should discard matches
//DateFilter df2 = DateFilter.Before("datefield", now - 999999);
TermRangeFilter df2 = new TermRangeFilter("datefield", DateTools.TimeToString(0, DateTools.Resolution.MILLISECOND), DateTools.TimeToString(now - 2000, DateTools.Resolution.MILLISECOND), true, false);
// search something that doesn't exist with DateFilter
Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));
// search for something that does exists
Query query2 = new TermQuery(new Term("body", "sunny"));
ScoreDoc[] result;
// ensure that queries return expected results without DateFilter first
result = searcher.Search(query1, null, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
result = searcher.Search(query2, null, 1000).ScoreDocs;
Assert.AreEqual(1, result.Length);
// run queries with DateFilter
result = searcher.Search(query1, df1, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
result = searcher.Search(query1, df2, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
result = searcher.Search(query2, df1, 1000).ScoreDocs;
Assert.AreEqual(1, result.Length);
result = searcher.Search(query2, df2, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
}
示例10: SetUp
public virtual void SetUp()
{
// Create an index writer.
directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
for (int i = 0; i < N; i++)
{
writer.AddDocument(CreateDocument(i));
}
writer.Optimize();
writer.Close();
}
示例11: TestBefore
public virtual void TestBefore()
{
// create an index
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true);
long now = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
Document doc = new Document();
// add time that is in the past
doc.Add(Field.Keyword("datefield", DateField.TimeToString(now - 1000)));
doc.Add(Field.Text("body", "Today is a very sunny day in New York City"));
writer.AddDocument(doc);
writer.Optimize();
writer.Close();
IndexSearcher searcher = new IndexSearcher(indexStore);
// filter that should preserve matches
DateFilter df1 = DateFilter.Before("datefield", now);
// filter that should discard matches
DateFilter df2 = DateFilter.Before("datefield", now - 999999);
// search something that doesn't exist with DateFilter
Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));
// search for something that does exists
Query query2 = new TermQuery(new Term("body", "sunny"));
Hits result;
// ensure that queries return expected results without DateFilter first
result = searcher.Search(query1);
Assert.AreEqual(0, result.Length());
result = searcher.Search(query2);
Assert.AreEqual(1, result.Length());
// run queries with DateFilter
result = searcher.Search(query1, df1);
Assert.AreEqual(0, result.Length());
result = searcher.Search(query1, df2);
Assert.AreEqual(0, result.Length());
result = searcher.Search(query2, df1);
Assert.AreEqual(1, result.Length());
result = searcher.Search(query2, df2);
Assert.AreEqual(0, result.Length());
}
示例12: SetUp
public override void SetUp()
{
base.SetUp();
// Create an index writer.
directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
for (int i = 0; i < N; i++)
{
writer.AddDocument(CreateDocument(i));
}
writer.Optimize();
writer.Close();
}
示例13: Main
public static void Main(System.String[] args)
{
System.String usage = typeof(IndexFiles) + " <root_directory>";
if (args.Length == 0)
{
System.Console.Error.WriteLine("Usage: " + usage);
System.Environment.Exit(1);
}
bool tmpBool;
if (System.IO.File.Exists(INDEX_DIR.FullName))
tmpBool = true;
else
tmpBool = System.IO.Directory.Exists(INDEX_DIR.FullName);
if (tmpBool)
{
System.Console.Out.WriteLine("Cannot save index to '" + INDEX_DIR + "' directory, please delete it first");
System.Environment.Exit(1);
}
System.IO.FileInfo docDir = new System.IO.FileInfo(args[0]);
bool tmpBool2;
if (System.IO.File.Exists(docDir.FullName))
tmpBool2 = true;
else
tmpBool2 = System.IO.Directory.Exists(docDir.FullName);
if (!tmpBool2) // || !docDir.canRead()) // {{Aroush}} what is canRead() in C#?
{
System.Console.Out.WriteLine("Document directory '" + docDir.FullName + "' does not exist or is not readable, please check the path");
System.Environment.Exit(1);
}
System.DateTime start = System.DateTime.Now;
try
{
IndexWriter writer = new IndexWriter(FSDirectory.Open(INDEX_DIR), new StandardAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
System.Console.Out.WriteLine("Indexing to directory '" + INDEX_DIR + "'...");
IndexDocs(writer, docDir);
System.Console.Out.WriteLine("Optimizing...");
writer.Optimize();
writer.Close();
System.DateTime end = System.DateTime.Now;
System.Console.Out.WriteLine(end.Millisecond - start.Millisecond + " total milliseconds");
}
catch (System.IO.IOException e)
{
System.Console.Out.WriteLine(" caught a " + e.GetType() + "\n with message: " + e.Message);
}
}
示例14: SetUp
public virtual void SetUp()
{
directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
Document doc = new Document();
doc.Add(Field.Text("Field", "one two three four five"));
writer.AddDocument(doc);
writer.Optimize();
writer.Close();
searcher = new IndexSearcher(directory);
query = new PhraseQuery();
}
示例15: StartServer
private static void StartServer()
{
// construct an index
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true);
Document doc = new Document();
doc.Add(Field.Text("test", "test text"));
writer.AddDocument(doc);
writer.Optimize();
writer.Close();
// publish it
//// LocateRegistry.CreateRegistry(1099); // {{Aroush}}
Lucene.Net.Search.Searchable local = new IndexSearcher(indexStore);
RemoteSearchable impl = new RemoteSearchable(local);
System.Runtime.Remoting.RemotingServices.Marshal(impl, "http://localhost/Searchable");
}