[
https://issues.apache.org/jira/browse/LUCENENET-289?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780469#action_12780469
]
atashbahar commented on LUCENENET-289:
--------------------------------------
I know about the Query.Rewrite and I have used it but returned fragments don't
contain any text when there is a wildcard character (*) in the query. Here is
the code I am using:
String Field_Name = "contents";
RAMDirectory ramDir = new RAMDirectory();
Analyzer analyzer = new StandardAnalyzer();
System.String[] texts = new System.String[] { "JFK has been shot",
"John Kennedy has been shot", "This text has a typo in referring to Keneddy" };
IndexWriter writer = new IndexWriter(ramDir, analyzer, true);
for (int i = 0; i < texts.Length; i++)
{
Document d = new Document();
Field f = new Field(Field_Name, texts[i], Field.Store.YES,
Field.Index.TOKENIZED);
d.Add(f);
writer.AddDocument(d);
}
writer.Optimize();
writer.Close();
IndexReader reader = IndexReader.Open(ramDir);
QueryParser parser = new QueryParser(Field_Name, analyzer);
Query query = parser.Parse("Ken*dy");
query = query.Rewrite(reader);
Searcher searcher = new IndexSearcher(ramDir);
Hits hits = searcher.Search(query);
SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<em>",
"</em>");
Highlighter highlighter = new Highlighter(formatter, new
QueryScorer(query));
for (int i = 0; i < hits.Length(); i++)
{
System.String text = hits.Doc(i).Get(Field_Name);
int maxNumFragmentsRequired = 2;
System.String fragmentSeparator = "...";
TokenStream tokenStream = analyzer.TokenStream(Field_Name, new
System.IO.StringReader(text));
System.String result = highlighter.GetBestFragments(tokenStream,
text, maxNumFragmentsRequired, fragmentSeparator);
lblResults.Text += "<br />" + result;
}
> Highlighter does not return fragments for wildcard queries
> ----------------------------------------------------------
>
> Key: LUCENENET-289
> URL: https://issues.apache.org/jira/browse/LUCENENET-289
> Project: Lucene.Net
> Issue Type: Bug
> Reporter: atashbahar
>
> I just download the latest code from SVN and updated my project and found out
> that Highlighter does not work properly when it comes to queries that contain
> wildcard characters. The return fragments contain no text.
> I was using version 2.0 before this and the Highlighter was returning correct
> results.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.