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
Esempio n. 2
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)
    async def _prepare_indexer(self, endpoint, api_key, name="sample-indexer", ds_name="sample-datasource", id_name="hotels"):
        con_str = self.settings.AZURE_STORAGE_CONNECTION_STRING
        self.scrubber.register_name_pair(con_str, 'connection_string')
        credentials = DataSourceCredentials(connection_string=con_str)
        container = DataContainer(name='searchcontainer')
        data_source = DataSource(
            name=ds_name,
            type="azureblob",
            credentials=credentials,
            container=container
        )
        client = SearchServiceClient(endpoint, AzureKeyCredential(api_key))
        ds_client = client.get_datasources_client()
        ds = await ds_client.create_datasource(data_source)

        index_name = id_name
        fields = [
        {
          "name": "hotelId",
          "type": "Edm.String",
          "key": True,
          "searchable": False
        }]
        index = Index(name=index_name, fields=fields)
        ind_client = client.get_indexes_client()
        ind = await ind_client.create_index(index)
        return Indexer(name=name, data_source_name=ds.name, target_index_name=ind.name)
async def create_indexer():
    # create an index
    index_name = "hotels"
    fields = [
        SimpleField(name="hotelId", type=edm.String, key=True),
        SimpleField(name="baseRate", type=edm.Double)
    ]
    index = Index(name=index_name, fields=fields)
    ind_client = service_client.get_indexes_client()
    async with ind_client:
        await ind_client.create_index(index)

    # [START create_indexer_async]
    # create a datasource
    ds_client = service_client.get_datasources_client()
    credentials = DataSourceCredentials(connection_string=connection_string)
    container = DataContainer(name='searchcontainer')
    ds = DataSource(name="async-indexer-datasource", type="azureblob", credentials=credentials, container=container)
    async with ds_client:
        data_source = await ds_client.create_datasource(ds)

    # create an indexer
    indexer = Indexer(name="async-sample-indexer", data_source_name="async-indexer-datasource", target_index_name="hotels")
    async with indexers_client:
        result = await indexers_client.create_indexer(indexer)
    print("Create new Indexer - async-sample-indexer")
def create_index():
    # [START create_index]
    name = "hotels"
    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)

    result = client.create_index(index)
    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)
def test_listize_flags_for_index():
    pattern_analyzer = _PatternAnalyzer(name="test_analyzer", flags="CANON_EQ")
    analyzers = []
    analyzers.append(pattern_analyzer)
    pattern_tokenizer = _PatternTokenizer(name="test_tokenizer",
                                          flags="CANON_EQ")
    tokenizers = []
    tokenizers.append(pattern_tokenizer)
    index = Index(name="test",
                  fields=None,
                  analyzers=analyzers,
                  tokenizers=tokenizers)
    result = listize_flags_for_index(index)
    assert isinstance(result.analyzers[0], PatternAnalyzer)
    assert isinstance(result.analyzers[0].flags, list)
    assert result.analyzers[0].flags[0] == "CANON_EQ"
    assert isinstance(result.tokenizers[0], PatternTokenizer)
    assert isinstance(result.tokenizers[0].flags, list)
    assert result.tokenizers[0].flags[0] == "CANON_EQ"
Esempio n. 9
0
async def create_index():
    # [START create_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_profiles = []
    index = Index(name=name,
                  fields=fields,
                  scoring_profiles=scoring_profiles,
                  cors_options=cors_options)

    result = await service_client.create_index(index)
def test_delistize_multi_flags_for_index():
    pattern_analyzer = PatternAnalyzer(name="test_analyzer",
                                       flags=["CANON_EQ", "MULTILINE"])
    analyzers = []
    analyzers.append(pattern_analyzer)
    pattern_tokenizer = PatternTokenizer(name="test_analyzer",
                                         flags=["CANON_EQ", "MULTILINE"])
    tokenizers = []
    tokenizers.append(pattern_tokenizer)
    index = Index(name="test",
                  fields=None,
                  analyzers=analyzers,
                  tokenizers=tokenizers)
    result = delistize_flags_for_index(index)
    assert isinstance(result.analyzers[0], _PatternAnalyzer)
    assert isinstance(result.analyzers[0].flags, str)
    assert result.analyzers[0].flags == "CANON_EQ|MULTILINE"
    assert isinstance(result.tokenizers[0], _PatternTokenizer)
    assert isinstance(result.tokenizers[0].flags, str)
    assert result.tokenizers[0].flags == "CANON_EQ|MULTILINE"
Esempio n. 11
0
def update_index():
    # [START update_index]
    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 = service_client.create_or_update_index(index_name=index.name,
                                                   index=index)