Filter Map in Map

Hello! I want to filter the map by the map.
if

{
    objectID: "boy_001"
    myCharacterList: [1,2,3,4]
},
{
    objectID: "boy_002"
    myCharacterList: [1,4]
},
{
    objectID: "boy_003"
    myCharacterList: [3,4]
},
{
    objectID: "boy_004"
    myCharacterList: [3,5]
},

and my filter’s list is [2,5]

So, my hope result is

boy_001
boy_004

now to write a query?

myCharacterList:[2,5]
myCharacterList in [2,5]

Hi!

I understand that you’re trying to retrieve items that have the value ‘2’ or ‘5’ in ‘myCharacterList’. In such case, you can use ‘facetFilters’ for that kind of disjunctive filtering.

Please note that the attribute has to be configured as ‘attributesForFacetting’ before used in ‘facetFilters’ parameter. Please read this document for further detail in filtering.

1 Like

Thank you for replying.
Do you mean like this?
I think redundant…

'facetFilters' => [
  ['myCharacterList:2', 'myCharacterList:5']
]

Can I use facetFilters for more than one fields?
I added hobbies field like this.

{
    objectID: "boy_001"
    myCharacterList: [1,2,3,4],
    hobbies: [1,2,3,4]
},
{
    objectID: "boy_002"
    myCharacterList: [1,4],
    hobbies: [1]
},
{
    objectID: "boy_003"
    myCharacterList: [3,4],
    hobbies: [2]
},
{
    objectID: "boy_004"
    myCharacterList: [3,5],
    hobbies: [4]
},

P.S. I use algolia-0.1.7 module for Flutter/Dart (unofficial, I hope official edition…)

['myCharacterList:25']

not work…

Dashboard

Document


It never return.
it is Algoloia bug?
The official document is not good

Hello @shinriyo,

  • Do you mean like this? I think redundant…

    'facetFilters' => [
      ['myCharacterList:2', 'myCharacterList:5']
    ]
    

    You are right, this is the way to use facetFilters. You can as well write more complex expressions, including using it for more than one field:

    // (attribute1:value OR attribute2:value) AND attribute3:value (combined strings and arrays)
    'facetFilters' => [
       ['attribute1:value', 'attribute2:value'], 'attribute3:value',
    ]
    
  • ['myCharacterList:25'] not work…
    This is because the syntax you use is for the PHP code, not for the dashboard. In your dashboard’s Facet filters UI, you should put them one by one:


    In this example, we are adding two filters: myCharacterList == 25 AND myCharacterList == 2, displaying only results which have both values in their list.

Thank you for replying.

But, I put myCharacterList:25.
However, No results.

myCharacterList == 25 AND myCharacterList == 2

If I put two values, is it AND statement? I guess, it never get result.

I guess. I should NumericFilter for number array?
And I can USE OR like this?

If you get no results for myCharacterList:25 as a facet filter, it might mean that the attributesForFaceting is not set? As my colleague Tatsuro mentioned:

Please note that the attribute has to be configured as ‘attributesForFacetting’ before used in ‘facetFilters’ parameter. Please read this document for further detail in filtering.

Well for filtering, there are two options:

  • Using filters for all kind of filters, which is our recommended way today: see filters documentation and examples, including OR queries. It’s easier because you can use syntax like filters = 'available = 1 AND (myCharacterList:25 OR myCharacterList:2)' with filters but not with numericFilters, facetFilters, etc

  • Using numericFilters for numbers, facetFilters for facets, etc. Then look at numericFilters docs and example for OR queries (separating filters by comma makes an AND, putting them in an array makes an OR.

Thank you for replying.
attributesForFaceting is not set. I misread.
Where can I find in “Advanced Search”?
I want to set before run API.

It’s easier because you can use syntax like filters = 'available = 1 AND (myCharacterList:25 OR myCharacterList:2)' with

OK. It is better. SQL-like syntax is better.
attributesForFaceting is troublesome.

You’re welcome, glad to hear we found what was causing problems!

There might be a confusion: Advanced Search is the interface to do a search with your current settings defined at build-time, using the parameters you put at search-time.

attributesForFaceting is an index setting that you have to configure if you want it to affect your search experience. Whenever you change a setting like this one, we automatically rebuild your index, and then search parameters like facetFilters will work.

If you want to change settings, you do it in the Configure panel of your dashboard:

you do it in the Configure panel of your dashboard:

I guess you mean Configuration panel.
I added like this.

Later I set myCharacterList:25.
Settings also not worked.

You’re right I meant Configuration panel.

You have been setting the wrong setting: your screenshot shows you defining Searchable attributes (searchableAttributes), not attributesForFaceting (which as you can see in my GIF above is in the Filtering) category below.

which as you can see in my GIF above is in the Filtering

Yes. I know. but gif animation is too fast to catch on.
But, I found it.

it appeared. it is useful.

By the way, Should I use attributesForFaceting? it is faster than filter?
I guess attributesForFaceting makes index.

1 Like

Hi @shinriyo, in order to use filters or facetFilters, which are query time parameters, you must first declare the attributes you want to filter on in attributesForFaceting which is an index setting. Index settings change the index during indexing time; they impact all searches. They have the settings scope).

Parameters like filters and facetFilters are in the search scope and are applied to certain queries.

To learn more about the different scopes please see https://www.algolia.com/doc/api-reference/api-parameters/#scope.

I hope this helps!

1 Like