Autocomplete.js exclude results

instantsearch
autocomplete
#1

I am building an autocomplete search box that searches through multiple indices. For one of them, I need to only return results from a certain type. I’m unable to make this work currently. Any suggestions on the right approach in adding a facetfilter to one of the queries?

autocomplete('#aa-search-input', {}, [
        {
          source: autocomplete.sources.hits(organizations, { hitsPerPage: 3 }),
          displayKey: 'name',
          templates: {
            header: '<div class="aa-suggestions-category">Organizations</div>',
            suggestion({_highlightResult}) {
              return `<a href="{{hit.name}}"><span>${_highlightResult.name.value}</span></a>`;
            }
          }
        },
        {
          source: autocomplete.sources.hits(documents, { hitsPerPage: 3 }),
          displayKey: 'name',
          templates: {
            header: '<div class="aa-suggestions-category">Documents</div>',
            suggestion({_highlightResult}) {
              return `<span>${_highlightResult.name.value}</span>`;
            }
          }
        },
        {
          source: autocomplete.sources.hits(lawyers, { hitsPerPage: 3, facetFilters: ['type:profile'] }),
          displayKey: 'full_name',
          templates: {
            header: '<div class="aa-suggestions-category">lawyers</div>',
            suggestion({_highlightResult}) {
               return `<span>{{hit.full_name}}</span>`;
            }
          }
        }
    ]);
#2

Hi @dev12,

Thanks for contacting Algolia.

As a shot in the dark, if you are trying to exclude profile:type the proper syntax would be:

NOT type:profile

See boolean filter syntax

However, if still having issues, could you give us a live example that we could take a look at? We have a sandbox that has most of the autocomplete boilerplate ready and you can update it for your specific use case:

Tip: If you are concerned about sharing your Search API Key, know that it is already publicly available on the frontend of any website. However, you can also generate a new Search API Key for purposes of this sandbox and then discard it after, if you’d like.

In addition, could you also please confirm that the attribute named profile is set as an attributesForFaceting so that you can filter on it and confirm which attribute and value you would like to exclude?

Best regards,