DocValues | Expert: represents field values as different types. | code | html |
FieldCacheSource | Expert: A base class for ValueSource implementations that retrieve values for a single field from the FieldCache . | code | html |
ValueSource | Expert: source of values for basic function queries. | code | html |
ByteFieldSource | Expert: obtains single byte field values from the
FieldCache
using getBytes() and makes those values
available as other numeric types, casting as needed. |
code | html |
CustomScoreProvider | An instance of this subclass should be returned by CustomScoreQuery#getCustomScoreProvider , if you want to modify the custom score calculation of a CustomScoreQuery . | code | html |
CustomScoreQuery | Query that sets document score as a programmatic function of several (sub) scores:
|
code | html |
CustomScoreQuery.CustomScorer | A scorer that applies a (callback) function on scores of the subQuery. | code | html |
CustomScoreQuery.CustomWeight | code | html | |
FieldScoreQuery | A query that scores each document as the value of the numeric input field. | code | html |
FieldScoreQuery.Type | Type of score field, indicating how field values are interpreted/parsed. | code | html |
FloatFieldSource | Expert: obtains float field values from the
FieldCache
using getFloats() and makes those values
available as other numeric types, casting as needed. |
code | html |
IntFieldSource | Expert: obtains int field values from the
FieldCache
using getInts() and makes those values
available as other numeric types, casting as needed. |
code | html |
OrdFieldSource | Expert: obtains the ordinal of the field value from the default Lucene Fieldcache using getStringIndex(). | code | html |
ReverseOrdFieldSource | Expert: obtains the ordinal of the field value from the default Lucene FieldCache using getStringIndex() and reverses the order. | code | html |
ShortFieldSource | Expert: obtains short field values from the
FieldCache
using getShorts() and makes those values
available as other numeric types, casting as needed. |
code | html |
ValueSourceQuery | Expert: A Query that sets the scores of document to the values obtained from a ValueSource . | code | html |
ValueSourceQuery.ValueSourceScorer | A scorer that (simply) matches all documents, and scores each document with the value of the value source in effect. | code | html |
ValueSourceQuery.ValueSourceWeight | code | html |
function
package provides tight control over documents scores.
Note: code snippets here should work, but they were never really compiled... so, tests sources under TestCustomScoreQuery, TestFieldScoreQuery and TestOrdValues may also be useful.
Indexing:
f = new Field("score", "7", Field.Store.NO, Field.Index.UN_TOKENIZED); f.setOmitNorms(true); d1.add(f);
Search:
Query q = new FieldScoreQuery("score", FieldScoreQuery.Type.BYTE);Document d1 above would get a score of 7.
Dividing the original score of each document by a square root of its docid (just to demonstrate what it takes to manipulate scores this way)
Query q = queryParser.parse("my query text"); CustomScoreQuery customQ = new CustomScoreQuery(q) { public float customScore(int doc, float subQueryScore, float valSrcScore) { return subQueryScore / Math.sqrt(docid); } };
For more informative debug info on the custom query, also override the name() method:
CustomScoreQuery customQ = new CustomScoreQuery(q) { public float customScore(int doc, float subQueryScore, float valSrcScore) { return subQueryScore / Math.sqrt(docid); } public String name() { return "1/sqrt(docid)"; } };
Taking the square root of the original score and multiplying it by a "short field driven score", ie, the short value that was indexed for the scored doc in a certain field:
Query q = queryParser.parse("my query text"); FieldScoreQuery qf = new FieldScoreQuery("shortScore", FieldScoreQuery.Type.SHORT); CustomScoreQuery customQ = new CustomScoreQuery(q,qf) { public float customScore(int doc, float subQueryScore, float valSrcScore) { return Math.sqrt(subQueryScore) * valSrcScore; } public String name() { return "shortVal*sqrt(score)"; } };