본문 바로가기
개발/ALGOLIA

알고리아 Managing Results(3-31)

by dev_caleb 2022. 3. 5.
728x90

Filters and Facet Filters

https://www.algolia.com/doc/guides/managing-results/refine-results/filtering/in-depth/filters-and-facetfilters/

 

Filters and facet filters | Algolia

Learn about the relationship between filters and facetFilters.

www.algolia.com

 

As an alternative to the filters parameter, you can use other parameters that provide nearly the same functionality. They include facetFilters for strings and booleans, and numericFilters for numbers and dates.

Whether you use the filters parameter or the combination facetFilters and numericFiltersparameters, the functionality is mostly the same - to filter records based on certain attributes. However,there are some differences:

필터 매개 변수 대신 거의 동일한 기능을 제공하는 다른 매개 변수를 사용할 수 있습니다. 문자열 및 부울런에 대한 facetFilters와 숫자와 날짜에 대한 numericFilters가 포함됩니다.
필터 매개 변수를 사용하든, 또는 facetFilters와 numericFiltersparameters의 조합을 사용하든, 기능은 대부분 동일합니다. - 특정 속성을 기준으로 레코드를 필터링합니다. 그러나 몇 가지 차이점이 있다.

  • Their syntax is different
  • You cannot use facet filtering on numbers, so you’ll need to use a second parameter (numericFilters)

-그들의 문법은 다르다.
-숫자에는 면 필터링을 사용할 수 없으므로, 두 번째 매개 변수(숫자 필터)를 사용해야 합니다.

 

For most developers, the filters parameter will be easier to use because of its familiar SQL syntax as well as its ability to mix string and numeric filters within the same parameter.

One suggestion is to use facetFilters when handling frontend faceting. But this is not necessary - all facet filtering can be handled by filters.

대부분의 개발자에게, 필터 매개변수는 친숙한 SQL 구문과 동일한 매개변수 내에서 문자열과 숫자 필터를 혼합할 수 있기 때문에 사용하기 더 쉽다.
한 가지 방법은 프런트 엔드 패싱 처리 시 패싯필터를 사용하는 것입니다. 그러나 반드시 필요한 것은 아닙니다. 모든 면 필터링은 필터로 처리할 수 있습니다.

 

 

Syntax difference between filters and facetFilters(필터와 facetFilter의 구문 차이)

The first difference is that filters needs to be a string and facetFilters needs to be an array.

첫 번째 차이점은 필터는 문자열이어야 하고 facetFilters는 배열이어야 한다는 것입니다.

 

index.search('', {
  filters: 'author:"Stephen King"'
});
index.search('', {
  facetFilters: [
    "author:Stephen King"
  ]
});

Multiple filters#

The syntax for multiple filtering is also different.

For filtering, you use ANDs and ORs when combining more than one filter.

다중 필터링에 대한 구문도 다릅니다.
필터링의 경우 둘 이상의 필터를 결합할 때 AND 및 OR을 사용합니다.

 

index.search('', {
  filters: '("author:Stephen King" OR "genre:Horror") AND "publisher:Penguin"'
});

For facet filtering, all you need to do is list the attributes using brackets. Without brackets, the entire list is interpreted as combining filters with AND. Within brackets [,], the list is interpreted with ORs.

So the equivalent facet filtering for the above is as follows:

패싯 필터링의 경우 대괄호를 사용하여 속성을 나열하기만 하면 됩니다. 대괄호가 없으면 전체 목록은 AND와 필터를 결합한 것으로 해석됩니다. 대괄호 [,] 안에 있는 목록은 OR로 해석됩니다.
따라서 위의 동등한 면 필터링은 다음과 같습니다.

 

index.search('', {
  facetFilters: [["author:Stephen King", "genre:Horror"], "publisher:Penguin"]
});

Note that in the case of multiple filters, every value within the main bracket is interpreted as a conjunction (AND). If you want to use a disjunctive (OR), you will need to use a nested array (for example: ["author:Stephen King", "genre:Horror"]).

Additionally, Algolia allows you to negate facet filters using a minus sign (-), sometimes called a dash. In this example, ebooks would be excluded from the results.

여러 필터의 경우 주괄호 내의 모든 값은 결합(AND)으로 해석됩니다. 분리(OR)를 사용하려면 중첩 배열을 사용해야 합니다(예: ["작성자:스티븐 킹, "장르:공포"]).
또한 Algolia에서는 대시라고도 하는 마이너스 기호(-)를 사용하여 면 필터를 부정할 수 있습니다. 이 예에서 전자책은 결과에서 제외될 것이다.

 

index.search('', {
  facetFilters: "category:-Ebook"
});

 

 

 

Combining filters and facetFilters within the same search#

You can also combine filters and facetFilters. There is one rule: we combine them using AND - meaning, we take the set of filters from each parameter and link them with AND.

So, continuing with our above query, we get the same results with the following:

필터와 facetFilter를 결합할 수도 있습니다. 한 가지 규칙이 있습니다: AND를 사용하여 결합합니다. 즉, 각 매개 변수에서 필터 집합을 가져와 AND와 연결합니다.
따라서 위의 쿼리를 계속하면 다음과 같은 결과를 얻을 수 있습니다.

 

 index.search('', {
   filters: '("author:Stephen King" OR "genre:Horror")',
   facetFilters: ["publisher:Penguin"]
 });

Which is the equivalent of saying “Search all penguins books AND which are either written by stephen king OR in the genre horror”.

There are many reasons to do this. For example, you can create filters programmatically to create a reduced recordset based on a user’s profile, and then apply facetFilters to reflect the facets that the user has chosen.

이것은 "모든 펭귄 책을 찾아라 그리고 또한 스티븐 킹이 쓴 책들 또는 장르 공포물로 된 책들도 찾아라"이라는 말과 같습니다.
이렇게 하는 데는 많은 이유가 있습니다. 예를 들어, 프로그래밍 방식으로 필터를 생성하여 사용자 프로파일에 따라 축소된 레코드 세트를 만든 다음 facetFilters를 적용하여 사용자가 선택한 패싯을 반영할 수 있습니다.

 

Limits on the number of filters(필터 갯수 제한)

Filtering adds complexity to queries, and as such, the total number of filters (including filters, facetFilters, optionalFilters, etc.) is limited to 1000.

 

필터링은 쿼리에 복잡성을 더하므로 필터, facetFilter, 옵션 필터 등 총 필터 수가 1000개로 제한됩니다.

 

Using facets for attributes that are unique or uncommon may degrade search performance and relevance. See the facets usage notes for more information.

고유하거나 흔하지 않은 속성에 패싯을 사용하면 검색 성능과 관련성이 저하될 수 있습니다. 자세한 내용은 면 사용 정보를 참조하십시오.

 

728x90

'개발 > ALGOLIA' 카테고리의 다른 글

알고리아 Managing Results(3-33)  (0) 2022.04.20
알고리아 Managing Results(3-32)  (0) 2022.03.05
알고리아 Managing Results(3-30)  (0) 2022.03.05
알고리아 Managing Results(3-29)  (0) 2022.03.05
알고리아 Managing Results(3-28)  (0) 2022.03.05