本文整理汇总了C#中Lucene.Net.Search.IndexSearcher类的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Search.IndexSearcher类的具体用法?C# Lucene.Net.Search.IndexSearcher怎么用?C# Lucene.Net.Search.IndexSearcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Lucene.Net.Search.IndexSearcher类属于命名空间,在下文中一共展示了Lucene.Net.Search.IndexSearcher类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestMmapIndex
public virtual void TestMmapIndex()
{
Assert.Ignore("Need to port tests, but we don't really support MMapDirectories anyway");
FSDirectory storeDirectory;
storeDirectory = new MMapDirectory(new System.IO.DirectoryInfo(storePathname), null);
// plan to add a set of useful stopwords, consider changing some of the
// interior filters.
StandardAnalyzer analyzer = new StandardAnalyzer(Util.Version.LUCENE_CURRENT, Support.Compatibility.SetFactory.CreateHashSet<string>());
// TODO: something about lock timeouts and leftover locks.
IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
IndexSearcher searcher = new IndexSearcher(storeDirectory, true);
for (int dx = 0; dx < 1000; dx++)
{
System.String f = RandomField();
Document doc = new Document();
doc.Add(new Field("data", f, Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
}
searcher.Close();
writer.Close();
RmDir(new System.IO.FileInfo(storePathname));
}
开发者ID:Nangal,项目名称:lucene.net,代码行数:26,代码来源:TestWindowsMMap.cs
示例2: TestDemo_Renamed_Method
public virtual void TestDemo_Renamed_Method()
{
Analyzer analyzer = new StandardAnalyzer();
// Store the index in memory:
Directory directory = new RAMDirectory();
// To store an index on disk, use this instead (note that the
// parameter true will overwrite the index in that directory
// if one exists):
//Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);
IndexWriter iwriter = new IndexWriter(directory, analyzer, true);
iwriter.SetMaxFieldLength(25000);
Document doc = new Document();
System.String text = "This is the text to be indexed.";
doc.Add(new Field("fieldname", text, Field.Store.YES, Field.Index.TOKENIZED));
iwriter.AddDocument(doc);
iwriter.Close();
// Now search the index:
IndexSearcher isearcher = new IndexSearcher(directory);
// Parse a simple query that searches for "text":
Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser("fieldname", analyzer);
Query query = parser.Parse("text");
Hits hits = isearcher.Search(query);
Assert.AreEqual(1, hits.Length());
// Iterate through the results:
for (int i = 0; i < hits.Length(); i++)
{
Document hitDoc = hits.Doc(i);
Assert.AreEqual("This is the text to be indexed.", hitDoc.Get("fieldname"));
}
isearcher.Close();
directory.Close();
}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:35,代码来源:TestDemo.cs
示例3: TestDemo_Renamed
public virtual void TestDemo_Renamed()
{
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
// Store the index in memory:
Directory directory = new RAMDirectory();
// To store an index on disk, use this instead:
//Directory directory = FSDirectory.open("/tmp/testindex");
IndexWriter iwriter = new IndexWriter(directory, analyzer, true, new IndexWriter.MaxFieldLength(25000));
Document doc = new Document();
System.String text = "This is the text to be indexed.";
doc.Add(new Field("fieldname", text, Field.Store.YES, Field.Index.ANALYZED));
iwriter.AddDocument(doc);
iwriter.Close();
// Now search the index:
IndexSearcher isearcher = new IndexSearcher(directory, true); // read-only=true
// Parse a simple query that searches for "text":
QueryParser parser = new QueryParser("fieldname", analyzer);
Query query = parser.Parse("text");
ScoreDoc[] hits = isearcher.Search(query, null, 1000).scoreDocs;
Assert.AreEqual(1, hits.Length);
// Iterate through the results:
for (int i = 0; i < hits.Length; i++)
{
Document hitDoc = isearcher.Doc(hits[i].doc);
Assert.AreEqual(hitDoc.Get("fieldname"), "This is the text to be indexed.");
}
isearcher.Close();
directory.Close();
}
开发者ID:Rationalle,项目名称:ravendb,代码行数:32,代码来源:TestDemo.cs
示例4: SetUp
public override void SetUp()
{
base.SetUp();
RAMDirectory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
for (int i = 0; i < docFields.Length; i++)
{
Document doc = new Document();
doc.Add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
writer.AddDocument(doc);
}
writer.Close();
searcher = new IndexSearcher(directory);
}
开发者ID:Rationalle,项目名称:ravendb,代码行数:14,代码来源:TestNearSpansOrdered.cs
示例5: SetUp
public virtual void SetUp()
{
RAMDirectory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
System.Text.StringBuilder buffer = new System.Text.StringBuilder();
for (int i = 0; i < docFields.Length; i++)
{
Document doc = new Document();
doc.Add(Field.Text(field, docFields[i]));
writer.AddDocument(doc);
}
writer.Close();
searcher = new IndexSearcher(directory);
}
开发者ID:emtees,项目名称:old-code,代码行数:14,代码来源:TestSpans.cs
示例6: SetUp
public override void SetUp()
{
base.SetUp();
RAMDirectory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
for (int i = 0; i < docFields.Length; i++)
{
Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
doc.Add(new Field(field, docFields[i], Field.Store.YES, Field.Index.TOKENIZED));
writer.AddDocument(doc);
}
writer.Close();
searcher = new IndexSearcher(directory);
//System.out.println("set up " + getName());
}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:15,代码来源:TestSpans.cs
示例7: SetUp
public override void SetUp()
{
base.SetUp();
directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true);
Document doc = new Document();
doc.Add(new Field("partnum", "Q36", Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.Add(new Field("description", "Illidium Space Modulator", Field.Store.YES, Field.Index.TOKENIZED));
writer.AddDocument(doc);
writer.Close();
searcher = new IndexSearcher(directory);
}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:15,代码来源:TestKeywordAnalyzer.cs
示例8: SetUp
public override void SetUp()
{
base.SetUp();
RAMDirectory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
//writer.infoStream = System.out;
for (int i = 0; i < 1000; i++)
{
Document doc = new Document();
doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
}
writer.Close();
searcher = new IndexSearcher(directory, true);
}
开发者ID:Nangal,项目名称:lucene.net,代码行数:17,代码来源:TestBasics.cs
示例9: TestIterator
public virtual void TestIterator()
{
RAMDirectory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Document doc = new Document();
doc.Add(new Field("field", "iterator test doc 1", Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
doc = new Document();
doc.Add(new Field("field", "iterator test doc 2", Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
writer.Close();
_TestUtil.CheckIndex(directory);
IndexSearcher searcher = new IndexSearcher(directory);
Hits hits = searcher.Search(new TermQuery(new Term("field", "iterator")));
HitIterator iterator = (HitIterator) hits.Iterator();
Assert.AreEqual(2, iterator.Length());
Assert.IsTrue(iterator.MoveNext());
Hit hit = (Hit) iterator.Current;
Assert.AreEqual("iterator test doc 1", hit.Get("field"));
Assert.IsTrue(iterator.MoveNext());
hit = (Hit) iterator.Current;
Assert.AreEqual("iterator test doc 2", hit.GetDocument().Get("field"));
Assert.IsFalse(iterator.MoveNext());
bool caughtException = false;
try
{
System.Object generatedAux = iterator.Current;
}
catch (System.ArgumentOutOfRangeException e)
{
Assert.IsTrue(true);
caughtException = true;
}
Assert.IsTrue(caughtException);
}
开发者ID:Rationalle,项目名称:ravendb,代码行数:45,代码来源:TestHitIterator.cs
示例10: Main
public static void Main(System.String[] args)
{
System.String index = @"c:\EmailTest\LuceneDB";
IndexReader reader = IndexReader.Open(FSDirectory.Open(new System.IO.FileInfo(index)), true); // only searching, so read-only=true
Searcher searcher = new IndexSearcher(reader);
if (Stopwatch.IsHighResolution) {
System.Console.WriteLine("We have a high resolution timer with an frequency of {0} ticks/ms", Stopwatch.Frequency/1000);
}
searchFor(searcher, "jeske AND neotonic");
searchFor(searcher, "noticed AND problems");
searchFor(searcher, "data AND returned");
searchFor(searcher, "scott AND hassan");
searcher.Close();
reader.Close();
System.Console.WriteLine("done");
}
开发者ID:jeske,项目名称:StepsDB-alpha,代码行数:19,代码来源:BendSearchTest.cs
示例11: PreviouslyIndexed
public static bool PreviouslyIndexed(string url)
{
string indexFileLocation = indexDir;
Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation, false);
Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir);
Lucene.Net.Search.Hits hits = null;
try
{
Lucene.Net.Search.Query query = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("url", url));
hits = searcher.Search(query);
}
catch { }
finally
{
searcher.Close();
}
return hits.Length() > 0;
}
开发者ID:eulalie367,项目名称:littleapps,代码行数:20,代码来源:Program.cs
示例12: SearchProjects
public static List<IndexedItem> SearchProjects(string s)
{
List<IndexedItem> retVal = new List<IndexedItem>();
string indexFileLocation = indexDir;
Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation, false);
Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir);
try
{
Lucene.Net.Search.Query query = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("content", s));
query = query.Combine(new Lucene.Net.Search.Query[] { query, new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("url", fromUrl)) });
query = query.Combine(new Lucene.Net.Search.Query[] { query, new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("title", s)) });
//execute the query
Lucene.Net.Search.Hits hits = searcher.Search(query);
//iterate over the results.
for (int i = 0; i < hits.Length(); i++)
{
Lucene.Net.Documents.Document doc = hits.Doc(i);
string article = doc.Get("content");
string title = doc.Get("title");
string url = doc.Get("url");
retVal.Add(new IndexedItem { Article = article, Href = url, Title = title });
}
foreach (IndexedItem ind in retVal)
{
Console.WriteLine(ind.Href);
}
retVal = retVal.Distinct().ToList();
}
catch { }
finally
{
searcher.Close();
}
return retVal;
}
开发者ID:eulalie367,项目名称:littleapps,代码行数:40,代码来源:Program.cs
示例13: CreateWeight
public override Weight CreateWeight(IndexSearcher searcher)
{
Weight baseWeight = baseQuery.CreateWeight(searcher);
object[] drillDowns = new object[drillDownQueries.Length];
for (int dim = 0; dim < drillDownQueries.Length; dim++)
{
Query query = drillDownQueries[dim];
Filter filter = DrillDownQuery.GetFilter(query);
if (filter != null)
{
drillDowns[dim] = filter;
}
else
{
// TODO: would be nice if we could say "we will do no
// scoring" here....
drillDowns[dim] = searcher.Rewrite(query).CreateWeight(searcher);
}
}
return new WeightAnonymousInnerClassHelper(this, baseWeight, drillDowns);
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:22,代码来源:DrillSidewaysQuery.cs
示例14: TestMmapIndex
public virtual void TestMmapIndex()
{
FSDirectory storeDirectory;
storeDirectory = FSDirectory.GetDirectory(storePathname);
// plan to add a set of useful stopwords, consider changing some of the
// interior filters.
StandardAnalyzer analyzer = new StandardAnalyzer(new System.Collections.Hashtable());
// TODO: something about lock timeouts and leftover locks.
IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true);
IndexSearcher searcher = new IndexSearcher(storePathname);
for (int dx = 0; dx < 1000; dx++)
{
System.String f = RandomField();
Document doc = new Document();
doc.Add(new Field("data", f, Field.Store.YES, Field.Index.TOKENIZED));
writer.AddDocument(doc);
}
searcher.Close();
writer.Close();
RmDir(new System.IO.FileInfo(storePathname));
}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:24,代码来源:TestWindowsMMap.cs
示例15: DoTestRank
// Test that queries based on reverse/ordFieldScore scores correctly
private void DoTestRank(System.String field, bool inOrder)
{
IndexSearcher s = new IndexSearcher(dir, true);
ValueSource vs;
if (inOrder)
{
vs = new OrdFieldSource(field);
}
else
{
vs = new ReverseOrdFieldSource(field);
}
Query q = new ValueSourceQuery(vs);
Log("test: " + q);
QueryUtils.Check(q, s);
ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;
Assert.AreEqual(N_DOCS, h.Length, "All docs should be matched!");
System.String prevID = inOrder?"IE":"IC"; // smaller than all ids of docs in this test ("ID0001", etc.)
for (int i = 0; i < h.Length; i++)
{
System.String resID = s.Doc(h[i].Doc).Get(ID_FIELD);
Log(i + ". score=" + h[i].Score + " - " + resID);
Log(s.Explain(q, h[i].Doc));
if (inOrder)
{
Assert.IsTrue(String.CompareOrdinal(resID, prevID) < 0, "res id " + resID + " should be < prev res id " + prevID);
}
else
{
Assert.IsTrue(String.CompareOrdinal(resID, prevID) > 0, "res id " + resID + " should be > prev res id " + prevID);
}
prevID = resID;
}
}
开发者ID:synhershko,项目名称:lucene.net,代码行数:37,代码来源:TestOrdValues.cs
示例16: TestSetBufferSize
public virtual void TestSetBufferSize()
{
System.IO.FileInfo indexDir = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "testSetBufferSize"));
MockFSDirectory dir = new MockFSDirectory(indexDir);
try
{
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
writer.SetUseCompoundFile(false);
for (int i = 0; i < 37; i++)
{
Document doc = new Document();
doc.Add(new Field("content", "aaa bbb ccc ddd" + i, Field.Store.YES, Field.Index.TOKENIZED));
doc.Add(new Field("id", "" + i, Field.Store.YES, Field.Index.TOKENIZED));
writer.AddDocument(doc);
}
writer.Close();
dir.allIndexInputs.Clear();
IndexReader reader = IndexReader.Open(dir);
Term aaa = new Term("content", "aaa");
Term bbb = new Term("content", "bbb");
Term ccc = new Term("content", "ccc");
Assert.AreEqual(reader.DocFreq(ccc), 37);
reader.DeleteDocument(0);
Assert.AreEqual(reader.DocFreq(aaa), 37);
dir.TweakBufferSizes();
reader.DeleteDocument(4);
Assert.AreEqual(reader.DocFreq(bbb), 37);
dir.TweakBufferSizes();
IndexSearcher searcher = new IndexSearcher(reader);
Hits hits = searcher.Search(new TermQuery(bbb));
dir.TweakBufferSizes();
Assert.AreEqual(35, hits.Length());
dir.TweakBufferSizes();
hits = searcher.Search(new TermQuery(new Term("id", "33")));
dir.TweakBufferSizes();
Assert.AreEqual(1, hits.Length());
hits = searcher.Search(new TermQuery(aaa));
dir.TweakBufferSizes();
Assert.AreEqual(35, hits.Length());
searcher.Close();
reader.Close();
}
finally
{
_TestUtil.RmDir(indexDir);
}
}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:50,代码来源:TestBufferedIndexInput.cs
示例17: Main
public static void Main(System.String[] args)
{
try
{
Searcher searcher = new IndexSearcher(@"index");
Analyzer analyzer = new StandardAnalyzer();
System.IO.StreamReader in_Renamed = new System.IO.StreamReader(new System.IO.StreamReader(System.Console.OpenStandardInput(), System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(System.Console.OpenStandardInput(), System.Text.Encoding.Default).CurrentEncoding);
while (true)
{
System.Console.Out.Write("Query: ");
System.String line = in_Renamed.ReadLine();
if (line.Length == - 1)
break;
Query query = QueryParser.Parse(line, "contents", analyzer);
System.Console.Out.WriteLine("Searching for: " + query.ToString("contents"));
Hits hits = searcher.Search(query);
System.Console.Out.WriteLine(hits.Length() + " total matching documents");
int HITS_PER_PAGE = 10;
for (int start = 0; start < hits.Length(); start += HITS_PER_PAGE)
{
int end = System.Math.Min(hits.Length(), start + HITS_PER_PAGE);
for (int i = start; i < end; i++)
{
Document doc = hits.Doc(i);
System.String path = doc.Get("path");
if (path != null)
{
System.Console.Out.WriteLine(i + ". " + path);
}
else
{
System.String url = doc.Get("url");
if (url != null)
{
System.Console.Out.WriteLine(i + ". " + url);
System.Console.Out.WriteLine(" - " + doc.Get("title"));
}
else
{
System.Console.Out.WriteLine(i + ". " + "No path nor URL for this document");
}
}
}
if (hits.Length() > end)
{
System.Console.Out.Write("more (y/n) ? ");
line = in_Renamed.ReadLine();
if (line.Length == 0 || line[0] == 'n')
break;
}
}
}
searcher.Close();
}
catch (System.Exception e)
{
System.Console.Out.WriteLine(" caught a " + e.GetType() + "\n with message: " + e.Message);
}
}
开发者ID:runefs,项目名称:Marvin,代码行数:65,代码来源:SearchFiles.cs
示例18: SetUp
public override void SetUp()
{
base.SetUp();
RAMDirectory directory = new RAMDirectory();
PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
writer.SetSimilarity(similarity);
//writer.infoStream = System.out;
for (int i = 0; i < 1000; i++)
{
Document doc = new Document();
Field noPayloadField = new Field(PayloadHelper.NO_PAYLOAD_FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED);
//noPayloadField.setBoost(0);
doc.Add(noPayloadField);
doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("multiField", English.IntToEnglish(i) + " " + English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
}
writer.Optimize();
writer.Close();
searcher = new IndexSearcher(directory);
searcher.SetSimilarity(similarity);
}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:24,代码来源:TestBoostingTermQuery.cs
示例19: Main
public static void Main(System.String[] a)
{
System.String indexName = "localhost_index";
System.String fn = "c:/Program Files/Apache Group/Apache/htdocs/manual/vhosts/index.html.en";
System.Uri url = null;
for (int i = 0; i < a.Length; i++)
{
if (a[i].Equals("-i"))
{
indexName = a[++i];
}
else if (a[i].Equals("-f"))
{
fn = a[++i];
}
else if (a[i].Equals("-url"))
{
url = new System.Uri(a[++i]);
}
}
System.IO.StreamWriter temp_writer;
temp_writer = new System.IO.StreamWriter(System.Console.OpenStandardOutput(), System.Console.Out.Encoding);
temp_writer.AutoFlush = true;
System.IO.StreamWriter o = temp_writer;
IndexReader r = IndexReader.Open(indexName);
o.WriteLine("Open index " + indexName + " which has " + r.NumDocs() + " docs");
MoreLikeThis mlt = new MoreLikeThis(r);
o.WriteLine("Query generation parameters:");
o.WriteLine(mlt.DescribeParams());
o.WriteLine();
Query query = null;
if (url != null)
{
o.WriteLine("Parsing URL: " + url);
query = mlt.Like(url);
}
else if (fn != null)
{
o.WriteLine("Parsing file: " + fn);
query = mlt.Like(new System.IO.FileInfo(fn));
}
o.WriteLine("q: " + query);
o.WriteLine();
IndexSearcher searcher = new IndexSearcher(indexName);
Hits hits = searcher.Search(query);
int len = hits.Length();
o.WriteLine("found: " + len + " documents matching");
o.WriteLine();
for (int i = 0; i < System.Math.Min(25, len); i++)
{
Document d = hits.Doc(i);
System.String summary = d.Get("summary");
o.WriteLine("score : " + hits.Score(i));
o.WriteLine("url : " + d.Get("url"));
o.WriteLine("\ttitle : " + d.Get("title"));
if (summary != null)
o.WriteLine("\tsummary: " + d.Get("summary"));
o.WriteLine();
}
}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:66,代码来源:MoreLikeThis.cs
示例20: Search
private void Search()
{
try
{
SearchProgressBar.Maximum = 11;
ProgressLabel.Text = "Progress: Initialize Search ...";
Searcher searcher = new IndexSearcher(@"Canon\index");
Analyzer analyzer = new StandardAnalyzer();
ArrayList resultList = new ArrayList();
System.IO.StreamReader in_Renamed = new System.IO.StreamReader(new System.IO.StreamReader(System.Console.OpenStandardInput(), System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(System.Console.OpenStandardInput(), System.Text.Encoding.Default).CurrentEncoding);
String line = QueryInputBox.Text;
if (line.Length == - 1)
return;
ProgressLabel.Text = "Progress: Parsing Query ...";
Query query = QueryParser.Parse(line, "contents", analyzer);
//int[] ix = qtm.GetTermFrequencies();
Hits hits = searcher.Search(query);
SearchProgressBar.Increment(1);
ProgressLabel.Text = "Progress: Searched. Analyzing results ...";
//QueryHighlightExtractor highlighter = new QueryHighlightExtractor(query, new WhitespaceAnalyzer(), "<B>", "</B>");
Highlighter highlighter = new Highlighter(new QueryScorer(query));
highlighter.SetTextFragmenter(new SimpleFragmenter(80));
int maxNumFragmentsRequired = 1;
//int HITS_PER_PAGE = 10;
for (int i = 0; i < 10; i++)
{
SearchProgressBar.Increment(1);
ProgressLabel.Text = "Progress: Analyzing hit " + (i+1).ToString();
// get the document from index
Document doc = hits.Doc(i);
//SegmentReader ir = new SegmentReader();
//Lucene.Net.Index.TermFreqVector tfv =
//tfv.GetTermFrequencies
string score = hits.Score(i).ToString();
//Box += "Hit no. " + i + " scored: " + score + " occ: " + /*highlighter.tokenFrequency */ " best fragment: \n";
ResultSet a = new ResultSet();
a.BookName = doc.Get("path").Replace(@"c:\cscd\temp\","");
a.Score = hits.Score(i);
a.numberOfHits = hits.Length();
// get the document filename
// we can't get the text from the index
//because we didn't store it there
//so get it from archive
string path = doc.Get("path");
string name = GetInternalName(path);
PaliReaderUtils.AalekhDecoder.UnzipFromZipLibrary(name);
path = System.IO.Directory.GetCurrentDirectory() + @"\Work\" + name + ".htm";
string plainText = "";
//load text from zip archive temporarily
using (StreamReader sr = new StreamReader(path, System.Text.Encoding.Default))
{
plainText = parseHtml(sr.ReadToEnd());
}
//-------------------------------Highlighter Code 1.4
TokenStream tokenStream = analyzer.TokenStream(new StringReader(plainText));
a.textFragment = highlighter.GetBestFragments(tokenStream, plainText, maxNumFragmentsRequired, "...");
if(File.Exists(path))
File.Delete(path);
//-------------------------------
resultList.Add(a);
}
SearchProgressBar.Value = 0;
searcher.Close();
ssr = new ShowSearchResults(/*Box*/resultList);
//this.Hide();
ssr.OpenBookEvent += new ShowSearchResults.OpenBook(this.TriggerOpenBook);
ssr.Closing += new System.ComponentModel.CancelEventHandler(this.Closing_ResultWindow);
this.Hide();
ssr.ShowDialog();
}
catch (System.Exception e)
{
MessageBox.Show(" caught a " + e.GetType() + "\n with message: " + e.Message);
}
}
开发者ID:novalis78,项目名称:Pali-Text-Reader,代码行数:82,代码来源:SearchDialog.cs
注:本文中的Lucene.Net.Search.IndexSearcher类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论