본문 바로가기
개발/ALGOLIA

알고리아 Managing Results(3-29)

by dev_caleb 2022. 3. 5.
728x90

 

Filter By Tags

https://www.algolia.com/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-tags/

 

Filter by tags | Algolia

How to filter by tags.

www.algolia.com

 

Sometimes, you may want to filter search results based on a specific metadata, like a type or a category. Imagine you have an online bookstore with sections; non-fiction, history, children’s literature, politics, etc. but you have a single index for all your books. Depending on where the user is making searches from, you may want to provide a different search experience.

유형이나 카테고리와 같은 특정 메타데이터를 기준으로 검색 결과를 필터링하려는 경우가 있습니다. 당신이 논픽션, 역사, 아동문학, 정치 등의 섹션이 있는 온라인 서점을 가지고 있지만 당신의 모든 책에 대한 하나의 index을 가지고 있다고 상상해 보세요. 사용자가 검색을 수행하는 위치에 따라 다른 검색 환경을 제공할 수 있습니다.

 

For example, let’s say a user goes to the politics category on your website, then starts searching for the biography of President Harry S. Truman. If your search relevance is primarily based on book popularity, by typing “harry”, they would most likely retrieve Harry Potter books first, which wouldn’t make sense to them.

Instead, what you can do is filter the results they get based on what they most likely want to see. Algolia lets you do this by allowing you to set filters based on one or several tags.

예를 들어, 한 사용자가 당신의 웹사이트의 정치 카테고리로 가서 해리 S 트루먼 대통령의 전기를 검색하기 시작한다고 가정해보자.  만약 당신의 검색 관련성이 주로 책의 인기에 기반을 둔다면, "해리"를 치면, 그들은 아마도 해리 포터 책을 가장 먼저 회수할 것이고, 이것은 그들에게 이치에 맞지 않을 것이다.
대신, 그들이 가장 보고 싶어 하는 것을 기준으로 결과를 필터링할 수 있습니다. Algolia를 사용하면 하나 이상의 태그를 기반으로 필터를 설정할 수 있습니다.

Dataset Example

Algolia lets you add tags to each of your records thanks to the special attribute _tags. This reserved Algolia attribute automatically works as a filter without you having to set it as an attribute for faceting.

Therefore, we can leverage this attribute and tag books by categories or genre.

 

Algolia를 사용하면 _tags라는 특수 특성 덕분에 각 레코드에 태그를 추가할 수 있습니다. 이 예약된 Algolia 특성은 패싱을 위한 속성으로 설정할 필요 없이 자동으로 필터로 작동합니다.
따라서 우리는 이 속성을 활용하여 카테고리 또는 장르별로 책에 태그를 지정할 수 있습니다.

 

 

[
  {
    "title": "Harry Potter and the Philosopher's Stone",
    "author": "J. K. Rowling",
    "popularity": 1000,
    "_tags": [
      "fantasy",
      "science fiction",
      "children's literature"
    ]
  },
  {
    "title": "Harry Potter and the Goblet of Fire",
    "author": "J. K. Rowling",
    "popularity": 3000,
    "_tags": [
      "fantasy",
      "science fiction",
      "children's literature"
    ]
  },
  {
    "title": "Harry Potter and the Chamber of Secrets",
    "author": "J. K. Rowling",
    "popularity": 2000,
    "_tags": [
      "fantasy",
      "science fiction",
      "children's literature"
    ]
  },
  {
    "title": "The Accidental President: Harry S. Truman and the Four Months That Changed the World",
    "author": "A. J. Baime",
    "popularity": 900,
    "_tags": [
      "biography",
      "history",
      "politics"
    ]
  },
  {
    "title": "Where the Buck Stops: The Personal and Private Writings of Harry S. Truman",
    "author": "Harry S. Truman",
    "popularity": 300,
    "_tags": [
      "history",
      "politics"
    ]
  },
  ...
]

 

We now have the necessary data to leverage Algolia’s filtering capabilities. For instance, if we typed “harry” and restricted our search to “politics”, we could retrieve “The Accidental President” and “Where the Buck Stops”, because they both have “politics” in their _tags attribute, and both have to do with Harry Truman.

우리는 이제 알골리아의 필터링 기능을 활용하는 데 필요한 데이터를 가지고 있다. 예를 들어, 우리가 "harry"를 입력하고 "politics"로 검색을 제한한다면, 우리는 "The Incidental President"와 "Where the Buck Stops"를 검색할 수 있을 것이다. 왜냐하면 둘 다 태그 속성에 "politics"가 있고 둘 다 해리 트루먼과 관련이 있기 때문이다.

 

_tags is a reserved word and so it is not searchable by default.

 

_tags는 예약된 단어이므로 기본적으로 검색할 수 없습니다.

 

 

Using the API

index.search('harry', {
  filters: 'politics' // Same as '_tags:politics'
}).then(({ hits }) => {
  console.log(hits);
});

If you don’t specify any attribute name, the filter applies to _tags. For example, politics translates into _tags:politics.

Note that you can also use tagFilters to do the same thing.

특성 이름을 지정하지 않으면 _tags에 필터가 적용됩니다. 예를 들어, 정치는 _tags:politics로 번역됩니다.
tagFilters를 사용하여 동일한 작업을 수행할 수도 있습니다.

 

Using the Dashboard

Regarding filters, you can’t set them directly in the dashboard since you can only filter at query time. Yet, you can test for specific filters in the dashboard before using them in your search code.

필터의 경우 쿼리 시에만 필터링할 수 있으므로 대시보드에서 직접 설정할 수 없습니다. 그러나 검색 코드에 사용하기 전에 대시보드에서 특정 필터를 테스트할 수 있습니다.

  • Select the Search product icon on your dashboard and then select your index.
  • Click the Add Query Param button.
  • Go to the Filters tab.
  • Type “politics” in the Tag filters input (this leverages the tagFilters feature).
  • Click Apply.

-대시보드에서 제품 검색 아이콘을 선택한 다음 인덱스를 선택합니다.
-Add Query Parameter 버튼을 클릭합니다.
-필터 탭으로 이동합니다.
-태그 필터 입력에 "politics"를 입력합니다(태그 필터 기능 활용).
-적용을 클릭합니다.

 

You can also test for regular filters (with the filters feature). Go to the Custom tab and add your filter as JSON:

필터 기능을 사용하여 일반 필터를 테스트할 수도 있습니다. 사용자 지정 탭으로 이동하여 필터를 JSON으로 추가합니다.

 

The Difference Between _tags and a Custom Array

Using _tags

The _tags reserved attribute is dedicated to filtering. For that reason, you don’t have to set it as an attribute for faceting and use the filterOnly modifier like you would with a custom attribute. The _tags attribute comes ready and optimized for filtering. If you only have a single group of tags, using _tags is the recommend approach.

Note that, because _tags isn’t defined as a facet, you don’t get a count of records that match the filters.

_tags 예약 특성은 필터링 전용입니다. 따라서 사용자 지정 특성처럼 filterOnly 한정자를 사용하고 faceting을 위한 특성으로 설정할 필요가 없습니다. _tags 특성은 필터링을 위해 준비되고 최적화됩니다. 태그 그룹이 하나만 있는 경우에는 _tags를 사용하는 것이 좋습니다.
_tags는 패싯으로 정의되지 않기 때문에 필터와 일치하는 레코드 수를 얻을 수 없습니다.

 

Using custom attributes(사용자 지정 특성 사용)

On the other hand, you could have use cases where it would make sense to keep tags separate in different attributes. For example, you may want to refine results further and also filter by chapter. It wouldn’t make sense to mix everything up in _tags, so in the case of several types of filters, creating a custom attribute is the way to go.


반면에 태그를 서로 다른 특성으로 분리하여 유지하는 것이 적합한 경우를 사용할 수 있습니다. 예를 들어 결과를 세분화하고 장별로 필터링할 수 있습니다. _태그에 모든 것을 섞는 것은 타당하지 않으므로 여러 유형의 필터의 경우 사용자 지정 특성을 만드는 것이 좋습니다.

 

728x90

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

알고리아 Managing Results(3-31)  (0) 2022.03.05
알고리아 Managing Results(3-30)  (0) 2022.03.05
알고리아 Managing Results(3-28)  (0) 2022.03.05
알고리아 Managing Results(3-27)  (0) 2022.03.05
알고리아 Managing Results(3-26)  (0) 2022.03.05