Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Added function_score to Sense KB
Browse files Browse the repository at this point in the history
Both on 0.90 and 1.0 apis.

Closes elastic#177
  • Loading branch information
bleskes committed Apr 24, 2014
1 parent 3c26c52 commit f4d578a
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 5 deletions.
73 changes: 70 additions & 3 deletions sense/app/kb/api_0_90/query.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(function () {
define(["_"], function (_) {
'use strict';

var SPAN_QUERIES = {
Expand All @@ -20,6 +20,51 @@ define(function () {
}
};

var DECAY_FUNC_DESC = {
__template: {
"FIELD": {
"origin": "",
"scale": ""
}
},
"{field}": {
"origin": "",
"scale": "",
"offset": "",
"decay": 0.5
}
},
SCORING_FUNCS = {
"script_score": {
__template: {
"script": "_score * doc['f'].value"
},
"script": "",
"lang": "mvel",
"params": {

}
},
"boost_factor": 2.0,
"random_score": {
"seed": 314159265359
},
"linear": DECAY_FUNC_DESC,
"exp": DECAY_FUNC_DESC,
"gauss": DECAY_FUNC_DESC,
"field_value_factor": {
__template: {
"field": ""
},
"field": "{field}",
"factor": 1.2,
"modifier": {
__one_of: ["none", "log", "log1p", "log2p", "ln", "ln1p", "ln2p", "square", "sqrt", "reciprocal"]
}
}
};


return function init(api) {
api.addGlobalAutocompleteRules('query', {
match: {
Expand Down Expand Up @@ -495,9 +540,31 @@ define(function () {
relation: 'within'
},
__scope_link: '.filter.geo_shape'
}
},
function_score: _.defaults({
__template: {
query: {

},
functions: [
{}
]
},
query: {},
filter: {},
functions: [
_.defaults(
{
filter: {}
},
SCORING_FUNCS
)
],
boost: 1.0,
boost_mode: { __one_of: ["multiply", "replace", "sum", "avg", "max", "min"]},
score_mode: { __one_of: ["multiply", "sum", "first", "avg", "max", "min"]},
max_boost: 10
}, SCORING_FUNCS)
});
};

});
72 changes: 70 additions & 2 deletions sense/app/kb/api_1_0/query.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(function () {
define(["_"], function (_) {
'use strict';

var SPAN_QUERIES = {
Expand All @@ -20,6 +20,50 @@ define(function () {
}
};

var DECAY_FUNC_DESC = {
__template: {
"FIELD": {
"origin": "",
"scale": ""
}
},
"{field}": {
"origin": "",
"scale": "",
"offset": "",
"decay": 0.5
}
},
SCORING_FUNCS = {
"script_score": {
__template: {
"script": "_score * doc['f'].value"
},
"script": "",
"lang": "mvel",
"params": {

}
},
"boost_factor": 2.0,
"random_score": {
"seed": 314159265359
},
"linear": DECAY_FUNC_DESC,
"exp": DECAY_FUNC_DESC,
"gauss": DECAY_FUNC_DESC,
"field_value_factor": {
__template: {
"field": ""
},
"field": "{field}",
"factor": 1.2,
"modifier": {
__one_of: ["none", "log", "log1p", "log2p", "ln", "ln1p", "ln2p", "square", "sqrt", "reciprocal"]
}
}
};

return function init(api) {
api.addGlobalAutocompleteRules('query', {
match: {
Expand Down Expand Up @@ -495,7 +539,31 @@ define(function () {
relation: 'within'
},
__scope_link: '.filter.geo_shape'
}
},
function_score: _.defaults({
__template: {
query: {

},
functions: [
{}
]
},
query: {},
filter: {},
functions: [
_.defaults(
{
filter: {}
},
SCORING_FUNCS
)
],
boost: 1.0,
boost_mode: { __one_of: ["multiply", "replace", "sum", "avg", "max", "min"]},
score_mode: { __one_of: ["multiply", "sum", "first", "avg", "max", "min"]},
max_boost: 10
}, SCORING_FUNCS)

});
};
Expand Down

0 comments on commit f4d578a

Please sign in to comment.