コード例 #1
0
 async def test_create_index(self, api_key, endpoint, index_name, **kwargs):
     name = "hotels"
     fields = [{
         "name": "hotelId",
         "type": "Edm.String",
         "key": True,
         "searchable": False
     }, {
         "name": "baseRate",
         "type": "Edm.Double"
     }]
     scoring_profile = ScoringProfile(name="MyProfile")
     scoring_profiles = []
     scoring_profiles.append(scoring_profile)
     cors_options = CorsOptions(allowed_origins=["*"],
                                max_age_in_seconds=60)
     index = Index(name=name,
                   fields=fields,
                   scoring_profiles=scoring_profiles,
                   cors_options=cors_options)
     client = SearchServiceClient(endpoint, AzureKeyCredential(api_key))
     result = await client.create_index(index)
     assert result.name == "hotels"
     assert result.scoring_profiles[0].name == scoring_profile.name
     assert result.cors_options.allowed_origins == cors_options.allowed_origins
     assert result.cors_options.max_age_in_seconds == cors_options.max_age_in_seconds
async def update_index():
    # [START update_index_async]
    name = "hotels"
    fields = fields = [
        SimpleField(name="hotelId", type=edm.String, key=True),
        SimpleField(name="baseRate", type=edm.Double),
        SearchableField(name="description", type=edm.String),
        SearchableField(name="hotelName", type=edm.String),
        ComplexField(name="address", fields=[
            SimpleField(name="streetAddress", type=edm.String),
            SimpleField(name="city", type=edm.String),
            SimpleField(name="state", type=edm.String),
        ])
    ]

    cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
    scoring_profile = ScoringProfile(
        name="MyProfile"
    )
    scoring_profiles = []
    scoring_profiles.append(scoring_profile)
    index = Index(
        name=name,
        fields=fields,
        scoring_profiles=scoring_profiles,
        cors_options=cors_options)

    result = await client.create_or_update_index(index_name=index.name, index=index)
コード例 #3
0
    async def test_create_or_update_index(self, api_key, endpoint, index_name, **kwargs):
        name = "hotels"
        fields = fields = [
            SimpleField(name="hotelId", type=edm.String, key=True),
            SimpleField(name="baseRate", type=edm.Double)
        ]

        cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
        scoring_profiles = []
        index = Index(
            name=name,
            fields=fields,
            scoring_profiles=scoring_profiles,
            cors_options=cors_options)
        client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client()
        result = await client.create_or_update_index(index_name=index.name, index=index)
        assert len(result.scoring_profiles) == 0
        assert result.cors_options.allowed_origins == cors_options.allowed_origins
        assert result.cors_options.max_age_in_seconds == cors_options.max_age_in_seconds
        scoring_profile = ScoringProfile(
            name="MyProfile"
        )
        scoring_profiles = []
        scoring_profiles.append(scoring_profile)
        index = Index(
            name=name,
            fields=fields,
            scoring_profiles=scoring_profiles,
            cors_options=cors_options)
        result = await client.create_or_update_index(index_name=index.name, index=index)
        assert result.scoring_profiles[0].name == scoring_profile.name
        assert result.cors_options.allowed_origins == cors_options.allowed_origins
        assert result.cors_options.max_age_in_seconds == cors_options.max_age_in_seconds
コード例 #4
0
async def update_index():
    # [START update_index_async]
    name = "hotels"
    fields = [{
        "name": "hotelId",
        "type": "Edm.String",
        "key": True,
        "searchable": False
    }, {
        "name": "baseRate",
        "type": "Edm.Double"
    }]
    cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
    scoring_profile = ScoringProfile(name="MyProfile")
    scoring_profiles = []
    scoring_profiles.append(scoring_profile)
    index = Index(name=name,
                  fields=fields,
                  scoring_profiles=scoring_profiles,
                  cors_options=cors_options)

    result = await service_client.create_or_update_index(index_name=index.name,
                                                         index=index)
コード例 #5
0
    async def test_create_or_update_indexes_if_unchanged(self, api_key, endpoint, index_name, **kwargs):
        client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client()

        # First create an index
        name = "hotels"
        fields = [
        {
          "name": "hotelId",
          "type": "Edm.String",
          "key": True,
          "searchable": False
        },
        {
          "name": "baseRate",
          "type": "Edm.Double"
        }]
        scoring_profile = ScoringProfile(
            name="MyProfile"
        )
        scoring_profiles = []
        scoring_profiles.append(scoring_profile)
        cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
        index = Index(
            name=name,
            fields=fields,
            scoring_profiles=scoring_profiles,
            cors_options=cors_options)
        result = await client.create_index(index)
        etag = result.e_tag
        # get e tag  nd update
        index.scoring_profiles = []
        await client.create_or_update_index(index.name, index)

        index.e_tag = etag
        with pytest.raises(HttpResponseError):
            await client.create_or_update_index(index.name, index, match_condition=MatchConditions.IfNotModified)