본문 바로가기
개발/ALGOLIA

알고리아 Managing Results(3-36)

by dev_caleb 2022. 4. 27.
728x90

https://www.algolia.com/doc/guides/managing-results/refine-results/grouping/how-to/item-variations/

 

Item variations | Algolia

Discover Algolia's Distinct feature to deduplicate results that share a common attribute.

www.algolia.com

Item Variations

Anytime you have products that come in variations - for example, in different colors - knowing how to structure your data to best represent your inventory without duplicates can become tricky. Good examples are t-shirts of different colors or smartphones with different storage capacity (and consequently different prices).

Take the example of an ecommerce website selling t-shirts and sweatshirts in a variety of models and colors. The simplest solution would be to have one record per model and only have a list of possible color variants. The issue with this approach is that whenever someone searches for “red t-shirt”, the engine returns all the t-shirt models that have at least one variant in red. However, the thumbnail would not necessarily be red, which would be confusing.

Instead, you want to make sure that whenever someone types “red t-shirt”, the page only displays products with a red thumbnail. Also, you want to make sure to only get a single item per model, and find a clever way to display all variants.

 

예를 들어 다양한 색상으로 제공되는 제품이 있을 때마다 중복 없이 인벤토리를 가장 잘 나타내도록 데이터를 구성하는 방법을 아는 것은 까다로울 수 있습니다. 다른 색상의 티셔츠나 저장 용량이 다른 스마트폰(결과적으로 가격이 다른)이 좋은 예입니다.
다양한 모델과 색상의 티셔츠와 맨투맨을 판매하는 전자상거래 웹사이트의 예를 들어보자. 가장 간단한 해결책은 모델당 하나의 레코드를 가지고 가능한 색상 변형 목록만 갖는 것이다. 이 접근법의 문제는 누군가가 "빨간 티셔츠"를 검색할 때마다 엔진이 최소한 하나의 빨간색을 가진 모든 티셔츠 모델을 반환한다는 것이다. 그러나 섬네일이 반드시 빨간색이 되는 것은 아니므로 혼란스러울 것이다.
대신 다른 사용자가 "빨간색 티셔츠"를 입력할 때마다 페이지에 빨간색 섬네일이 있는 제품만 표시되도록 하려고 합니다. 또한 모델당 하나의 항목만 가져오고 모든 변형을 표시할 수 있는 방법을 찾으려고 합니다.

 

 

Dataset example#

In the inventory, you have two t-shirt models (A and B) and two models of sweatshirts (C and D). Each model comes in several colors.

데이터 집합 예제#
재고에는 두 개의 티셔츠 모형(A와 B)과 두 개의 맨투맨 모형(C와 D)이 있습니다. 각 모델은 여러 가지 색상이 있습니다.

 

In your dataset, you can represent them by creating one record for each color variant of each item. Each record specifies the type, the model, the color and the associated thumbnail. Here’s what your records look like:

 

데이터 세트에서 각 항목의 각 색상 변형에 대해 하나의 레코드를 생성하여 표시할 수 있습니다. 각 레코드는 유형, 모델, 색상 및 관련 축소판 그림을 지정합니다. 레코드는 다음과 같습니다.

 

[
  {
    "type": "t-shirt",
    "model": "B",
    "color": "blue",
    "thumbnail_url": "tshirt-B-blue.png"
  },
  {
    "type": "sweatshirt",
    "model": "C",
    "color": "red",
    "thumbnail_url": "sweatshirt-C-red.png"
  },
  ...
]

 

Going a step further, you could also add all the possible color variations for each record. This way, you could display all the variants for a single product in your front end (for example, color swatches under the thumbnail), allowing the end user to discover them.

 

 

한 단계 더 나아가 각 레코드에 대해 가능한 모든 색상 변형을 추가할 수도 있습니다. 이렇게 하면 단일 제품에 대한 모든 변형(예: 축소 이미지 아래의 컬러 스왓치)을 프런트 엔드에 표시하여 최종 사용자가 검색할 수 있습니다.

 

[
  {
    "type": "t-shirt",
    "model": "B",
    "color": "blue",
    "thumbnail_url": "tshirt-B-blue.png",
    "color_variants": ["orange", "teal", "yellow", "red", "green"]
  },
  {
    "type": "t-shirt",
    "model": "B",
    "color": "orange",
    "thumbnail_url": "tshirt-B-orange.png",
    "color_variants": ["blue", "teal", "yellow", "red", "green"]
  },
  ...
]

 

With this approach, every record represents a single variation, which ensures displaying always consistent data. Having one record per variation also lets you add granular custom ranking attributes, like number_of_sales. Besides, you can leverage Algolia’s distinct feature to de-duplicate models. This way, when someone searches for “t-shirt”, they only get one of each model.

 

 

이 방법을 사용하면 모든 레코드가 단일 변동을 나타내므로, 항상 일관된 데이터를 표시할 수 있습니다. 또한 변동당 하나의 레코드를 사용하면 number_of_sales와 같은 세분화된 사용자 지정 순위 속성을 추가할 수 있습니다. 또한 Algolia의 고유한 기능을 활용하여 모델을 복제할 수 있습니다. 이런 식으로, 누군가가 "티셔츠"를 검색할 때, 그들은 각 모델 중 하나만 얻습니다.

 

 

Using the API

At indexing time#

Before de-duplicating items, restrict what attributes are searchable. You don’t want to search into thumbnail_url, which may be irrelevant and add noise, nor into color_variants, because it could lead to false positives. Therefore, you can set model, type and color as searchableAttributes.

 

항목 복제를 취소하기 전에, 검색할 수 있는 특성을 제한하십시오. 관련이 없고 노이즈를 추가할 수 있는 썸네일_url이나 color_variants를 검색하면 잘못된 긍정으로 이어질 수 있으므로 검색하지 않는 것이 좋습니다. 따라서 모델, 유형 및 색상을 검색 가능한 특성으로 설정할 수 있습니다.

 

index.setSettings({
  searchableAttributes: [
    'model',
    'type',
    'color'
  ]
}).then(() => {
  // done
});

 

To use distinct you first need to set model as attributeForDistinct during indexing time. Only then can you set distinct to true to de-duplicate your results. Note that setting distinct at indexing time is optional. If you want to, you can set it at query time instead. 

 

구별을 사용하려면 먼저 인덱싱 시간 동안 모델을 ForDistinct 속성으로 설정해야 합니다. 그런 다음 결과를 중복 제거하도록 고유 항목을 true로 설정할 수 있습니다. 인덱싱 시간에 고유하게 설정하는 것은 선택 사항입니다. 원하는 경우 대신 쿼리 시간에 설정할 수 있습니다.

 

 

index.setSettings({
  attributeForDistinct: 'model',
  distinct: true
}).then(() => {
  // done
});

 

At query time#

Once attributeForDistinct is set, you can enable distinct by setting it to true. Note that you can set distinct to true or 1 interchangeably.

 

ForDistinct 특성을 미리 설정하면,  distinctrue로 설정하여 활성화할 수 있습니다. distinct을 true 또는 1로 상호 교환하여 설정할 수 있습니다.

 

index.search('query', {
  distinct: true
}).then(({ hits }) => {
  console.log(hits);
});

 

 

Using the dashboard#

You can also set your attribute for distinct and enable distinct in your Algolia dashboard.

  1. Go to your dashboard, then go to the Search product and select your index.
  2. Click on the Configuration tab.
  3. In the Searchable Attributes section, click the “Add a searchable attribute” button.
  4. Select the model, type and color attributes in the dropdown one after another.
  5. Click the Deduplication and Grouping tab, which you can find under Search behavior.
  6. Set the Distinct dropdown to true.
  7. Set the Attribute for Distinct dropdown to model.
  8. Don’t forget to save your changes.

When distinct is set to true, you get one color for each model. To control which one, you can set a new attribute with business metrics, for example, number_of_sales, and set it up for custom ranking.

구별이 참으로 설정되면 각 모형에 대해 하나의 색상이 지정됩니다. 어떤 속성을 제어하려면 비즈니스 메트릭(예: number_of_sales)을 사용하여 새 속성을 설정하고 사용자 지정 순위에 맞게 설정할 수 있습니다.

Additionally, you can display all available colors for each item thanks to the color_variantsattribute. This way, the end user can access all possible variants from the search results without the page being crowded with too many items.

또한 color_variants 특성 덕분에 각 항목에 사용 가능한 모든 색상을 표시할 수 있습니다. 이렇게 하면 최종 사용자는 페이지가 너무 많은 항목으로 붐비지 않고 검색 결과에서 가능한 모든 변형에 액세스할 수 있습니다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90

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

알고리아 Managing Results(3-38)  (0) 2022.04.28
알고리아 Managing Results(3-37)  (0) 2022.04.27
알고리아 Managing Results(3-35)  (0) 2022.04.27
알고리아 Managing Results(3-33)  (0) 2022.04.20
알고리아 Managing Results(3-32)  (0) 2022.03.05