eas.math.gnuplot2.DataTable
Model definition part; this json is used to define a model (input variables, // columns/facets, and function parameters and body); "model": { "variables": { "set_int":["c","d"], // supported hashset types: [set_int, set_float, set_string, // set_double, set_long] "map_int_float":["j"], // supported hashmap: [map_int_float, map_int_double, map_int_*...] // [map_string_int, map_string_float, map_string_*] "int":["e","f"], // supported normal variables: [int, double, float, long, bool, string] "long":["g","h"], "custom_obj":["krati","big_cache"] // supported external static big in-memory object (initialized when senseidb starts) }, "facets": { "int":["year","age"], // facet type support: [double, float, int, long, short, string]; "long":["time"] // facet variable has the same name as the facet name, and they // are defined inside this json; }, // (2) Scoring function and function input parameters in Java; A scoring function and its // parameters are the model. A model changes when the function body or signature // changes; // Params for the function. The symbol order matters, and symbols must be those defined // above. innerScore MUST be used, otherwise, makes no sense to use the custom relevance; // reserved keyword for internal parameters are: "_INNER_SCORE" and "_NOW" "function_params":["_INNER_SCORE", "timeVal", "_timeWeight", "_waterworldWeight", "_half_time"], // The value string in the following JSONObject is like this (a return statement MUST // appear as the last one): // // float delta=System.currentTimeMillis() - timeVal; // float t=delta>0 ? delta : 0; // float hour = t/(1000*3600); // float timeScore = (float) Math.exp(-(hour/_half_time)); // float waterworldScore = _INNER_SCORE; // float time = timeScore * _timeWeight; // float water = waterworldScore * _waterworldWeight; // return (time + water); "function":"A LONG JAVA CODE STRING HERE, ONLY AS FUNCTION BODY, NEEDS RETURN STATEMENT." } // (3) Input values for the model above, if the model requires input values; "values": { "c":[1996,1997], "e":0.98, "j":{"1":2.3, "2":3.4, "3":2.9} // A user input hashmap; "jj":{"key":[1,2,3], "value":[2.3, 3.4, 2.9]} // It also supports this method to pass in a map. } } A dummy testing relevance json inside a query request json may look like this: { "query": { "query_string": { "query": "", "relevance":{ "model":{ "variables":{ "set_int":["goodYear"], "int":["thisYear"], "string":["coolTag"], "map_int_float":["mileageWeight"], "map_int_string":["yearcolor"], "map_string_float":["colorweight"], "map_string_string":["categorycolor"] }, "facets":{ "int":["year","mileage"], "long":["groupid"], "string":["color","category"], "mstring":["tags"] }, "function_params":["_INNER_SCORE", "thisYear", "year", "goodYear", "mileageWeight", "mileage", "color", "yearcolor", "colorweight", "category", "categorycolor"], "function":" if (tags.contains(coolTag)) \ return 999999f; \ if (categorycolor.containsKey(category) \ && categorycolor.get(category).equals(color)) \ return 10000f; \ if (colorweight.containsKey(color)) \ return 200f + colorweight.getFloat(color); \ if (yearcolor.containsKey(year) && \ yearcolor.get(year).equals(color)) \ return 200f; \ if (mileageWeight.containsKey(mileage)) \ return 10000+mileageWeight.get(mileage); \ if (goodYear.contains(year)) \ return (float)Math.exp(2d); \ if (year == thisYear) \ return 87f; \ return _INNER_SCORE;" }, "values":{ "goodYear":[1996,1997], "thisYear":2001, "mileageWeight":{"11400":777.9, "11000":10.2}, "yearcolor":{"1998":"red"}, "colorweight":{"red":335.5}, "categorycolor":{"compact":"red"}, "coolTag":"cool" } } } }, "from": 0, "size": 6, "explain": false, "fetchStored": false, "sort":["_score"] } An advanded usage of weighted multi-facet relevance can be: { "query": { "query_string": { "query": "java", "relevance": { "model": { "variables": { "string":["skill"] }, "facets": { "wmstring":["user_skills"] }, "function_params":["_INNER_SCORE", "user_skills", "skill"], "function":" int weight = 0; \ if (user_skills.hasWeight(skill)) \ weight = user_skills.getWeight(); \ return _INNER_SCORE + weight;" }, "values": { "skill":"java" } } } }, "selections": [ { "terms": { "country_code": { "values": ["us"], "excludes": [], "operator": "or" } } }], "from": 0, "size": 10, "explain": false, "fetchStored": false }