-
-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
autocomplete milestone #526
Changes from 14 commits
aa3e764
6d4e689
f7c64cb
3a789b4
9a5d425
e40c9ef
b80efff
30db744
25ab63c
3051885
01a3233
ca0c51b
b862fc8
2398f05
da4c666
9dbed08
e093a09
b771053
ee73774
e6d9a0c
0524062
1c9af40
979aab1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ query.score( peliasQuery.view.admin('country_a') ); | |
query.score( peliasQuery.view.admin('region') ); | ||
query.score( peliasQuery.view.admin('region_a') ); | ||
query.score( peliasQuery.view.admin('county') ); | ||
query.score( peliasQuery.view.admin('borough') ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove this to avoid having any effect on search from this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moving this to #527 |
||
query.score( peliasQuery.view.admin('localadmin') ); | ||
query.score( peliasQuery.view.admin('locality') ); | ||
query.score( peliasQuery.view.admin('neighbourhood') ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ or postalcode because we should only try to match those when we're sure that's w | |
*/ | ||
var adminFields = placeTypes.concat([ | ||
'region_a', | ||
'borough' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't need to be done since placeTypes already has borough in the list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! |
||
]); | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
var peliasQuery = require('pelias-query'), | ||
searchDefaults = require('../search_defaults'); | ||
|
||
/** | ||
This view (unfortunately) requires autocomplete to use the phrase.* index. | ||
|
||
ideally we wouldn't need to use this, but at time of writing we are unable | ||
to distinguish between 'complete tokens' and 'grams' in the name.* index. | ||
|
||
this view was introduced in order to score exact matches higher than partial | ||
matches, without it we find results such as "Clayton Avenue" appearing first | ||
in the results list for the query "Clay Av". | ||
|
||
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 | ||
than partial matches. | ||
**/ | ||
|
||
module.exports = 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']); | ||
|
||
// split the 'input:name' on whitespace | ||
var name = vs.var('input:name').get(), | ||
tokens = name.split(' '); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps split on any whitespace so that multiple spaces, tabs, or any other weird stuff is handled ok? Or would that be cleaned up by a sanitizer before this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could result in empty tokens if there are multiple spaces in a row. just doesn't feel like a very clean solution. |
||
|
||
// if the query is incomplete then we need to remove | ||
// the final (incomplete) token as it will not match | ||
// tokens in the phrase.* index. | ||
if( !vs.var('input:name:isComplete').get() ){ | ||
tokens.pop(); | ||
} | ||
|
||
// no valid tokens to use, fail now, don't render this view. | ||
if( tokens.length < 1 ){ return null; } | ||
|
||
// set 'input:name' to be only the fully completed characters | ||
vsCopy.var('input:name').set( tokens.join(' ') ); | ||
|
||
return peliasQuery.view.phrase( vsCopy ); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
var peliasQuery = require('pelias-query'); | ||
|
||
/** | ||
Population / Popularity subquery | ||
**/ | ||
|
||
module.exports = function( vs ){ | ||
|
||
var view = peliasQuery.view.ngrams( vs ); | ||
|
||
view.match['name.default'].analyzer = vs.var('phrase:analyzer'); | ||
delete view.match['name.default'].boost; | ||
|
||
return view; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why so high?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simply copied the value from 'country', I will drop it down to a value for 'region' instead if you feel it's too high. What would you suggest as a good value here?