-
Notifications
You must be signed in to change notification settings - Fork 405
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
Fixed #1634 added support to custom search services and minor fixes #1664
Merged
MV88
merged 6 commits into
geosolutions-it:master
from
MV88:iss_1634_search_custom_service
Mar 31, 2017
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ module.exports = { | |
}], | ||
"toolsOptions": { | ||
"test": { | ||
"label": "ciao" | ||
"label": "Hello" | ||
} | ||
... | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,40 +9,91 @@ 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) => ({ | ||
boundingbox: f.properties.bbox, | ||
lat: 1, | ||
lon: 1, | ||
display_name: `${f.properties.STATE_NAME} (${f.properties.STATE_ABBR})` | ||
|
||
})); | ||
*/ | ||
|
||
module.exports = { | ||
const axios = require('axios'); | ||
const urlUtil = require('url'); | ||
let Services = { | ||
nominatim: (searchText, options = {}) => | ||
require('./Nominatim') | ||
.geocode(searchText, options) | ||
.then( res => GeoCodeUtils.nominatimToGeoJson(res.data)), | ||
wfs: (searchText, {url, typeName, queriableAttributes, outputFormat="application/json", predicate ="ILIKE", staticFilter="", blacklist = [], item, ...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 | ||
// if the array searchWords is empty, then use the full searchText | ||
if (searchWords.length === 0 ) { | ||
searchWords = [searchText]; | ||
searchWords = !!searchText ? [searchText] : []; | ||
} | ||
let filter; | ||
if (searchWords.length > 0 ) { | ||
filter = "(".concat( searchWords.map( (w) => queriableAttributes.map( attr => `${attr} ${predicate} '%${w.replace("'", "''")}%'`).join(" OR ")).join(') AND (')).concat(")"); | ||
} | ||
|
||
filter = filter ? filter.concat(staticFilterParsed) : staticFilterParsed || null; | ||
|
||
return WFS | ||
.getFeatureSimple(url, assign({ | ||
maxFeatures: 10, | ||
startIndex: 0, | ||
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(staticFilterParsed) | ||
}, params)) | ||
maxFeatures: 10, | ||
typeName, | ||
outputFormat, | ||
// create a filter like : `(ATTR ilike '%word1%') AND (ATTR ilike '%word2%')` | ||
cql_filter: filter | ||
}, params)) | ||
.then( response => response.features ); | ||
}, | ||
bzVie: (searchText, {pathname, lang}) => { | ||
let params = assign({}, {query: searchText, lang}); | ||
let url = urlUtil.format({ | ||
pathname, | ||
query: params | ||
}); | ||
return axios.post(url).then( (res) => { | ||
if (res && res.data && res.data.success) { | ||
return res.data.vie.map((item) => { | ||
return { | ||
"type": "Feature", | ||
"properties": { | ||
"code": item.codice, | ||
"desc": item.descrizione | ||
} | ||
}; | ||
}); | ||
} | ||
return []; | ||
}); | ||
}, | ||
bzCivico: (searchText, {pathname, item}) => { | ||
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. remove this too |
||
let params = assign({}, {query: searchText, idVia: item.properties.code}); | ||
let url = urlUtil.format({ | ||
pathname, | ||
query: params | ||
}); | ||
return axios.post(url).then( (res) => { | ||
if (res && res.data && res.data.success) { | ||
return res.data.vie.map((nestedItem) => { | ||
return { | ||
"type": "Feature", | ||
"properties": { | ||
"code": nestedItem.codice, | ||
"desc": nestedItem.descrizione | ||
} | ||
}; | ||
}); | ||
} | ||
return []; | ||
}); | ||
} | ||
}; | ||
|
||
const Utils = { | ||
setService: (type, fun) => { | ||
Services[type] = fun; | ||
}, | ||
getService: (type) => { | ||
return !!Services[type] ? Services[type] : null; | ||
} | ||
}; | ||
|
||
module.exports = {API: {Services, Utils}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is a custom service. Please remove it from pull request