Skip to content
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

Add support for blacklist and word splitting in wfs search #1647

Merged
merged 2 commits into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions web/client/api/searchText.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ module.exports = {
require('./Nominatim')
.geocode(searchText, options)
.then( res => GeoCodeUtils.nominatimToGeoJson(res.data)),
wfs: (searchText, {url, typeName, queriableAttributes, outputFormat="application/json", predicate ="ILIKE", staticFilter="", ...params }) => {
wfs: (searchText, {url, typeName, queriableAttributes, outputFormat="application/json", predicate ="ILIKE", staticFilter="", blacklist = [], ...params }) => {
// split into words and remove blacklisted words
let searchWords = searchText.split(" ").filter(w => w).filter( w => blacklist.indexOf(w.toLowerCase()) < 0 );

// if the searchtext is empty use the full searchText
if (searchWords.length === 0 ) {
searchWords = [searchText];
}
return WFS
.getFeatureSimple(url, assign({
maxFeatures: 10,
startIndex: 0,
typeName,
outputFormat,
cql_filter: queriableAttributes.map( attr => `${attr} ${predicate} '%${searchText}%'`).join(' OR ').concat(staticFilter)
// create a filter like : `(ATTR ilike '%word1%') AND (ATTR ilike '%word2%')`
cql_filter: "(".concat( searchWords.map( (w) => queriableAttributes.map( attr => `${attr} ${predicate} '%${w.replace("'", "''")}%'`).join(" OR ")).join(') AND (')).concat(")") .concat(staticFilter)
}, params))
.then( response => response.features );
}
Expand Down
3 changes: 2 additions & 1 deletion web/client/plugins/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ const ToggleButton = require('./searchbar/ToggleButton');
* "queriableAttributes": ["attribute_to_query"],
* "sortBy": "ID",
* "srsName": "EPSG:4326",
* "maxFeatures": 4
* "maxFeatures": 4,
* "blackist": [... an array of strings to exclude from the final search filter ]
* },
* "nestedPlaceholder": "Write other text to refine the search...",
* "then": [ ... an array of services to use when one item of this service is selected]
Expand Down