コード例 #1
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)
コード例 #2
0
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)
コード例 #3
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
コード例 #4
0
    def test_defaults(self):
        fld = SearchableField(name="foo", type=edm.Collection(edm.String))
        assert fld.name == "foo"
        assert fld.type == edm.Collection(edm.String)
        assert fld.retrievable == True
        assert fld.sortable == False
        assert fld.facetable == False
        assert fld.searchable == True
        assert fld.filterable == False

        assert fld.analyzer is None
        assert fld.search_analyzer is None
        assert fld.index_analyzer is None
        assert fld.synonym_maps is None
コード例 #5
0
    def test_defaults(self):
        fld = SearchableField(name="foo", collection=True)
        assert fld.name == "foo"
        assert fld.type == SearchFieldDataType.Collection(
            SearchFieldDataType.String)
        assert fld.hidden == False
        assert fld.sortable == False
        assert fld.facetable == False
        assert fld.searchable == True
        assert fld.filterable == False

        assert fld.analyzer_name is None
        assert fld.search_analyzer_name is None
        assert fld.index_analyzer_name is None
        assert fld.synonym_map_names is None
コード例 #6
0
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)