lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "chris.stodola" <stadler.christ...@web.de>
Subject Re: How can I use QueryScorer() to find only perfect matches??
Date Thu, 18 Mar 2010 10:43:10 GMT

Hi Erick,

I did as recommended and changed the query approprietly. But the result is
still the same.
On page 78 in the book "lucene in action" it is explained how scoring is
working. Therefore I get more results than the exact match I was expecting.
But how can I highlight in a large document only the results identified by a
certain query like +contents:term +contents:query?
Are there any alternatives to the QueryScore method? any examples? any
papers to read first?

thx
christian

Erick Erickson wrote:
> 
> Try +contents:term +contents:query. By misplacing the
> '+' you're getting the default OR operator and the '+'
> is probably being thrown away by the analyzer.
> 
> Luke will help here a lot.
> 
> HTH
> Erick
> 
> On Mon, Mar 15, 2010 at 9:46 AM, christian stadler
> <stadler.christian@web.de
>> wrote:
> 
>> Hi there,
>>
>> I have an issue with the QueryScorer(query) method at the moment and I
>> need
>> some assistance.
>> I was indexing my e-book "lucene in action" and based on this index-db I
>> started to play around with some boolean queries like:
>> (contents:+term contents:+query)
>> As a result I'm expecting as a perfect match for the phrase "term query"
>> four
>> hits.
>>
>> But when I run my sample to highlight this phrase in the context then I
>> get
>> a
>> lot more results. It also finds all the matches for "term" and "query"
>> independently.
>>
>> I think the problem is the QueryScorer() which softens the former exact
>> boolean
>> query.
>> Then I was trying the following:
>> private static Highlighter GetHits(Query query, Formatter formatter)
>> {
>>    string filed = "contents"
>>    BooleanQuery termsQuery = new BooleanQuery();
>>
>>    WeightedTerm[] terms = QueryTermExtractor.GetTerms(query, true,
>> field);
>>    foreach (WeightedTerm term in terms)
>>    {
>>        TermQuery termQuery = new TermQuery(new Term(field,
>> term.GetTerm()));
>>        termsQuery.Add(termQuery, BooleanClause.Occur.MUST);
>>    }
>>
>>    // create query scorer based on term queries (field specific)
>>    QueryScorer scorer = new QueryScorer(termsQuery);
>>
>>    Highlighter highlighter = new Highlighter(formatter, scorer);
>>    highlighter.SetTextFragmenter(new SimpleFragmenter(20));
>>
>>    return highlighter;
>> }
>> to rewrite the query and set the term attribute from SHOULD to MUST
>>
>> But the result was the same.
>> Do you have any example how I can use the QueryScorer() in exactly the
>> same
>> way
>> as to mimic a BooleanSearch??
>>
>> thanks in advance
>> Christian
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-dev-help@lucene.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/How-can-I-use-QueryScorer%28%29-to-find-only-perfect-matches---tp27904831p27943914.html
Sent from the Lucene - Java Developer mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message