diff --git a/web/client/api/searchText.js b/web/client/api/searchText.js index 69d5ae7ad0..e42659b2e9 100644 --- a/web/client/api/searchText.js +++ b/web/client/api/searchText.js @@ -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 ); } diff --git a/web/client/plugins/Search.jsx b/web/client/plugins/Search.jsx index 59e940f4f9..eb18c20af7 100644 --- a/web/client/plugins/Search.jsx +++ b/web/client/plugins/Search.jsx @@ -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]