algoliasearch-helper-flutter icon indicating copy to clipboard operation
algoliasearch-helper-flutter copied to clipboard

filterOnly ?

Open Patrick386 opened this issue 2 years ago • 3 comments

Cloud functions

  • IndexName: company
  • filterOnly(status)
  • filterOnly(published)

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?

Patrick386 avatar Mar 11 '23 11:03 Patrick386

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.

VladislavFitz avatar May 26 '23 16:05 VladislavFitz

@VladislavFitz the filters param in not there in SearchState

Abhishek-Acme avatar May 30 '23 19:05 Abhishek-Acme

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.

Patrick386 avatar Jun 10 '23 08:06 Patrick386