Hi, thanks for the hint. Actually I've done all this. Let me put some more
details :
I've made already my custom similarity :
public class CustomSimilarityProvider extends AbstractSimilarityProvider {
private final CustomSimilarity similarity;
@Inject
protected CustomSimilarityProvider(@Assisted String name) {
super(name);
this.similarity = new CustomSimilarity();
}
@Override
public Similarity get() {
return similarity;
}
}
public class CustomSimilarity extends DefaultSimilarity {
@Override
public float scorePayload(int doc, int start, int end, BytesRef payload) {
if (payload != null) {
return PayloadHelper.decodeFloat(payload.bytes);
} else {
return 1.0F;
}
}
}
I've created my own queryParser :
public class PayloadQueryParser implements QueryParser {
<...>
public Query parse(QueryParseContext parseContext) throws IOException,
QueryParsingException {
XContentParser parser = parseContext.parser();
<...>
return query; // A PayloadTermQuery
}
}
I've registered all these using a Plugin registering with the dedicated
module :
public void processModule(Module module) {
<...>
if(module instanceof IndexQueryParserModule){
((IndexQueryParserModule) module).addQueryParser("payload_query",
PayloadQueryParser.class);
}
}
But seems I'm missing something so that the Similarity is actually used for
scoring.
I've noticed in the QueryParserContext that it makes reference to the
defaultSimilarity, but not only. May it be linked with the configuration of
the mapping, or there is a trick to register and make use of the
similarity?
I've been lurking around in the code. I haven't found a hint about it yet.
Luca maybe you know the classes that use the similarity ?
Actually in Lucene, I would inject the similarity as follow:
this.isearcher = new IndexSearcher(reader);
isearcher.setSimilarity(new PayloadSimilarity());
before executing a PayloadTermQuery.
BR,
Aurelien
Le mardi 10 septembre 2013 20:11:19 UTC+3, Luca Cavanna a écrit :
The scoring part is in the similarity. Have a look here for an example of
custom similarity:
GitHub - tlrx/elasticsearch-custom-similarity-provider: A custom SimilarityProvider example for Elasticsearch .
If you want to score based on payloads the interesting method to override
in your own similarity should be the scorePayload one. The lucene javadochttp://lucene.apache.org/core/4_4_0/core/org/apache/lucene/search/similarities/TFIDFSimilarity.html#scorePayload(int,+int,+int,+org.apache.lucene.util.BytesRef)should help understanding what you need to do.
Cheers
Luca
On Tuesday, September 10, 2013 12:02:28 PM UTC+2, Aurélien wrote:
Hi,
In the continuity of a development to integrate payloads into my elastic
search application, I developped successfully custom analyzers, custom
similarity and custom queyr parser. BTW, if someone is interested by code
example for a custom query parser, let me know, I'll take some time to put
it on github.
Now my issue is to use my custom similarity into the scoring process of
the custom query parser. Can someone give me some ideas how and where this
is done in the code ?
Thank you all.
Aurelien
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.