Skip to content

Commit

Permalink
Add support for blacklist and word splitting in wfs search (#1647)
Browse files Browse the repository at this point in the history
* Add support for blacklist and word splitting in wfs search

* updated documentation
  • Loading branch information
offtherailz authored Mar 27, 2017
1 parent e81ecb3 commit 3d10eb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit 3d10eb4

Please sign in to comment.