Skip to content

Commit

Permalink
clean up + make work, tests still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
blackmad committed Aug 12, 2020
1 parent 1101715 commit c073bfd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 46 deletions.
24 changes: 1 addition & 23 deletions controller/search.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const _ = require('lodash');
const querystring = require('querystring');

const logger = require('pelias-logger').get('api');

const searchService = require('../service/search');
const logger = require('pelias-logger').get('api');
const logging = require( '../helper/logging' );
const retry = require('retry');
const Debug = require('../helper/debug');
Expand Down Expand Up @@ -136,25 +133,6 @@ function setup( peliasConfig, esclient, query, should_execute ){
// be results. if there are no results from this ES call, don't overwrite
// what's already there from a previous call.
if (!_.isEmpty(docs)) {
if (req.clean.exposeInternalDebugTools && req.clean.enableDebug) {

// Add an ES explain link to each document
docs.forEach((doc) => {
const docDebugInfo = {};
if (req.headers.host) {
const requestPath = `${req.path}?${ querystring.stringify({
...req.query,
restrictIds: doc._id,
debug: 'explain'
}) }`;

docDebugInfo.esExplainUrl = `${ req.secure ? 'https' : 'http' }://${req.headers.host}${requestPath}`;
}

doc.debug = [docDebugInfo];
});
}

res.data = docs;
res.meta = meta || {};
// store the query_type for subsequent middleware
Expand Down
1 change: 1 addition & 0 deletions query/autocomplete_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'phrase:boost': 1,
'phrase:slop': 3,
'phrase:cutoff_frequency': 0.01,
'phrase:minimum_should_match': '1<-1 3<-50%',

'focus:function': 'exp',
'focus:offset': '0km',
Expand Down
31 changes: 16 additions & 15 deletions query/view/phrase_first_all_tokens_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@ const toMultiFields = require('./helper').toMultiFields;
const _ = require('lodash');

module.exports = function (vs) {
console.log(vs.var('input:name:raw_tokens').get(), vs.var('input:name:tokens').get());
console.log(_.eq(vs.var('input:name:raw_tokens').get(), vs.var('input:name:tokens').get()));
console.log(vs.var('input:name:raw_tokens').get() === vs.var('input:name:tokens').get());
if (vs.var('input:name:raw_tokens').get().length === vs.var('input:name:tokens').get().length) {
const view_name = 'first_all_tokens_only';
// get a copy of the *complete* tokens produced from the input:name
const raw_complete_tokens = vs.var('input:name:raw_tokens_complete').get();

// if the parsed tokens (what's going to be searched in the must), are the same as the raw tokens
// don't use this query since it will be redundant
if (raw_complete_tokens.length === vs.var('input:name:tokens').get().length) {
return null;
}

// if there's a housenumber and a street, don't do this because it might
// make housenumber matching way too lenient
if (vs.isset('input:housenumber') && vs.isset('input:street')) {
return null;
}

const view_name = 'first_all_tokens_only';
// get a copy of the *complete* tokens produced from the input:name
console.log(vs.var('input:name:raw_tokens').get());
const tokens = vs.var('input:name:raw_tokens_complete').get();
console.log('all tokens only', { tokens });

// no valid tokens to use, fail now, don't render this view.
if (!tokens || tokens.length < 1) {
if (!raw_complete_tokens || raw_complete_tokens.length < 1) {
return null;
}

// set the 'input' variable to all but the last token
vs.var(`match:${view_name}:input`).set(tokens.join(' '));
vs.var(`match:${view_name}:input`).set(raw_complete_tokens.join(' '));
vs.var(`match:${view_name}:field`).set(vs.var('phrase:field').get());

vs.var(`match:${view_name}:analyzer`).set(vs.var('phrase:analyzer').get());
vs.var(`match:${view_name}:boost`).set(vs.var('phrase:boost').get());

// vs.var(`match:${view_name}:minimum_should_match`).set(vs.var('ngram:minimum_should_match').get());
vs.var(`match:${view_name}:minimum_should_match`).set('1<-1 3<-25%');
vs.var(`match:${view_name}:minimum_should_match`).set(vs.var('phrase:minimum_should_match').get());

return peliasQuery.view.leaf.match(view_name)(vs);
};
8 changes: 0 additions & 8 deletions sanitizer/_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ function _setup(exposeInternalDebugTools) {
}
}

if (raw.restrictIds) {
if (exposeInternalDebugTools) {
clean.restrictIds = raw.restrictIds.split(',');
} else {
messages.errors.push('restrictIds not enabled, must enable exposeInternalDebugTools in pelias config');
}
}

return messages;
},

Expand Down

0 comments on commit c073bfd

Please sign in to comment.