Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Is it possible to do autocomplete with more than one field

Vote:
 

Apologies if this is obvious

Is it possible to do autocomplete with more than one field

This example shows it with one field as a source which I've got working

http://find.episerver.com/Documentation/searching-with-javascript-autocomplete

I can see that the post data fields is an array but what about the wildcard and the output for the success filed. This is what we are doing currently for one field

    //.. episerver find search
        $(searchBoxSelector).autocomplete({
            source: function (request, response) {
                var wildcard = { "ProductName$$string.lowercase": "*" + request.term + "*" };
                var postData = {
                    "query": { "wildcard": wildcard },
                    "fields": ["ProductName$$string"],
                    "size": 5
                };
                $.ajax({
                    url: autocompleteUrl,
                    data: JSON.stringify(postData),
                    dataType: 'json',
                    type: 'POST',
                    success: function (data) {
                        response($.map(data.hits.hits, function (item) {
                            return {
                                label: item.fields.ProductName$$string,
                                value: item.fields.ProductName$$string
                            };
                        }));
                    }
                });
            }};

Thanks

#88646
Jul 22, 2014 14:34
Vote:
 

You can probably use a boolQuery for this:

{
    "query" : {
        "bool": {
            "should": [
               {"wildcard" : { "ProductName$$string.lowercase": "*" + request.term + "*" }},
               {"wildcard" : { "ProductCategory$$string.lowercase": "*" + request.term + "*" }}
            ] 
        }
    },
    "fields": [
       "ProductName$$string",
       "ProductCategory$$string"
    ]
}
#88648
Jul 22, 2014 15:27
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.