UNPKG

1.2 kBJavaScriptView Raw
1
2/**
3 And example of a linguistic search which ranks local records
4 higher than those far away (but does not exclude them)
5**/
6
7// this is our target point (somewhere in London)
8var focus = { lat: 51.5, lon: -0.06 };
9
10var query = require('../index'),
11 vs = new query.Vars( query.defaults );
12
13/**
14 build a query with 2 conditions:
15 - the linguistic matching strategy for scoring (phrase)
16 - the geographic decay function (focus)
17**/
18var q = new query.layout.FilteredBooleanQuery()
19 .score( query.view.phrase )
20 .score( query.view.focus( query.view.phrase ) );
21
22/**
23 configure implementation-specific settings:
24 - phrase settings
25 - focus settings
26**/
27vs.set({
28 'phrase:field': 'phrase.default',
29 'phrase:analyzer': 'standard',
30 'focus:function': 'gauss',
31 'focus:offset': '10km',
32 'focus:scale': '100km',
33 'focus:decay': 0.4
34});
35
36/**
37 set the user-specific variables:
38 - the input text provided by the user
39 - the input point to use for localization
40**/
41vs.var( 'input:name', 'union square' );
42vs.var('focus:point:lat', focus.lat);
43vs.var('focus:point:lon', focus.lon);
44
45// render the query
46var rendered = q.render( vs );
47console.log( JSON.stringify( rendered, null, 2 ) );