Skip to content

Commit

Permalink
Made nested services more generic
Browse files Browse the repository at this point in the history
Now instead of filterTemplate we have the selected item passed to the nested service.
The nested service will use it to generate the new search.
  • Loading branch information
offtherailz committed Mar 27, 2017
1 parent 3d10eb4 commit 66f2ddc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions web/client/api/searchText.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const WFS = require('./WFS');
const assign = require('object-assign');
const GeoCodeUtils = require('../utils/GeoCodeUtils');
const {generateTemplateString} = require('../utils/TemplateUtils');
/*
const toNominatim = (fc) =>
fc.features && fc.features.map( (f) => ({
Expand All @@ -24,8 +25,9 @@ module.exports = {
require('./Nominatim')
.geocode(searchText, options)
.then( res => GeoCodeUtils.nominatimToGeoJson(res.data)),
wfs: (searchText, {url, typeName, queriableAttributes, outputFormat="application/json", predicate ="ILIKE", staticFilter="", blacklist = [], ...params }) => {
wfs: (searchText, {url, typeName, queriableAttributes, outputFormat="application/json", predicate ="ILIKE", staticFilter="", blacklist = [], item, ...params }) => {
// split into words and remove blacklisted words
const staticFilterParsed = generateTemplateString(staticFilter || "")(item);
let searchWords = searchText.split(" ").filter(w => w).filter( w => blacklist.indexOf(w.toLowerCase()) < 0 );

// if the searchtext is empty use the full searchText
Expand All @@ -39,7 +41,7 @@ module.exports = {
typeName,
outputFormat,
// 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)
cql_filter: "(".concat( searchWords.map( (w) => queriableAttributes.map( attr => `${attr} ${predicate} '%${w.replace("'", "''")}%'`).join(" OR ")).join(') AND (')).concat(")") .concat(staticFilterParsed)
}, params))
.then( response => response.features );
}
Expand Down
6 changes: 3 additions & 3 deletions web/client/epics/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const searchEpic = action$ =>
*/
const searchItemSelected = action$ =>
action$.ofType(TEXT_SEARCH_ITEM_SELECTED)
.mergeMap(action => {
.switchMap(action => {
const item = action.item;


Expand Down Expand Up @@ -117,8 +117,8 @@ const searchItemSelected = action$ =>
nestedServices.map((nestedService) => ({
...nestedService,
options: {
...nestedService.options,
staticFilter: generateTemplateString(nestedService.filterTemplate || "")(item)
item,
...nestedService.options
}
})), {
text: generateTemplateString(item.__SERVICE__.displayName || "")(item),
Expand Down

0 comments on commit 66f2ddc

Please sign in to comment.