Thanks a lot ... It works! :-)
Cheers
Michael
-----Original Message-----
From: Uwe Schindler [mailto:[email protected]]
Sent: Montag, 26. September 2011 17:33
To: [email protected]
Subject: RE: Automatic Prefix Query
One thing to mention:
> You can subclass QueryParser and override newFieldQuery to produce a
> PrefixQuery instead of TermQuery - that's all. Here a simple example
> with
an
> anonymous inner class:
>
> qp = new QueryParser(...) {
> @Override
> protected Query newTermQuery(Term term) {
> return new PrefixQuery(term);
> }
> };
>
> After that this QueryParser instance will produce PrefixQuery for each
token,
> where it created a TermQuery before (the default impl does "new
> TermQuery(term)").
PrefixQuery does no scoring at all, so all results get the same score. A
good trick to emphasize exact hits is adding both queries (TermQuery and
PrefixQuery), maybe boost the PrefixQuery even down by 0.2 or like that:
qp = new QueryParser(...) {
@Override
protected Query newTermQuery(Term term) {
final BooleanQuery bq = new BooleanQuery();
bq.add(super.newTermQuery(term), BooleanClause.Occur.SHOULD);
final Query pq = new PrefixQuery(term);
pq.setBoost(0.2f);
bq.add(pq, BooleanClause.Occur.SHOULD);
return bq;
}
};
If you then get a exact hit, this hits both clauses and gets extra
boost.
Hits only on the prefix get a much lower score.
Uwe
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]