Amplifying lucene in fields while searching

Can I customize the promotion of a field with a Query object before running the search? I know the correct way to do this is to change the increment of fields while indexing, but it takes about 4 days to create an index, and I'm just wondering if you have a quick hack I can do now.

also i tried hard coding in amplifying the search term i.e. AND (this is different) ^ 7

and it works and that will be the end of this, EXCEPTION I want to decrease the relevance of this part of the query, I want

And the field (this is different) ^. 1

but I am getting empty results.

thank

+2


source to share


2 answers


You can expand the similarity in Searcher too, use

setSimilarity(Similarity)

      

By expanding the similarity, you can tailor the scoring engine in Lucene to your needs.

EDIT:



In particular, you can override the lengthNorm method in affinity (or a subclass of it):

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

      

fieldWeights can be a Map attribute where you specify the weight you want to attach to each field. If you reference fieldWeights anywhere, you can change the field weights to whatever you want before doing the search (but only do this for one query at a time, experiment).

+2


source


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



0


source







All Articles