private void btnExecuteSearch_Click(object sender, EventArgs e) { Directory indexDirectory = FSDirectory.Open(new System.IO.DirectoryInfo(tempPath)); IndexSearcher searcher = new IndexSearcher(indexDirectory, true); // read-only=true QueryParser qp = new HebrewQueryParser(Lucene.Net.Util.Version.LUCENE_29, "content", analyzer); qp.DefaultOperator = QueryParser.Operator.AND; Query query = qp.Parse(txbSearchQuery.Text); ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs; // Iterate through the results: var l = new BindingList <SearchResult>(); for (int i = 0; i < hits.Length; i++) { Document hitDoc = searcher.Doc(hits[i].Doc); var sr = new SearchResult(hitDoc.GetField("title").StringValue, hitDoc.GetField("path").StringValue, hits[i].Score); l.Add(sr); } searcher.Close(); indexDirectory.Close(); dgvResults.DataSource = l; }
public void ParsesAcronymsCorrectly() { QueryParser qp = new HebrewQueryParser(LuceneUtil.Version.LUCENE_29, "f", new global::Lucene.Net.Analysis.Hebrew.SimpleAnalyzer()); qp.Parse(@"צה""ל"); qp.Parse(@"""צהל"""); qp.Parse(@"כל הכבוד לצה""ל"); qp.Parse(@"""כל הכבוד לצה""ל"""); qp.Parse(@"""כל הכבוד"" לצה""ל"); qp.Parse(@"מנכ""לית"); try { qp.Parse(@"צה""""ל"); qp.Parse(@"""צה""ל"); Assert.Fail("Expected exception was not thrown"); } catch(ParseException) { } }
public void ParsesAcronymsCorrectly() { QueryParser qp = new HebrewQueryParser(LuceneUtil.Version.LUCENE_30, "f", new global::Lucene.Net.Analysis.Hebrew.SimpleAnalyzer()); qp.Parse(@"צה""ל"); qp.Parse(@"""צהל"""); qp.Parse(@"כל הכבוד לצה""ל"); qp.Parse(@"""כל הכבוד לצה""ל"""); qp.Parse(@"""כל הכבוד"" לצה""ל"); qp.Parse(@"מנכ""לית"); try { qp.Parse(@"צה""""ל"); qp.Parse(@"""צה""ל"); Assert.True(false, "Expected exception was not thrown"); } catch (ParseException) { } }
private void RunQuery(string query, int expectedPosition) { var hqp = new HebrewQueryParser(global::Lucene.Net.Util.Version.LUCENE_29, "Text", analyzer); Query q = hqp.Parse(query); TopDocs td = searcher.Search(q, 10000); int num = td.ScoreDocs[0].Doc; var tf = searcher.IndexReader.GetTermFreqVectors(num)[0]; var tp = (TermPositionVector)tf; var trms_list = new SortedSet <Term>(); q.ExtractTerms(trms_list); foreach (var t in trms_list) { int[] pos = tp.GetTermPositions(tp.IndexOf(t.Text)); TermVectorOffsetInfo[] off = tp.GetOffsets(tp.IndexOf(t.Text)); AssertSinglePositionExists(pos, expectedPosition); /* * string sPos = ""; * string sOff = ""; * foreach (int p in pos) * { * sPos += " " + p; * } * foreach (TermVectorOffsetInfo o in off) * { * sOff += " (" + o.GetStartOffset() + "," + o.GetEndOffset() + ")"; * } * Trace.WriteLine(string.Format("Term: {0} Pos:{1} Off:{2}", t.Text(), sPos, sOff)); */ } }