Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save theduckylittle/c659413dc4fdcbcd793bd2148202332f to your computer and use it in GitHub Desktop.
Save theduckylittle/c659413dc4fdcbcd793bd2148202332f to your computer and use it in GitHub Desktop.
"OR" search with GeoMoose 3.5
app.registerService('search', SearchService, {
fields: [
{type: 'text', label: 'Owner Name', name: 'OWNER_NAME'},
{type: 'text', label: 'Street/Address', name: 'OWN_ADD_L1'},
{type: 'text', label: 'City/State/ZIP', name: 'OWN_ADD_L3'}
],
searchLayers: ['vector-parcels/parcels'],
validateFieldValues: function (fields) {
let nonEmpty = 0;
const validateFieldValuesResult = {
valid: true,
message: null
};
if (fields['OWNER_NAME'] !== undefined && fields['OWNER_NAME'] !== '') {
nonEmpty++;
}
if (fields['OWN_ADD_L1'] !== undefined && fields['OWN_ADD_L1'] !== '') {
nonEmpty++;
}
if (fields['OWN_ADD_L3'] !== undefined && fields['OWN_ADD_L3'] !== '') {
nonEmpty++;
}
if (nonEmpty === 0) {
validateFieldValuesResult.valid = false;
validateFieldValuesResult.message = 'Please complete at least one field.'
}
return validateFieldValuesResult;
},
prepareFields: function (fields) {
// reformat the fields for the query engine,
// "*stuff*" will do a case-ignored "contains" query.
var query = ['or'];
for(var i = 0, ii = fields.length; i < ii; i++) {
if(fields[i].value !== '' && fields[i].value !== undefined) {
query.push({
comparitor: 'ilike',
name: fields[i].name,
value: '%' + fields[i].value + '%'
});
}
}
return [query];
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment