lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shailesh Kochhar" <>
Subject Exposing API for scoring
Date Fri, 19 Oct 2007 01:13:07 GMT

I'm experimenting with a few different scoring implementations and I
was wondering what the easiest way would be to incorporate a new
scorer into a searcher implementation.

>From reading the docs on Scoring at:
it seems that the path of least resistance would be to create an
entire new hierarchy of class.

1. A new Query class to extend TermQuery with an appropriate
implementation of TermWeight,
2. A new Scorer class to extend TermScorer with the appropriate Scorer
implementation, and;
3. A new Similarity class which would provide the appropriate
Similarity implementations.

Given a new Query class I was at a loss when it came to instantiation.
Would something like the following work -- i.e. is it sufficient to
replace the top-level Query object, or would I need an implementation
of a QueryParser that returns instances of the derived Query type.

    Query query = QueryParser.parse(queryString);
    ScopedQuery sq = new ScopedQuery(query);
    ScopedSimilarity ss = new ScopedSimilarity();

    Searcher searcher = new IndexSearcher("path/to/index");
    HitCollector hc =;

With the following in ScopedQuery.ScopedWeight

createScorer(IndexReader reader)

   return new ScopedScorer(this, termDocs, similarity,

I'm hoping that I won't need to implement a new Query parser.

  - Shailesh

PS: Perhaps a useful API call would be Searcher.setScorer(Scorer s),
similar to the Searcher.setSimilarity call

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message