|
|
@ -14,26 +14,58 @@ var peliasQuery = require('pelias-query'), |
|
|
|
the view uses some of the values from the 'search_defaults.js' file to add an |
|
|
|
the view uses some of the values from the 'search_defaults.js' file to add an |
|
|
|
additional 'SHOULD' condition which scores exact matches slighly higher |
|
|
|
additional 'SHOULD' condition which scores exact matches slighly higher |
|
|
|
than partial matches. |
|
|
|
than partial matches. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
the 'includePartialTokens' variable was introduced in order to allow the view |
|
|
|
|
|
|
|
to be reused as an additional boost for tokens which are in fact complete, |
|
|
|
|
|
|
|
despite us not knowing for sure whether they are complete or not. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
an example is 'Stop 2', without partial tokens the boost will only apply to |
|
|
|
|
|
|
|
documents matching 'stop', with an additional view we can further boost |
|
|
|
|
|
|
|
documents matching 'stop 2'. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
note: it is most likely insufficent to include a version of this view in your |
|
|
|
|
|
|
|
query which has includePartialTokens=true without also having a copy with |
|
|
|
|
|
|
|
includePartialTokens=false. One view will boost the tokens that are known to |
|
|
|
|
|
|
|
be complete and the other will additionally boost tokens which may or may not be |
|
|
|
|
|
|
|
complete, as per the example above. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
note: a clause has been included in the code which disables the view for |
|
|
|
|
|
|
|
includePartialTokens=true if it would generate the exact same view as for |
|
|
|
|
|
|
|
includePartialTokens=false. |
|
|
|
**/ |
|
|
|
**/ |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function( vs ){ |
|
|
|
module.exports = function( includePartialTokens ){ |
|
|
|
|
|
|
|
return function( vs ){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// make a copy of the variables so we don't interfere with the values
|
|
|
|
|
|
|
|
// passed to other views.
|
|
|
|
|
|
|
|
var vsCopy = new peliasQuery.Vars( vs.export() ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// copy phrase:* values from search defaults
|
|
|
|
|
|
|
|
vsCopy.var('phrase:analyzer').set(searchDefaults['phrase:analyzer']); |
|
|
|
|
|
|
|
vsCopy.var('phrase:field').set(searchDefaults['phrase:field']); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get a copy of only the *complete* tokens produced from the input:name
|
|
|
|
|
|
|
|
var tokens = vs.var('input:name:tokens_complete').get(); |
|
|
|
|
|
|
|
|
|
|
|
// make a copy of the variables so we don't interfere with the values
|
|
|
|
if( includePartialTokens ){ |
|
|
|
// passed to other views.
|
|
|
|
// get a copy of *all* tokens produced from the input:name (including partial tokens)
|
|
|
|
var vsCopy = new peliasQuery.Vars( vs.export() ); |
|
|
|
var allTokens = vs.var('input:name:tokens').get(); |
|
|
|
|
|
|
|
|
|
|
|
// copy phrase:* values from search defaults
|
|
|
|
// a duplicate view would be generated, fail now, don't render this view.
|
|
|
|
vsCopy.var('phrase:analyzer').set(searchDefaults['phrase:analyzer']); |
|
|
|
// see file comments for more info
|
|
|
|
vsCopy.var('phrase:field').set(searchDefaults['phrase:field']); |
|
|
|
if( allTokens.join(' ') === tokens.join(' ') ){ return null; } |
|
|
|
|
|
|
|
|
|
|
|
// get a copy of the *complete* tokens produced from the input:name
|
|
|
|
// use *all* the tokens for this view instead of only the complete tokens.
|
|
|
|
var tokens = vs.var('input:name:tokens_complete').get(); |
|
|
|
tokens = allTokens; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// no valid tokens to use, fail now, don't render this view.
|
|
|
|
// no valid tokens to use, fail now, don't render this view.
|
|
|
|
if( !tokens || tokens.length < 1 ){ return null; } |
|
|
|
if( !tokens || tokens.length < 1 ){ return null; } |
|
|
|
|
|
|
|
|
|
|
|
// set 'input:name' to be only the fully completed characters
|
|
|
|
// set 'input:name' to be only the fully completed characters
|
|
|
|
vsCopy.var('input:name').set( tokens.join(' ') ); |
|
|
|
vsCopy.var('input:name').set( tokens.join(' ') ); |
|
|
|
|
|
|
|
|
|
|
|
return peliasQuery.view.phrase( vsCopy ); |
|
|
|
return peliasQuery.view.phrase( vsCopy ); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|