lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <>
Subject Re: Number Proximity Query
Date Wed, 04 Oct 2006 18:24:33 GMT

: (1) Should values returned by DocValues (return from ValueSource) must
: always betwen 1.0 and 0.0 ? How is this value affect the overall document
: scores, assuming there are others Query clauses as well that is perform on
: the document (on other fields).

The "values" returned by the various methods in DocValues can be anything
you want, as long as they conform to hte primitive datatype in the method
sig -- ideally whatever float floatVal returns should be roughly
equivilent to whever double you return from doubleVal so that your
ValueSource appears to behave the same way regardless of whatever other
ValueSources you may compose it in.

How the values affect the over all Document score really depends on how
big the values you return are, and how you compose your FunctionQuery with
the other parts of your query (presumably in a BooleanQuery)

Take a look at LinearFloatFunction and the DocValues it produces.  it's a
good example of what a "function" you want to be able to compose in a
function query should do.

If i remember your problem statement correctly, all you really need is an
AbsoluteValueFunction that you could compose with some linear functions
ala:  linear(abs(linear(field(x), -1, N), -1, M)))

...where N is the magic number you want your doc vals to be close to, M is
the biggest value you ever want your FunctionQuery to score a document
with, and field(x) is where you put a FieldCacheSource on the field you
care about.

Your AbsoluteValueFunction would look a lot like LinearFloatFunction, with
out the slope or intercept and a getValues method that looked something like...

  public DocValues getValues(IndexReader reader) throws IOException {
    final DocValues vals =  source.getValues(reader);
    return new DocValues() {
      public float floatVal(int doc) {
        return Math.abs(vals.floatVal(doc))

: (2) The documentation on the following functions is extremely lacking (no
: matter where I looked). Any expert here can help out ?
: -- Weight.getValue() : what values should be returned for
: NumberProximityQuery?
: -- Weight.sumOfSquareWeights() : no idea what is this for???
: -- Weight.normalize() : still no idea
: -- Scorer.score() : should this value always between 1.0 and 0.0 ?

I honestly don't remember off the top of me head what those methods are
for our how they come into play -- the scoring.html doc that's in progress
should help clear up some of that.  As i recall, the last time i needed to
understand what those methods did, i looked at some of the primitive query
types (like TermQuery and BooleanQuery) to see what they did.

The one thing I can tell you with certainty is that there is nothing
magical about scores between 0.0 and 1.0 -- the notion that Lucene Scores
are between 0 and 1 is a myth perpetuated by the Hits interface which does
a mock-normalization of the scores if the highest is greater then 1.
When you get down into the bowels of scoring, the scores can be any float
-- even negative numbers are legal scores.


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

View raw message