Azure Cognitive Search Visual Studio Code 확장(사용 중지됨)

이전에 미리 보기로 제공되었던 Azure Cognitive Search 대한 Visual Studio Code 확장은 일반 공급으로 전환되지 않았으며 2022년 11월 1일부터 사용이 중지되었습니다.

Azure Marketplace 더 이상 확장을 사용할 수 없지만 코드는 에서 https://github.com/microsoft/vscode-azurecognitivesearch오픈 소스로 제공됩니다. 고유한 용도로 도구를 복제하고 수정할 수 있습니다.

확장을 사용하는 경우 이 문서에서는 Azure Cognitive Search REST API를 사용하여 대화형으로 REST API 요청을 작성하는 방법을 설명합니다.

필수 구성 요소

확장을 사용하려면 다음 서비스 및 도구가 필요합니다.

확장 설치

Github의 추가 정보 를 참조하세요.

구독에 연결

Visual Studio COde를 시작합니다.

Azure에 로그인... 을 선택하고, Azure 계정에 로그인합니다.

구독이 표시됩니다. 다음 스크린샷에서 구독 이름은 "Visual Studio Enterprise"이며 "azsearch-service"라는 하나의 검색 서비스를 포함합니다.

VS Code의 VS Code Azure 구독

표시되는 구독을 제한하려면 명령 팔레트(Ctrl+Shift+P 또는 Cmd+Shift+P)를 열고, Azure 또는 구독 선택을 검색합니다. Azure 계정에 로그인하거나 로그아웃하는 데 사용할 수 있는 명령도 있습니다.

검색 서비스를 확장하면 인덱스, 데이터 원본, 인덱서, 기술 세트, 동의어 맵 및 별칭 등 각 Cognitive Search 항목에 대한 트리 항목이 표시됩니다.

VS Code Azure 검색 트리

이러한 트리 항목을 확장하여 검색 서비스에 있는 모든 리소스를 표시할 수 있습니다.

1 - 인덱스 만들기

인덱스 만들기 REST API를 사용합니다.

VS Code 확장을 사용하면 요청 본문만 고려하면 됩니다. 이 빠른 시작에서는 인덱스 정의 샘플 및 해당 문서를 제공합니다.

인덱스 정의

아래의 인덱스 정의는 가상 호텔에 대한 스키마 샘플입니다.

fields 컬렉션은 검색 인덱스의 문서 구조를 정의합니다. 각 필드에는 데이터 형식과 필드를 사용하는 방법을 결정하는 다양한 추가 특성이 있습니다.

{
    "name": "hotels-quickstart",
    "fields": [
        {
            "name": "HotelId",
            "type": "Edm.String",
            "key": true,
            "filterable": true
        },
        {
            "name": "HotelName",
            "type": "Edm.String",
            "searchable": true,
            "filterable": false,
            "sortable": true,
            "facetable": false
        },
        {
            "name": "Description",
            "type": "Edm.String",
            "searchable": true,
            "filterable": false,
            "sortable": false,
            "facetable": false,
            "analyzer": "en.lucene"
        },
        {
            "name": "Description_fr",
            "type": "Edm.String",
            "searchable": true,
            "filterable": false,
            "sortable": false,
            "facetable": false,
            "analyzer": "fr.lucene"
        },
        {
            "name": "Category",
            "type": "Edm.String",
            "searchable": true,
            "filterable": true,
            "sortable": true,
            "facetable": true
        },
        {
            "name": "Tags",
            "type": "Collection(Edm.String)",
            "searchable": true,
            "filterable": true,
            "sortable": false,
            "facetable": true
        },
        {
            "name": "ParkingIncluded",
            "type": "Edm.Boolean",
            "filterable": true,
            "sortable": true,
            "facetable": true
        },
        {
            "name": "LastRenovationDate",
            "type": "Edm.DateTimeOffset",
            "filterable": true,
            "sortable": true,
            "facetable": true
        },
        {
            "name": "Rating",
            "type": "Edm.Double",
            "filterable": true,
            "sortable": true,
            "facetable": true
        },
        {
            "name": "Address",
            "type": "Edm.ComplexType",
            "fields": [
                {
                    "name": "StreetAddress",
                    "type": "Edm.String",
                    "filterable": false,
                    "sortable": false,
                    "facetable": false,
                    "searchable": true
                },
                {
                    "name": "City",
                    "type": "Edm.String",
                    "searchable": true,
                    "filterable": true,
                    "sortable": true,
                    "facetable": true
                },
                {
                    "name": "StateProvince",
                    "type": "Edm.String",
                    "searchable": true,
                    "filterable": true,
                    "sortable": true,
                    "facetable": true
                },
                {
                    "name": "PostalCode",
                    "type": "Edm.String",
                    "searchable": true,
                    "filterable": true,
                    "sortable": true,
                    "facetable": true
                },
                {
                    "name": "Country",
                    "type": "Edm.String",
                    "searchable": true,
                    "filterable": true,
                    "sortable": true,
                    "facetable": true
                }
            ]
        }
    ],
    "suggesters": [
        {
            "name": "sg",
            "searchMode": "analyzingInfixMatching",
            "sourceFields": [
                "HotelName"
            ]
        }
    ]
}

새 인덱스를 만들려면 마우스 오른쪽 단추로 인덱스를 클릭한 다음, 새 인덱스 만들기를 선택합니다. indexes-new-28c972f661.azsindex와 비슷한 이름의 편집기가 팝업됩니다.

위의 인덱스 정의를 창에 붙여넣습니다. 파일을 저장하고 인덱스를 업데이트할 것인지 묻는 메시지가 표시되면 업로드를 선택합니다. 이 단계에서는 인덱스가 만들어지고 왼쪽의 트리 뷰에 추가됩니다.

인덱스 만들기의 Gif

인덱스 정의에 문제가 있는 경우 아래와 유사한 오류 메시지가 표시됩니다.

인덱스 만들기 오류 메시지

오류가 발생하면 문제를 해결하고 파일을 다시 저장합니다.

2 - 문서 로드

REST API에서 인덱스 만들기 및 인덱스 채우기는 별도의 단계입니다. Azure Cognitive Search에서 인덱스에는 검색 가능한 모든 데이터가 포함됩니다. 이 빠른 시작에서는 데이터가 JSON 문서로 제공됩니다. 이 작업에는 문서 추가, 업데이트 또는 삭제 REST API가 사용됩니다.

인덱스로 새 문서를 추가하려면 다음을 수행합니다.

  1. 만든 hotels-quickstart 인덱스를 펼칩니다. 마우스 오른쪽 단추로 문서를 클릭하고, 새 문서 만들기를 선택합니다.

    문서 만들기

  2. 인덱스의 스키마를 유추한 JSON 편집기가 표시됩니다.

    json 문서 만들기

  3. 아래 JSON을 붙여넣은 다음, 파일을 저장합니다. 변경 내용을 확인하라는 메시지가 표시됩니다. 업로드를 선택하여 변경 내용을 저장합니다.

    {
        "HotelId": "1",
        "HotelName": "Secret Point Motel",
        "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Time's Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",
        "Category": "Boutique",
        "Tags": [ "pool", "air conditioning", "concierge" ],
        "ParkingIncluded": false,
        "LastRenovationDate": "1970-01-18T00:00:00Z",
        "Rating": 3.60,
        "Address": {
            "StreetAddress": "677 5th Ave",
            "City": "New York",
            "StateProvince": "NY",
            "PostalCode": "10022",
            "Country": "USA"
        } 
    }
    
  4. 나머지 세 문서에 대해 이 프로세스를 반복합니다.

    문서 2:

    {
        "HotelId": "2",
        "HotelName": "Twin Dome Motel",
        "Description": "The hotel is situated in a  nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts.",
        "Category": "Boutique",
        "Tags": [ "pool", "free wifi", "concierge" ],
        "ParkingIncluded": false,
        "LastRenovationDate": "1979-02-18T00:00:00Z",
        "Rating": 3.60,
        "Address": {
            "StreetAddress": "140 University Town Center Dr",
            "City": "Sarasota",
            "StateProvince": "FL",
            "PostalCode": "34243",
            "Country": "USA"
        } 
    }
    

    문서 3:

    {
        "HotelId": "3",
        "HotelName": "Triple Landscape Hotel",
        "Description": "The Hotel stands out for its gastronomic excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services.",
        "Category": "Resort and Spa",
        "Tags": [ "air conditioning", "bar", "continental breakfast" ],
        "ParkingIncluded": true,
        "LastRenovationDate": "2015-09-20T00:00:00Z",
        "Rating": 4.80,
        "Address": {
            "StreetAddress": "3393 Peachtree Rd",
            "City": "Atlanta",
            "StateProvince": "GA",
            "PostalCode": "30326",
            "Country": "USA"
        } 
    }
    

    문서 4:

    {
        "HotelId": "4",
        "HotelName": "Sublime Cliff Hotel",
        "Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace.",
        "Category": "Boutique",
        "Tags": [ "concierge", "view", "24-hour front desk service" ],
        "ParkingIncluded": true,
        "LastRenovationDate": "1960-02-06T00:00:00Z",
        "Rating": 4.60,
        "Address": {
            "StreetAddress": "7400 San Pedro Ave",
            "City": "San Antonio",
            "StateProvince": "TX",
            "PostalCode": "78216",
            "Country": "USA"
        }
    }
    

이 시점에서 문서 섹션에서 사용할 수 있는 4개의 문서가 모두 표시됩니다.

모든 문서가 업로드된 후의 상태

3 - 인덱스 검색

이제 인덱스에 콘텐츠가 포함되어 있으므로 문서 검색 REST API를 사용하여 쿼리를 실행할 수 있습니다.

  1. 검색할 인덱스 를 마우스 오른쪽 단추로 클릭하고 검색을 선택합니다. 이 단계에서는 와 비슷한 이름의 편집기를 sandbox-b946dcda48.azs엽니다.

    확장의 검색 보기

  2. 단순 쿼리가 자동으로 채워집니다. Ctrl+Alt+R 또는 Cmd+Alt+R을 눌러 쿼리를 제출합니다. 왼쪽 창에 결과 팝업이 표시됩니다.

    확장의 검색 결과

쿼리 예

구문을 이해하기 위해 몇 가지 다른 쿼리 예제를 시도해봅니다. 아래에는 시도해 볼 수 있는 네 가지 추가 쿼리가 있습니다. 여러 쿼리를 동일한 편집기에 추가할 수 있습니다. Ctrl+Alt+R 또는 Cmd+Alt+R을 누르면 커서에서 제출할 쿼리가 결정됩니다.

나란히 정렬된 쿼리 및 결과

첫 번째 쿼리에서는 특정 boutiqueselect 필드만 검색합니다. 불필요한 데이터를 다시 끌어오면 쿼리의 대기 시간이 늘어날 수 있으므로 필요한 필드만 선택(select)하는 것이 좋습니다. 또한 쿼리는 검색 결과와 함께 총 결과 수를 반환하도록 $count=true를 설정합니다.

// Query example 1 - Search `boutique` with select and return count
search=boutique&$count=true&$select=HotelId,HotelName,Rating,Category

다음 쿼리에서는 wifi라는 검색 용어를 지정하고, 상태가 'FL'인 결과만 반환하는 필터도 포함합니다. 결과는 Hotel의 Rating을 기준으로 정렬됩니다.

// Query example 2 - Search with filter, orderBy, select, and count
search=wifi&$filter=Address/StateProvince eq 'FL'&$select=HotelId,HotelName,Rating,Address/StateProvince&$orderby=Rating desc

다음으로, searchFields 매개 변수를 사용하여 검색을 검색 가능한 단일 필드로 제한합니다. 이는 특정 필드의 일치에만 관심이 있는 경우 쿼리를 더 효율적으로 만들 수 있는 좋은 옵션입니다.

// Query example 3 - Limit searchFields
search=sublime cliff&$select=HotelId,HotelName,Rating&searchFields=HotelName

쿼리에 포함하는 또 다른 일반적인 옵션은 facets입니다. 패싯을 사용하면 사용자가 필터링할 수 있는 값을 쉽게 알 수 있도록 앱에 필터를 빌드할 수 있습니다.

// Query example 4 - Take the top two results, and show only HotelName and Category in the results
search=*&$select=HotelId,HotelName,Rating&searchFields=HotelName&facet=Category

포털에서 인덱스 열기

포털에서 검색 서비스를 보려면 마우스 오른쪽 단추로 검색 서비스 이름을 클릭하고, 포털에서 열기를 선택합니다.

리소스 정리

본인 소유의 구독으로 이 모듈을 진행하고 있는 경우에는 프로젝트가 끝날 때 여기서 만든 리소스가 계속 필요한지 확인하는 것이 좋습니다. 계속 실행되는 리소스에는 요금이 부과될 수 있습니다. 리소스를 개별적으로 삭제하거나 리소스 그룹을 삭제하여 전체 리소스 세트를 삭제할 수 있습니다.

왼쪽 탐색 창의 모든 리소스 또는 리소스 그룹 링크를 사용하여 포털에서 리소스를 찾고 관리할 수 있습니다.

무료 서비스를 사용하는 경우 인덱스, 인덱서, 데이터 원본 세 개로 제한됩니다. 포털에서 개별 항목을 삭제하여 제한 이하로 유지할 수 있습니다.

다음 단계

이제 핵심 작업을 수행하는 방법을 알게 되었으므로 인덱서와 같은 고급 기능에 대한 추가 REST API 호출을 진행하거나 인덱싱에 콘텐츠 변환을 추가하는 보강 파이프라인 을 설정할 수 있습니다. 다음 단계에서는 다음 링크를 권장합니다.