본문 바로가기
개발/ALGOLIA

알고리아 Managing Results(3-12)

by dev_caleb 2022. 3. 3.
728x90

Sort By Attribute

https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/how-to/sort-by-attribute/

 

Sort by attribute | Algolia

Learn how to set up a replica index to sort by attribute.

www.algolia.com

 

By design, Algolia provides one ranking formula per index: when you want to provide different rankings for the same data you need to use different indices for each ranking. These additional indices are called replicas.

설계상, Algolia는 인덱스당 하나의 순위 공식을 제공합니다. 동일한 데이터에 대해 다른 순위를 제공하려면 각 순위에 대해 다른 색인을 사용해야 합니다. 이러한 추가 인덱스를 복제본(replicas)이라고 합니다.

 

If you want to set up sort by attribute it is important that you understand replica indices.

 

속성별로 정렬을 설정하려면 복제본 색인을 이해하는 것이 중요합니다.

 

 

To sort by attribute, you will first need to create a replica index and then modify the ranking formula of the replica. This can be done through the Dashboard and the API.

속성별로 정렬하려면 먼저 복제본 색인을 작성한 후 복제본의 순위 수식을 수정해야 합니다. 이것은 Dashboard와 API를 통해 가능합니다.

This guide will help you set up the necessary back end for sorting by attribute, but you need to configure your front end (with widgets or custom logic) to make the option accessible to your users.

 

이 안내서는 속성별 정렬에 필요한 백엔드를 설정하는 데 도움이 되지만, 사용자가 이 옵션에 액세스할 수 있도록 하려면 프런트엔드를 위젯 또는 사용자 정의 로직으로 구성해야 합니다.

Attribute format

Attributes used for sorting must have boolean or numerical values. You cannot use a string attribute and dates must be represented as numbers.

정렬에 사용되는 속성에는 부울 또는 숫자 값이 있어야 합니다. 문자열 특성을 사용할 수 없으며 날짜는 숫자로 표현되어야 합니다.

Numerical values should be indexed as actual numbers, not strings.

숫자 값은 문자열이 아닌 실제 숫자로 인덱싱해야 합니다.

 

Using the API

Creating a replica

To create replicas, use the setSettings method on your primary index. You can add more than one replica at a time if you want to provide multiple alternative sorting strategies.

Algolia offers two flavors of replicas, standard and virtual replicas. You can choose either one depending on your needs.

The example below shows how to create the products_standard_price_desc standard replica.

 

복제본을 작성하려면 기본 색인에서 setSettings 방법을 사용하십시오. 여러 개의 대체 정렬 전략을 제공하려는 경우, 한 번에 둘 이상의 복제본을 추가할 수 있습니다.
알골리아는 표준 복제본과 가상 복제본의 두 가지 맛을 제공합니다. 당신은 필요에 따라 둘 중 하나를 선택할 수 있습니다.
아래 예는 products_standard_price_desc 표준 복제본을 만드는 방법을 보여줍니다.

 

index.setSettings({
  replicas: [
    'products_standard_price_desc'
  ]
}).then(() => {
  // done
});

The example below shows how to create the products_virtual_price_desc virtual replica.

 

아래 예에서는 products_virtual_price_desc 가상 복제본을 만드는 방법을 보여 줍니다.

 

index.setSettings({
  replicas: [
    'virtual(products_virtual_price_desc)'
  ]
}).then(() => {
  // done
});

Changing replica settings(복제본 설정 변경)

To change a replica’s settings:

  1. Initialize the replica.
  2. Use setSettings to change the replica’s setting.

In the example below, the products_standard_price_desc standard replica is sorted by price, descending.

복제본 설정을 변경하려면:
복제본을 초기화합니다.
setSettings를 사용하여 복제본의 설정을 변경합니다.
아래의 예에서 products_standard_price_desc 표준 복제본은 가격별로 내림차순으로 정렬됩니다.

 

 

const replicaIndex = client.initIndex('products_standard_price_desc');

replicaIndex.setSettings({
  ranking: [
    "desc(price)",
    "typo",
    "geo",
    "words",
    "filters",
    "proximity",
    "attribute",
    "exact",
    "custom"
  ]
}).then(() => {
  // done
});

In the example below, the products_virtual_price_desc virtual replica is sorted by price, descending. Remember, a virtual replica reuses its primary index’s ranking and settings. That’s why only the customRanking attributes which are the attributes used for sorting are specified here.

아래 예에서는 products_virtual_price_desc 가상 복제본이 가격별로 내림차순으로 정렬되어 있습니다. 가상 복제본은 기본 인덱스의 순위와 설정을 재사용합니다. 그것이 오직 정렬에 사용되는 속성인 customParting 특성만 여기에 지정되는 이유입니다.(기본 인덱스의 순위와 설정을 재사용하기 때문에..)

 

 

const replicaIndex = client.initIndex('products_virtual_price_desc');

replicaIndex.setSettings({
  customRanking: [
    "desc(price)"
  ]
}).then(() => {
  // done
});

 

 

Using the dashboard#

Creating a replica#

  1. Go to the Indices section of the dashboard and select your index.
  2. Click the Replicas tab.
  3. Click the Create Replica Index button. If you are on a Premium plan, choose between a standard or virtual replica depending on your needs.
  4. Repeat for each replica you want to add.
  5. Don’t forget to save your changes.

복제본 만들기#

1. 대시보드의 인덱스 섹션으로 이동하여 인덱스를 선택합니다.
2. [복제본] 탭을 누릅니다.
3. [복제본 색인 작성] 단추를 누릅니다. 프리미엄 요금제를 사용 중인 경우 필요에 따라 표준 복제본 또는 가상 복제본 중에서 선택하십시오.
4. 추가할 각 복제본에 대해 위 과정을 반복합니다.
5. 변경 사항을 저장하는 것을 잊지 마십시오.

 

 

Changing replica settings#

  1. Go to the Indices section of the dashboard and select your replica index.
  2. Click the Configuration tab.
  3. In the Ranking and Sorting section, use the + Add sort-by attribute button to add the attribute you want to sort by. Then select either Ascending or Descending to the right of the attribute name.
  4. Don’t forget to save your changes.

복제본 설정 변경#

1. 대시보드의 인덱스 섹션으로 이동하여 복제본 인덱스를 선택합니다.
2. 구성 탭을 클릭합니다.
3. 순위 및 정렬 섹션에서 + 정렬 기준 특성 추가 버튼을 사용하여 정렬 기준으로 사용할 특성을 추가합니다. 그런 다음 특성 이름 오른쪽에 있는 오름차순 또는 내림차순을 선택합니다.
4. 변경 사항을 저장하는 것을 잊지 마십시오.

 

 

When using replicas for sorting, you should set the typoTolerance parameter to min. This ensures the most relevant results show up and get sorted.

정렬에 복제본을 사용할 때 오타 매개변수를 min으로 설정해야 합니다. 이렇게 하면 가장 관련성이 높은 결과가 나타나고 정렬됩니다.

 

 

 

 

 

 

 

 

 

728x90

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

알고리아 Managing Results(3-14)  (0) 2022.03.04
알고리아 Managing Results(3-13)  (0) 2022.03.04
알고리아 Managing Results(3-11)  (0) 2022.03.03
알고리아 Managing Results(3-10)  (0) 2022.03.03
알고리아 Managing Results(3-9)  (0) 2022.03.03