algolia / algoliasearch-helper-flutter

⚡️ Building block to create instant-search applications with Flutter
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/flutter/
Other
22 stars 15 forks source link

filterOnly ? #64

Open Patrick386 opened 1 year ago

Patrick386 commented 1 year ago

Cloud functions

attributesForFaceting: [ ‘filterOnly(status)’, ‘filterOnly(published)’, ],

client:

  HitsSearcher hitsSearcher = HitsSearcher.create(
      applicationID: AlgoliaCredentials.applicationID,
      apiKey: AlgoliaCredentials.apiKey,
      state:  const SearchState(
        indexName: 'company',
        facetFilters: ['published:true'],
        //query: '',
      ));

I want to create a page that has status ‘processing’ and published ‘true’. How do I do that?

VladislavFitz commented 1 year ago

Hi @Patrick386 , Sorry for late reaction. The recommended way to do it is to use the filters value of the SearchState. Your code should look as follows:

 HitsSearcher hitsSearcher = HitsSearcher.create(
      applicationID: AlgoliaCredentials.applicationID,
      apiKey: AlgoliaCredentials.apiKey,
      state:  const SearchState(
        indexName: 'company',
        filters: 'published:true AND status:processing',
        //query: '',
      ));

Otherwise you can use the FilterState component connected to your HitsSearcher instance, which simplified the filter management.

Abhishek-Acme commented 1 year ago

@VladislavFitz the filters param in not there in SearchState

Patrick386 commented 1 year ago

Hi @Patrick386 , Sorry for late reaction. The recommended way to do it is to use the filters value of the SearchState. Your code should look as follows:

 HitsSearcher hitsSearcher = HitsSearcher.create(
      applicationID: AlgoliaCredentials.applicationID,
      apiKey: AlgoliaCredentials.apiKey,
      state:  const SearchState(
        indexName: 'company',
        filters: 'published:true AND status:processing',
        //query: '',
      ));

Otherwise you can use the FilterState component connected to your HitsSearcher instance, which simplified the filter management.

Thank you for your answer. By the way, the following code is the one I am currently using.

  final FilterState filterState = FilterState()
    ..add(mainCategoryGroupID, [Filter.facet('mainCategory', category.main)])
    ..add(subCategoryGroupID, [])
    ..add(typeGroupID, [])
    ..add(tagGroupID, []);

  HitsSearcher hitsSearcher = HitsSearcher(
    applicationID: AlgoliaCredentials.applicationID,
    apiKey: AlgoliaCredentials.apiKey,
    indexName: AlgoliaCredentials.discoveryIndex,
  )..connectFilterState(filterState);

I will try applying the recommended code. Thank you for your helpful response.