Skip to content

Instantly share code, notes, and snippets.

@polyfractal
Created April 9, 2014 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polyfractal/10276706 to your computer and use it in GitHub Desktop.
Save polyfractal/10276706 to your computer and use it in GitHub Desktop.
termInfo = _index[field].get(term,_PAYLOADS);
score = 0;
for (pos : termInfo) {
score = score + pos.payloadAsFloat(0);
}
return score;
curl -XPUT "http://localhost:9200/syn" -d'
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"boosted_syn" : {
"tokenizer" : "whitespace",
"filter" : [
"lowercase",
"syns",
"delimited_payload_filter"
]
}
},
"filter" : {
"syns" : {
"type" : "synonym",
"synonyms" : [
"potato=>vegetable|3",
"tomato=>vegetable|2",
"carrot=>vegetable|1"
]
}
}
}
}
},
"mappings": {
"data" : {
"properties": {
"title" : {
"type": "string",
"analyzer": "boosted_syn"
}
}
}
}
}'
curl -XPOST "http://localhost:9200/syn/data/1" -d'
{
"title" : "vegetable"
}'
curl -XPOST "http://localhost:9200/syn/data/2" -d'
{
"title" : "potato"
}'
curl -XPOST "http://localhost:9200/syn/data/3" -d'
{
"title" : "tomato"
}'
curl -XPOST "http://localhost:9200/syn/data/4" -d'
{
"title" : "carrot"
}'
curl -XGET "http://localhost:9200/syn/data/_search" -d'
{
"query": {
"function_score" : {
"query" : {
"match": {
"title": "vegetable"
}
},
"script_score" : {
"script" : "boosted_syn",
"params" : {
"field" : "title",
"term" : "vegetable"
}
},
"boost_mode" : "replace"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment