I'm using a modified version of the CMV application and I'm trying to alter the query used by the suggestions query of a search widget. The suggestQueryParamters seems to allow for a custom where clause but I can't find any documentation on how to use it.
I want to alter the query from using wildcards on both sides of the search sting (the default) to only using it on the right side of the string i.e.
where field like '{value}%'
instead of
where field like '%{value}%'
In my code below you can see where I try to build a suggestQueryParams object into the sources property but it isn't having any effect. I'm guessing there is something wrong with the construction of the suggestQueryParams object but I can't find anything about constructing it correctly.
this.searchDijit.on("load", function () {
var sources = [
{
featureLayer: new FeatureLayer("http://MyTestServer.amazonaws.com/arcgis/rest/services/clinrt/Building_XY/MapServer/0", {
outFields: ["*"],
//infoTemplate: new InfoTemplate("Parcels", "Number: ${ADDRESS}</br>Street: ${NAME}</br>Full_Address: ${Full_Address}")
}),
outFields: ["Full_Address"],
displayField: "Full_Address",
suggestionTemplate: "${Full_Address}",
name: "Parcels",
placeholder: "example: 1 CIVIC CENTER PLZ",
enableSuggestions: true,
maxSuggestions: 50,
suggestQueryParams: {where: 'upper(Full_Address) Like \'[value]%\'' }
},
];
//Set the sources above to the search widget
this.set("sources", sources);
this.set("activeSourceIndex", 0);
});
Update So while I couldn't find a way to alter the query that the search widget uses I did find a why to do what I wanted. I found that I could listen for the results event and alter the suggestion list box to remove the items I didn't want. It's not the prettiest or the most efficient way but it works:
this.searchDijit.on( 'suggest-results', lang.hitch(
this, function (e) {
//console.log('suggest results', e);
var itemi = this.searchDijit.suggestionsNode.children[0].children[0];
if (!itemi.childNodes || itemi.childNodes.length == 0) return;
//Here is the logic to remove unwanted items from the list of returned suggestions
for (var i=0; li=itemi.childNodes[i]; i++) {
if(!isNaN(e.value) && li.innerText.indexOf(e.value) != 0){
itemi.removeChild(li);
i = i -1;
};
}
}
));