tags:

views:

480

answers:

2

Is it possible to adjust the boost of a field with the Query object before running the search? I know the proper way to do it is to change the fields boost during indexing, but it takes about 4 days to make an index and was just wondering if there's a quick hack i can do for now.

also i have tried hardcoding in the boost to the search query, ie AND field(this that other)^7

and that works, and it would be the end of it, EXCEPT i want to reduce the relevance of this part of the query, i want

AND field(this that other)^.1

but i get empty results.

thanks

A: 

You can extend Similarity and in the Searcher, use

setSimilarity(Similarity)

By extending Similarity, you can adapt the scoring mechanism in Lucene to your needs.

EDIT:

More specifically, you can override the lengthNorm method in Similarity (or a subclass thereof):

public float lengthNorm(String fieldName, int numTokens){
    return fieldWeights.get(fieldName)*super.lengthNorm(fieldName, numTokens);
}

fieldWeights could be a Map attribute in which you specify the weight you want to attach to each field. If you keep a reference to fieldWeights somewhere, you can change the field weights to whatever you want just before you perform a search (But do this for only one query at a time, to experiment).

lbp
A: 

Why not just boost the terms you want with a higher value and leave the ones you are trying to un-boost at zero?

Gandalf