def test_delete_indexes_if_unchanged(self, api_key, endpoint, index_name,
                                         **kwargs):
        client = SearchIndexClient(endpoint, AzureKeyCredential(api_key))

        # 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 = SearchIndex(name=name,
                            fields=fields,
                            scoring_profiles=scoring_profiles,
                            cors_options=cors_options)
        result = client.create_index(index)
        etag = result.e_tag
        # get e tag  and update
        index.scoring_profiles = []
        client.create_or_update_index(index)

        index.e_tag = etag
        with pytest.raises(HttpResponseError):
            client.delete_index(index,
                                match_condition=MatchConditions.IfNotModified)
Пример #2
0
async def update_index():
    # [START update_index_async]
    name = "hotels"
    fields = [
        SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
        SimpleField(name="baseRate", type=SearchFieldDataType.Double),
        SearchableField(name="description", type=SearchFieldDataType.String, collection=True),
        SearchableField(name="hotelName", type=SearchFieldDataType.String),
        ComplexField(name="address", fields=[
            SimpleField(name="streetAddress", type=SearchFieldDataType.String),
            SimpleField(name="city", type=SearchFieldDataType.String),
            SimpleField(name="state", type=SearchFieldDataType.String),
        ], collection=True)
    ]

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

    result = await client.create_or_update_index(index=index)
 def test_create_or_update_index(self, api_key, endpoint, index_name,
                                 **kwargs):
     name = "hotels"
     fields = [
         SimpleField(name="hotelId",
                     type=SearchFieldDataType.String,
                     key=True),
         SimpleField(name="baseRate", type=SearchFieldDataType.Double)
     ]
     cors_options = CorsOptions(allowed_origins=["*"],
                                max_age_in_seconds=60)
     scoring_profiles = []
     index = SearchIndex(name=name,
                         fields=fields,
                         scoring_profiles=scoring_profiles,
                         cors_options=cors_options)
     client = SearchIndexClient(endpoint, AzureKeyCredential(api_key))
     result = client.create_or_update_index(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 = SearchIndex(name=name,
                         fields=fields,
                         scoring_profiles=scoring_profiles,
                         cors_options=cors_options)
     result = client.create_or_update_index(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 _test_delete_indexes_if_unchanged(self, client):
        # First create an index
        name = "hotels-del-unchanged"
        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 = SearchIndex(name=name,
                            fields=fields,
                            scoring_profiles=scoring_profiles,
                            cors_options=cors_options)
        result = await client.create_index(index)
        etag = result.e_tag
        # get eTag and update
        index.scoring_profiles = []
        await client.create_or_update_index(index)

        index.e_tag = etag
        with pytest.raises(HttpResponseError):
            await client.delete_index(
                index, match_condition=MatchConditions.IfNotModified)
Пример #5
0
def _create_index():
    name = "hotel-index"

    # Here we create an index with listed fields.
    fields = [
        SimpleField(name="hotelId",
                    type=SearchFieldDataType.String,
                    filterable=True,
                    sortable=True,
                    key=True),
        SearchableField(name="hotelName", type=SearchFieldDataType.String),
        SimpleField(name="description", type=SearchFieldDataType.String),
        SimpleField(name="descriptionFr", type=SearchFieldDataType.String),
        SimpleField(name="category", type=SearchFieldDataType.String),
        SimpleField(name="parkingIncluded",
                    type=SearchFieldDataType.Boolean,
                    filterable=True),
        SimpleField(name="smokingAllowed",
                    type=SearchFieldDataType.Boolean,
                    filterable=True),
        SimpleField(name="lastRenovationDate",
                    type=SearchFieldDataType.String),
        SimpleField(name="rating",
                    type=SearchFieldDataType.Int64,
                    sortable=True),
        SimpleField(name="location", type=SearchFieldDataType.GeographyPoint),
    ]
    cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)

    # pass in the name, fields and cors options and create the index
    index = SearchIndex(name=name, fields=fields, cors_options=cors_options)
    index_client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
    result = index_client.create_index(index)
    return result
Пример #6
0
    async def _test_create_or_update_index(self, client):
        name = "hotels-cou"
        fields = fields = [
            SimpleField(name="hotelId",
                        type=SearchFieldDataType.String,
                        key=True),
            SimpleField(name="baseRate", type=SearchFieldDataType.Double)
        ]

        cors_options = CorsOptions(allowed_origins=["*"],
                                   max_age_in_seconds=60)
        scoring_profiles = []
        index = SearchIndex(name=name,
                            fields=fields,
                            scoring_profiles=scoring_profiles,
                            cors_options=cors_options)
        result = await client.create_or_update_index(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 = SearchIndex(name=name,
                            fields=fields,
                            scoring_profiles=scoring_profiles,
                            cors_options=cors_options)
        result = await client.create_or_update_index(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
def create_index(name, endpoint, key):
    # Create a service client
    client = SearchIndexClient(endpoint, AzureKeyCredential(key))

    fields = [
        SimpleField(name='Id', type=SearchFieldDataType.String, key=True),
        SearchableField(name='FileName', type=SearchFieldDataType.String),
        SimpleField(name='FilePath', type=SearchFieldDataType.String),
        SearchableField(name='KeyPhrases',
                        collection=True,
                        type=SearchFieldDataType.String,
                        analyzer_name="en.lucene"),
        SearchableField(name='People',
                        collection=True,
                        type=SearchFieldDataType.String),
        SearchableField(name='Organisation',
                        collection=True,
                        type=SearchFieldDataType.String),
        SearchableField(name='Location',
                        collection=True,
                        type=SearchFieldDataType.String)
    ]

    cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
    scoring_profiles = []

    index = SearchIndex(name=name,
                        fields=fields,
                        scoring_profiles=scoring_profiles,
                        cors_options=cors_options)

    result = client.create_index(index)
 def _create_index(self, client, index_name):
     fields = [
         SimpleField(name="hotelId",
                     type=SearchFieldDataType.String,
                     key=True),
         SimpleField(name="baseRate", type=SearchFieldDataType.Double),
     ]
     scoring_profile = ScoringProfile(name="MyProfile")
     scoring_profiles = []
     scoring_profiles.append(scoring_profile)
     cors_options = CorsOptions(allowed_origins=["*"],
                                max_age_in_seconds=60)
     index = SearchIndex(name=index_name,
                         fields=fields,
                         scoring_profiles=scoring_profiles,
                         cors_options=cors_options)
     result = client.create_index(index)
def create_index():
    # [START create_index]
    name = "hotels"
    fields = [
        SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
        SimpleField(name="baseRate", type=SearchFieldDataType.Double),
        SearchableField(name="description", type=SearchFieldDataType.String, collection=True),
        ComplexField(name="address", fields=[
            SimpleField(name="streetAddress", type=SearchFieldDataType.String),
            SimpleField(name="city", type=SearchFieldDataType.String),
        ], collection=True)
    ]
    cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
    scoring_profiles = []
    index = SearchIndex(
        name=name,
        fields=fields,
        scoring_profiles=scoring_profiles,
        cors_options=cors_options)

    result = client.create_index(index)
def create_schema_from_json_and_upload(schema,
                                       index_name,
                                       admin_client,
                                       url=False):

    cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
    scoring_profiles = []
    schema_data = get_schema_data(schema, url)

    index = SearchIndex(name=index_name,
                        fields=schema_data['fields'],
                        scoring_profiles=scoring_profiles,
                        suggesters=schema_data['suggesters'],
                        cors_options=cors_options)

    try:
        upload_schema = admin_client.create_index(index)
        if upload_schema:
            print(f'Schema uploaded; Index created for {index_name}.')
        else:
            exit(0)
    except:
        print("Unexpected error:", sys.exc_info()[0])