lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erick Erickson <erickerick...@gmail.com>
Subject Re: How can I use QueryScorer() to find only perfect matches??
Date Mon, 15 Mar 2010 14:17:21 GMT
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
>
>

Mime
View raw message