From 979aab1ac3231cf598ebcf0df1c4d6f2fee26fa4 Mon Sep 17 00:00:00 2001 From: missinglink Date: Fri, 29 Apr 2016 19:10:52 +0200 Subject: [PATCH] ensure that problematic single grams are removed from the query --- query/autocomplete.js | 15 ++++++++++----- query/view/pop_subquery.js | 16 ---------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/query/autocomplete.js b/query/autocomplete.js index 50f6da29..6d5863a8 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -74,11 +74,16 @@ function generateQuery( clean ){ // input text vs.var( 'input:name', clean.text ); - // if the input parser has run and suggested a 'parsed_text.name' to use. - if( clean.hasOwnProperty('parsed_text') && clean.parsed_text.hasOwnProperty('name') ){ - - // use 'parsed_text.name' instead of 'clean.text'. - vs.var( 'input:name', clean.parsed_text.name ); + // if the tokenizer has run then we set 'input:name' to as the combination of the + // 'complete' tokens with the 'incomplete' tokens, the resuting array differs + // slightly from the 'input:name:tokens' array as some tokens might have been + // removed in the process; such as single grams which are not present in then + // ngrams index. + if( check.array( clean.tokens_complete ) && check.array( clean.tokens_incomplete ) ){ + var combined = clean.tokens_complete.concat( clean.tokens_incomplete ); + if( combined.length ){ + vs.var( 'input:name', combined.join(' ') ); + } } // focus point diff --git a/query/view/pop_subquery.js b/query/view/pop_subquery.js index f29191fc..724b773f 100644 --- a/query/view/pop_subquery.js +++ b/query/view/pop_subquery.js @@ -13,21 +13,5 @@ module.exports = function( vs ){ view.match['name.default'].analyzer = vs.var('phrase:analyzer'); delete view.match['name.default'].boost; - // only use complete tokens against the phase index (where possible). - var completeTokens = vs.var('input:name:tokens_complete').get(), - incompleteTokens = vs.var('input:name:tokens_incomplete').get(); - - // if the tokenizer has run (autocomplete only) then we will combine the - // 'complete' tokens with the 'incomplete' tokens, the resuting array differs - // slightly from the 'input:name:tokens' array as some tokens might have been - // removed in the process; such as single grams which are not present in then - // ngrams index. - if( check.array( completeTokens ) && check.array( incompleteTokens ) ){ - var combined = completeTokens.concat( incompleteTokens ); - if( combined.length ){ - view.match['name.default'].query = combined.join(' '); - } - } - return view; };