일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 제로샷
- 파라미터 힌트
- 퓨샷
- Redshift
- 인자 힌트
- 인컨텍스트 러닝
- 동화책
- 반복문
- 아기동화
- Docker
- 프롬프트 튜닝
- 검색
- GPT
- Cognitive Search
- 도커
- Cognitive Service
- Compute
- UDF
- FOR
- Python
- 토끼
- dask
- Ai
- 대스크
- 모험
- Azure
- 파이썬
- 조건문
- 컨텍스트 매니져
- AI 동화
- Today
- Total
호랭이 분석가
[Azure] Cognitive Search로 검색 및 필터 설정 (Python) 본문
[Azure] Cognitive Search Index 생성, 삭제, 업로드
Python을 이용하여 Azure Cognitive Search의 Indexes를 생성할 때, 사용할 수 있는 Class는 무엇이 있는지 알아보겠습니다. Azure Cognitive Search client library for Python Table of contents Azure Cognitive Search client library for
dataiger.tistory.com
Azure Cognitive Search로 Index를 생성하고 데이터를 준비하였다면
검색을 위한 기본 준비는 끝났습니다.
# 샘플 인덱스명 / 필드 상세
index_name = 'test'
fields = [
SimpleField(name="testId", type=SearchFieldDataType.String, key=True),
SearchableField(name="testRate", type=SearchFieldDataType.Double,
filterable=True),
SearchableField(name="description", type=SearchFieldDataType.String),
SearchableField(name="testTag", type=SearchFieldDataType.String,
filterable=True, collection=True)
]
# 데이터 예제
{
"testId": "4",
"testRate": 4.5,
"description" : "가중치 +0 테스트"
"testTag": [
"성공",
"가중치",
"검색"
]
},
{
"testId": "6",
"testRate": 3.5,
"description" : "가중치 +1 테스트"
"testTag": [
"실패",
"종료"
]
}
참고로 fields에 collentions=True의 Parameter를 설정하셨다면 리스트 형태로 데이터를 저장할 수 있습니다.
위 코드 블록의 필드를 가진 인덱스에 데이터가 예제처럼 준비된 상태라고 가정하고
검색어는 "가중치"로 "testTag"에 "성공"이란 데이터를 필터링하여 검색해 가져오는 코드를 확인해 보겠습니다.
from azure.core.credentials import AzureKeyCredential
from azure.search.documents import SearchClient
# Azure 정보
search_service_name = 'your-service-name'
key = 'your-api-key'
endpoint = f'https://{serach_service_name}.search.windows.net/'
# 검색 클라이언트 생성
search_client = SearchClient(endpoint, index_name, AzureKeyCredential(key))
# 검색어와 필터
search_text = "가중치"
filter = "testTag/any(t: t eq '성공')"
# 검색 요청
search_result = search_client.search(search_text=search_text,
filter=filter
)
Azure 정보를 입력한 후 검색 클라이언트를 생성합니다.
그리고 검색할 단어와 필터를 만드는데 필터는 OData 문법을 따릅니다.
예제는 Azure Cognitive Search Documents를 참조하시면 됩니다.
OData filter reference - Azure Cognitive Search
OData language reference and full syntax used for creating filter expressions in Azure Cognitive Search queries.
learn.microsoft.com
'Azure > Cognitive Search' 카테고리의 다른 글
[Azure] Cognitive Search Vector Search 벡터 유사도 검색(Python) (0) | 2023.07.11 |
---|---|
[Azure] Cognitive Search 검색 스코어링 프로파일 설정 (Python) (0) | 2023.07.09 |
[Azure] Cognitive Search로 자동 완성 검색 구현하기 Suggest API(Python) (0) | 2023.07.07 |
[Azure] Cognitive Search Index 생성, 삭제, 업로드 (Python) (0) | 2023.07.04 |
[Azure] Cognitive Search Index Field 종류 (Python) (0) | 2023.07.04 |