public override void Warm(IndexReader r) { IndexSearcher s = new IndexSearcher(r); Lucene.Net.Search.TopDocs hits = s.Search(new TermQuery(new Term("foo", "bar")), 10); Assert.AreEqual(20, hits.TotalHits); }
public virtual void Test() { BoostingTermQuery query = new BoostingTermQuery(new Term("field", "seventy")); TopDocs hits = searcher.Search(query, null, 100); Assert.IsTrue(hits != null, "hits is null and it shouldn't be"); Assert.IsTrue(hits.TotalHits == 100, "hits Size: " + hits.TotalHits + " is not: " + 100); //they should all have the exact same score, because they all contain seventy once, and we set //all the other similarity factors to be 1 Assert.IsTrue(hits.GetMaxScore() == 1, hits.GetMaxScore() + " does not equal: " + 1); for (int i = 0; i < hits.ScoreDocs.Length; i++) { ScoreDoc doc = hits.ScoreDocs[i]; Assert.IsTrue(doc.score == 1, doc.score + " does not equal: " + 1); } CheckHits.CheckExplanations(query, PayloadHelper.FIELD, searcher, true); Lucene.Net.Search.Spans.Spans spans = query.GetSpans(searcher.GetIndexReader()); Assert.IsTrue(spans != null, "spans is null and it shouldn't be"); Assert.IsTrue(spans is TermSpans, "spans is not an instanceof " + typeof(TermSpans)); /*float score = hits.score(0); * for (int i =1; i < hits.length(); i++) * { * Assert.IsTrue(score == hits.score(i), "scores are not equal and they should be"); * }*/ }
// Test that queries based on reverse/ordFieldScore returns docs with expected score. private void DoTestExactScore(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); TopDocs td = s.Search(q, null, 1000); Assert.AreEqual(N_DOCS, td.TotalHits, "All docs should be matched!"); ScoreDoc[] sd = td.ScoreDocs; for (int i = 0; i < sd.Length; i++) { float score = sd[i].Score; System.String id = s.IndexReader.Document(sd[i].Doc).Get(ID_FIELD); Log("-------- " + i + ". Explain doc " + id); Log(s.Explain(q, sd[i].Doc)); float expectedScore = N_DOCS - i; Assert.AreEqual(expectedScore, score, TEST_SCORE_TOLERANCE_DELTA, "score of result " + i + " shuould be " + expectedScore + " != " + score); System.String expectedId = inOrder?Id2String(N_DOCS - i):Id2String(i + 1); // reverse ==> smaller values first Assert.IsTrue(expectedId.Equals(id), "id of result " + i + " shuould be " + expectedId + " != " + score); } }
/// <summary> /// Search for files. /// </summary> /// <param name="queryText">The query text.</param> /// <returns>The files that match the query text.</returns> public SourceFile[] Search(string queryText) { Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser( Lucene.Net.Util.Version.LUCENE_30, "body", _analyzer); Lucene.Net.Search.Query query = parser.Parse(queryText); using (Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(_directory, true)) { Lucene.Net.Search.TopDocs result = searcher.Search(query, int.MaxValue); List <SourceFile> files = new List <SourceFile>(); foreach (Lucene.Net.Search.ScoreDoc d in result.ScoreDocs) { Lucene.Net.Documents.Document doc = searcher.Doc(d.Doc); files.Add(new SourceFile( doc.Get("id"), doc.Get("type"), doc.Get("name"), doc.Get("fileName"), null)); } return(files.ToArray()); } }
public Task <IEnumerable <ISearchItem> > Search(string pattern, int page) { using (Analyzer analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48)) using (Lucene.Net.Store.Directory index = new SimpleFSDirectory(Path.ChangeExtension(_bookFile.FullName, Convert.ToInt32(LuceneVersion.LUCENE_48).ToString()))) using (IndexReader reader = DirectoryReader.Open(index)) { Lucene.Net.Search.Query query = new QueryParser(LuceneVersion.LUCENE_48, nameof(TabHtmlText.Html), analyzer).Parse(pattern); Lucene.Net.Search.TopScoreDocCollector collector = Lucene.Net.Search.TopScoreDocCollector.Create(512, true); Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(reader); searcher.Search(query, collector); Lucene.Net.Search.TopDocs docs = collector.GetTopDocs(page * PageSize, PageSize); QueryScorer scorer = new QueryScorer(query); Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter(), scorer) // SpanGradientFormatter { TextFragmenter = new SimpleSpanFragmenter(scorer, 30) }; IEnumerable <ISearchItem> items = docs.ScoreDocs.Select(scoreDoc => { Document doc = searcher.Doc(scoreDoc.Doc); string html = doc.Get(nameof(TabHtmlText.Html)); string[] fragments = highlighter.GetBestFragments(new HTMLStripCharAnalyzer(), nameof(TabHtmlText.Html), html, 3); return(new SearchItem(int.Parse(doc.Get(nameof(TabHtmlText.NumId))), string.Join("\n", fragments))); }); return(Task.FromResult(items.ToList().AsEnumerable())); } }
public void Run() { Lucene.Net.Index.IndexReader indexReader = Lucene.Net.Index.IndexReader.Open(_directory, true); Lucene.Net.Search.Searcher indexSearch = new Lucene.Net.Search.IndexSearcher(indexReader); var queryParser = new QueryParser(luceneVersion, "TAGS", _analyzer); Console.Write("검색어를 입력해주세요 :"); string q = Console.ReadLine(); var query = queryParser.Parse(q); Console.WriteLine("[검색어] {0}", q); Lucene.Net.Search.TopDocs resultDocs = indexSearch.Search(query, indexReader.MaxDoc); var hits = resultDocs.ScoreDocs; int currentRow = 0; foreach (var hit in hits) { var documentFromSearch = indexSearch.Doc(hit.Doc); Console.WriteLine("* Result {0}", ++currentRow); Console.WriteLine("\t-제목 : {0}", documentFromSearch.Get("TITLE")); Console.WriteLine("\t-내용 : {0}", documentFromSearch.Get("SUMMARY")); Console.WriteLine("\t-태그 : {0}", documentFromSearch.Get("TAGS")); } Console.WriteLine(); }
public virtual void TestNoMatch() { BoostingTermQuery query = new BoostingTermQuery(new Term(PayloadHelper.FIELD, "junk")); TopDocs hits = searcher.Search(query, null, 100); Assert.IsTrue(hits != null, "hits is null and it shouldn't be"); Assert.IsTrue(hits.TotalHits == 0, "hits Size: " + hits.TotalHits + " is not: " + 0); }
public bool CheckDocExist(OfficeData officeData) { Lucene.Net.Search.Query query1 = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("FileName", officeData.FileName)); Lucene.Net.Search.Query query2 = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("LastWriteTime", officeData.LastWriteTime)); Lucene.Net.Search.BooleanQuery query3 = new Lucene.Net.Search.BooleanQuery(); query3.Add(query1, Lucene.Net.Search.Occur.MUST); query3.Add(query2, Lucene.Net.Search.Occur.MUST); Lucene.Net.Search.TopDocs topDocs = searcher.Search(query3, 2); if (topDocs.TotalHits == 0) { return(false); } return(true); }
public virtual void TestIgnoreSpanScorer() { PayloadTermQuery query = new PayloadTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"), new MaxPayloadFunction(), false); IndexSearcher theSearcher = new IndexSearcher(directory, true, null); theSearcher.Similarity = new FullSimilarity(); TopDocs hits = searcher.Search(query, null, 100, null); Assert.IsTrue(hits != null, "hits is null and it shouldn't be"); Assert.IsTrue(hits.TotalHits == 100, "hits Size: " + hits.TotalHits + " is not: " + 100); //they should all have the exact same score, because they all contain seventy once, and we set //all the other similarity factors to be 1 //System.out.println("Hash: " + seventyHash + " Twice Hash: " + 2*seventyHash); Assert.IsTrue(hits.MaxScore == 4.0, hits.MaxScore + " does not equal: " + 4.0); //there should be exactly 10 items that score a 4, all the rest should score a 2 //The 10 items are: 70 + i*100 where i in [0-9] int numTens = 0; for (int i = 0; i < hits.ScoreDocs.Length; i++) { ScoreDoc doc = hits.ScoreDocs[i]; if (doc.Doc % 10 == 0) { numTens++; Assert.IsTrue(doc.Score == 4.0, doc.Score + " does not equal: " + 4.0); } else { Assert.IsTrue(doc.Score == 2, doc.Score + " does not equal: " + 2); } } Assert.IsTrue(numTens == 10, numTens + " does not equal: " + 10); CheckHits.CheckExplanations(query, "field", searcher, true); Lucene.Net.Search.Spans.Spans spans = query.GetSpans(searcher.IndexReader, null); Assert.IsTrue(spans != null, "spans is null and it shouldn't be"); Assert.IsTrue(spans is TermSpans, "spans is not an instanceof " + typeof(TermSpans)); //should be two matches per document int count = 0; //100 hits times 2 matches per hit, we should have 200 in count while (spans.Next(null)) { count++; } }
public virtual void TestShrinkToAfterShortestMatch3() { RAMDirectory directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, new TestPayloadAnalyzer(this), IndexWriter.MaxFieldLength.LIMITED); Document doc = new Document(); doc.Add(new Field("content", new System.IO.StreamReader(new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes("j k a l f k k p a t a k l k t a"))))); writer.AddDocument(doc); writer.Close(); IndexSearcher is_Renamed = new IndexSearcher(directory, true); SpanTermQuery stq1 = new SpanTermQuery(new Term("content", "a")); SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k")); SpanQuery[] sqs = new SpanQuery[] { stq1, stq2 }; SpanNearQuery snq = new SpanNearQuery(sqs, 0, true); Spans spans = snq.GetSpans(is_Renamed.IndexReader); TopDocs topDocs = is_Renamed.Search(snq, 1); System.Collections.Hashtable payloadSet = new System.Collections.Hashtable(); for (int i = 0; i < topDocs.ScoreDocs.Length; i++) { while (spans.Next()) { System.Collections.Generic.ICollection <byte[]> payloads = spans.GetPayload(); for (System.Collections.IEnumerator it = payloads.GetEnumerator(); it.MoveNext();) { CollectionsHelper.AddIfNotContains(payloadSet, new System.String(System.Text.UTF8Encoding.UTF8.GetChars((byte[])it.Current))); } } } Assert.AreEqual(2, payloadSet.Count); if (DEBUG) { System.Collections.IEnumerator pit = payloadSet.GetEnumerator(); while (pit.MoveNext()) { System.Console.Out.WriteLine("match:" + pit.Current); } } Assert.IsTrue(payloadSet.Contains("a:Noise:10")); Assert.IsTrue(payloadSet.Contains("k:Noise:11")); }
String q = args[1]; // B public static void search(String indexDir, String q) { Directory dir = FSDirectory.Open(new System.IO.FileInfo(indexDir)); // C IndexSearcher searcher = new IndexSearcher(dir, true); // D QueryParser parser = new QueryParser("contents", new StandardAnalyzer(Version.LUCENE_CURRENT)); // E Query query = parser.Parse(q); // E Lucene.Net.Search.TopDocs hits = searcher.Search(query, 10); // F System.Console.WriteLine("Found " + hits.totalHits + " document(s) that matched query '" + q + "':"); for (int i = 0; i < hits.scoreDocs.Length; i++) { ScoreDoc scoreDoc = hits.ScoreDocs[i]; // G Document doc = searcher.Doc(scoreDoc.doc); // G System.Console.WriteLine(doc.Get("filename")); // G } searcher.Close(); // H }
// Test that FieldScoreQuery returns docs with expected score. private void DoTestExactScore(System.String field, FieldScoreQuery.Type tp) { IndexSearcher s = new IndexSearcher(dir, true); Query q = new FieldScoreQuery(field, tp); TopDocs td = s.Search(q, null, 1000); Assert.AreEqual(N_DOCS, td.TotalHits, "All docs should be matched!"); ScoreDoc[] sd = td.ScoreDocs; for (int i = 0; i < sd.Length; i++) { float score = sd[i].Score; Log(s.Explain(q, sd[i].Doc)); System.String id = s.IndexReader.Document(sd[i].Doc).Get(ID_FIELD); float expectedScore = ExpectedFieldScore(id); // "ID7" --> 7.0 Assert.AreEqual(expectedScore, score, TEST_SCORE_TOLERANCE_DELTA, "score of " + id + " shuould be " + expectedScore + " != " + score); } }
public virtual void TestNoPayload() { BoostingTermQuery q1 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "zero")); BoostingTermQuery q2 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "foo")); BooleanClause c1 = new BooleanClause(q1, BooleanClause.Occur.MUST); BooleanClause c2 = new BooleanClause(q2, BooleanClause.Occur.MUST_NOT); BooleanQuery query = new BooleanQuery(); query.Add(c1); query.Add(c2); TopDocs hits = searcher.Search(query, null, 100); Assert.IsTrue(hits != null, "hits is null and it shouldn't be"); Assert.IsTrue(hits.TotalHits == 1, "hits Size: " + hits.TotalHits + " is not: " + 1); int[] results = new int[1]; results[0] = 0; //hits.scoreDocs[0].doc; CheckHits.CheckHitCollector(query, PayloadHelper.NO_PAYLOAD_FIELD, searcher, results); }
/// <summary> /// display the abstract of results in a new window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { myLuceneApp.CreateSearcher(); Lucene.Net.Search.Query query = myLuceneApp.InfoParser(infoNeed); Lucene.Net.Search.TopDocs result = myLuceneApp.SearchText(query); int index = pageDivded.currentPage - 1; if (dataGridView1.Columns[e.ColumnIndex].Name == "list") { selectedItemIndex = index * 10 + e.RowIndex; Lucene.Net.Documents.Document documents = myLuceneApp.GetSearcher.Doc(result.ScoreDocs[selectedItemIndex].Doc); string abstractText = documents.Get("abstract").ToString(); GlobalData.abstractContent = abstractText; } myLuceneApp.CleanUpSearcher(); AbstractView abstractView = new AbstractView(); abstractView.ShowDialog(); }
public void Test_Store_RAMDirectory() { Lucene.Net.Store.RAMDirectory ramDIR = new Lucene.Net.Store.RAMDirectory(); //Index 1 Doc Lucene.Net.Index.IndexWriter wr = new Lucene.Net.Index.IndexWriter(ramDIR, new Lucene.Net.Analysis.WhitespaceAnalyzer(), true); Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document(); doc.Add(new Lucene.Net.Documents.Field("field1", "value1 value11", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED)); wr.AddDocument(doc); wr.Close(); //now serialize it System.Runtime.Serialization.Formatters.Binary.BinaryFormatter serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); serializer.Serialize(memoryStream, ramDIR); //Close DIR ramDIR.Close(); ramDIR = null; //now deserialize memoryStream.Seek(0, System.IO.SeekOrigin.Begin); Lucene.Net.Store.RAMDirectory ramDIR2 = (Lucene.Net.Store.RAMDirectory)serializer.Deserialize(memoryStream); //Add 1 more doc wr = new Lucene.Net.Index.IndexWriter(ramDIR2, new Lucene.Net.Analysis.WhitespaceAnalyzer(), false); doc = new Lucene.Net.Documents.Document(); doc.Add(new Lucene.Net.Documents.Field("field1", "value1 value11", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED)); wr.AddDocument(doc); wr.Close(); //Search Lucene.Net.Search.IndexSearcher s = new Lucene.Net.Search.IndexSearcher(ramDIR2); Lucene.Net.QueryParsers.QueryParser qp = new Lucene.Net.QueryParsers.QueryParser("field1", new Lucene.Net.Analysis.Standard.StandardAnalyzer()); Lucene.Net.Search.Query q = qp.Parse("value1"); Lucene.Net.Search.TopDocs topDocs = s.Search(q, 100); s.Close(); Assert.AreEqual(topDocs.totalHits, 2, "See the issue: LUCENENET-174"); }
public void Query(string searchText) { //state the file location of the index DirectoryInfo directoryInfo = new DirectoryInfo(_Location); Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.Open(directoryInfo); //create an index searcher that will perform the search Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir, true); //build a query object Lucene.Net.Index.Term searchTerm = new Lucene.Net.Index.Term("content", searchText); Lucene.Net.Search.Query query = new Lucene.Net.Search.TermQuery(searchTerm); //execute the query Lucene.Net.Search.TopDocs hits = searcher.Search(query, null, 100); //iterate over the results. for (int i = 0; i < hits.TotalHits; i++) { Lucene.Net.Search.ScoreDoc doc = hits.ScoreDocs[i]; } }
void LUCENENET_100_ClientSearch() { try { Lucene.Net.Search.Searchable s = (Lucene.Net.Search.Searchable)Activator.GetObject(typeof(Lucene.Net.Search.Searchable), @"tcp://localhost:38087/Searcher"); Lucene.Net.Search.MultiSearcher searcher = new Lucene.Net.Search.MultiSearcher(new Lucene.Net.Search.Searchable[] { s }); Lucene.Net.Search.Query q = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("field1", "moon")); Lucene.Net.Search.Sort sort = new Lucene.Net.Search.Sort(); sort.SetSort(new Lucene.Net.Search.SortField("field2", Lucene.Net.Search.SortField.INT)); Lucene.Net.Search.TopDocs h = searcher.Search(q, null, 100, sort); } catch (Exception ex) { LUCENENET_100_Exception = ex; } finally { LUCENENET_100_testFinished = true; } }
private string Highlight(int numId, string pattern, string html) { if (!string.IsNullOrWhiteSpace(pattern)) { using (Analyzer analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48)) using (Lucene.Net.Store.Directory index = new SimpleFSDirectory(Path.ChangeExtension(_bookFile.FullName, Convert.ToInt32(LuceneVersion.LUCENE_48).ToString()))) using (IndexReader reader = DirectoryReader.Open(index)) { Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(reader); Lucene.Net.Search.TopDocs docs = searcher.Search( Lucene.Net.Search.NumericRangeQuery.NewInt32Range(nameof(TabHtmlText.NumId), numId, numId, true, true), 1); int docId = docs.ScoreDocs.First().Doc; QueryScorer scorer = new QueryScorer(new QueryParser(LuceneVersion.LUCENE_48, nameof(TabHtmlText.Html), analyzer) .Parse(pattern)); Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter("<span style=\"background-color: yellow\">", "</span>"), scorer) { TextFragmenter = new NullFragmenter() }; using (TokenStream stream = TokenSources.GetAnyTokenStream(reader, docId, nameof(TabHtmlText.Html), analyzer)) { return(highlighter.GetBestFragment(stream, html)); } } } return(html); }
// since custom scoring modifies the order of docs, map results // by doc ids so that we can later compare/verify them private System.Collections.Hashtable TopDocsToMap(TopDocs td) { System.Collections.Hashtable h = new System.Collections.Hashtable(); for (int i = 0; i < td.totalHits; i++) { h[(System.Int32) td.scoreDocs[i].doc] = (float) td.scoreDocs[i].score; } return h; }
/// <summary> /// save result as txt file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveResultButton_Click_2(object sender, EventArgs e) { //set paramaeter of savefiledialog Stream stream; saveFileDialog1.CreatePrompt = true; saveFileDialog1.OverwritePrompt = true; saveFileDialog1.DefaultExt = "txt"; saveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (infoNeed == "") { MessageBox.Show("Invalid input!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); InfoNeedInput.Clear(); return; } myLuceneApp.CreateSearcher(); Lucene.Net.Search.Query query = myLuceneApp.InfoParser(infoNeed); Lucene.Net.Search.TopDocs result = myLuceneApp.SearchText(query); string query1 = query.ToString(); string path = ""; string oneLine = ""; int rank = 0; string topicID = textBox3.Text; string gropunumber = "0123456798_0987654321_ourteam"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { path = saveFileDialog1.FileName; if (File.Exists(path)) { using (StreamWriter myWritter1 = File.AppendText(path)) { foreach (Lucene.Net.Search.ScoreDoc scoreDoc in result.ScoreDocs) { rank++; Lucene.Net.Documents.Document doc = myLuceneApp.GetSearcher.Doc(scoreDoc.Doc); string docID = doc.Get("id").Replace(" ", "").Replace("\n", "").Replace("\r", "").ToString(); oneLine = string.Format("{0}\tQ0\t{1}\t{2}\t{3}\t{4}", topicID, docID, rank, scoreDoc.Score.ToString(), gropunumber); myWritter1.WriteLine(oneLine); } myWritter1.Flush(); myWritter1.Close(); } } else if ((stream = saveFileDialog1.OpenFile()) != null) { using (StreamWriter myWritter2 = new StreamWriter(stream)) { foreach (Lucene.Net.Search.ScoreDoc scoreDoc in result.ScoreDocs) { rank++; Lucene.Net.Documents.Document doc = myLuceneApp.GetSearcher.Doc(scoreDoc.Doc); string docID = doc.Get("id").Replace(" ", "").Replace("\n", "").Replace("\r", "").ToString(); oneLine = string.Format("{0}\tQ0\t{1}\t{2}\t{3}\t{4}", topicID, docID, rank, scoreDoc.Score.ToString(), gropunumber); myWritter2.WriteLine(oneLine); } myWritter2.Flush(); myWritter2.Close(); //"{0}\tQ0\t{1,10}\t{2,5}\t{3,15}\t{4,38}" } } } }
/// <summary> /// Deal with the information need as suitable query /// search the processed query /// display the result /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void submitButton_Click(object sender, EventArgs e) { CleanResult(); infoNeed = InfoNeedInput.Text; Stopwatch stopwatch = new Stopwatch(); //give an error warning when input is null if (infoNeed == "") { MessageBox.Show("Invalid input!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); InfoNeedInput.Clear(); return; } //take the analyzer selected by users string analyzerSelection = comboBox1.SelectedItem.ToString(); myLuceneApp.AnalyzerSelection(analyzerSelection); //make the input "as is" to search myLuceneApp.CreateSearcher(); if (checkBox1.Checked) { infoNeed = infoNeed.Replace("\"", ""); infoNeed = "\"" + infoNeed + "\""; } string expandedQueryItems = ""; OptionOfQeryExpansionAndWeighterQueries(expandedQueryItems); AnalyzerChoice(); //record searching time stopwatch.Start(); //parse the information need into final query terms Lucene.Net.Search.Query query = myLuceneApp.InfoParser(infoNeed); string queryText = query.ToString(); //display the final query in textbox textBox2.Text = queryText; Lucene.Net.Search.TopDocs result = myLuceneApp.SearchText(query); stopwatch.Stop(); TimeSpan timeSpan = stopwatch.Elapsed; double time = timeSpan.TotalSeconds; time = Math.Round(time, 4); toolStripStatusLabel2.Text = "Searching time: " + time.ToString() + "s"; int rank = 0; pageDivded.DtSource.Columns.Add("list"); //display the number of result groupBox5.Text = "Result: " + result.TotalHits.ToString(); //display the results foreach (Lucene.Net.Search.ScoreDoc scoreDoc in result.ScoreDocs) { rank++; Lucene.Net.Documents.Document doc = myLuceneApp.GetSearcher.Doc(scoreDoc.Doc); string ID = "ID" + doc.Get("id").Replace(" ", "").ToString(); string title = "Title: " + doc.Get("title").ToString(); string author = "Author: " + doc.Get("author").ToString(); string bbibliographic = "Bibliographic: " + doc.Get("bibliographic").ToString(); string textAbstract = doc.Get("firstSentence").ToString(); string row = "Rank:" + rank + "\r\n" + title + "\r\n" + author + "\r\n" + bbibliographic + "\r\n" + textAbstract + "\r\n"; pageDivded.DtSource.Rows.Add(row); } //A prompt message pop up when there is no results if (pageDivded.DtSource.Rows.Count <= 0) { MessageBox.Show("No result", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } pageDivded.DividedPage(); dataGridView1.DataSource = pageDivded.LoadPage(); dataGridView1.Columns["list"].FillWeight = 240; dataGridView1.Show(); label6.Text = pageDivded.PageNumber(); myLuceneApp.CleanUpSearcher(); }