Created
March 19, 2020 02:55
-
-
Save theduckylittle/c659413dc4fdcbcd793bd2148202332f to your computer and use it in GitHub Desktop.
"OR" search with GeoMoose 3.5
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
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