簡體   English   中英

在 Azure 認知搜索中將 2 個 Azure SQL 表合並為 1 個索引

[英]Combine 2 Azure SQL tables into 1 index in Azure Cognitive Search

我正在關注這個關於如何將 2 個不同的數據源組合成 1 個索引的示例,結果正是我想要的:來自一個數據源的索引酒店,每個都有來自另一個數據源的房間詳細信息的數組(或列表)。

就我而言,我的兩個數據源都來自一個不使用分區鍵的 Azure SQL 數據庫:

        DataSource hotelSource = DataSource.AzureSql(
            name: "hotels-sql",
            sqlConnectionString: Configuration["ConnectionStrings"],
            tableOrViewName: "hotels");
        hotelSource.DataChangeDetectionPolicy = new SqlIntegratedChangeTrackingPolicy();

        DataSource roomSource = DataSource.AzureSql(
            name: "rooms-sql",
            sqlConnectionString: Configuration["ConnectionStrings"],
            tableOrViewName: "rooms");
        roomSource.DataChangeDetectionPolicy = new SqlIntegratedChangeTrackingPolicy();

我像這樣設置索引:

    fields = new List<Field>
    {
        Field.New("Id", DataType.String, isKey: true),
        Field.New("Name", DataType.String, isSearchable: true, isRetrievable: false, analyzerName: AnalyzerName.StandardLucene),
        Field.New("Description", DataType.String, isSearchable: true, isRetrievable: false, analyzerName: AnalyzerName.StandardLucene),
        Field.New("Category", DataType.String, isRetrievable: false, isFilterable: true),
        new Field("Rooms", DataType.Collection(DataType.Complex), new List<Field>
        {
            Field.New("Name", DataType.String, isRetrievable: false, isSearchable: true, analyzerName: AnalyzerName.StandardLucene),
            Field.New("Description", DataType.String, isRetrievable: false, isSearchable: true, analyzerName: AnalyzerName.StandardLucene),
            Field.New("Category", DataType.String, isRetrievable: false, isFilterable: true)
        })
    };

    var definition = new Index()
    {
        Name = indexName,
        Fields = fields,
        ScoringProfiles = new List<ScoringProfile>
        {
            new ScoringProfile("main", new TextWeights(new Dictionary<string, double>
            {
                {"Name", 1},
                {"Description", 0.8},
                {"Rooms/Name", 0.4},
                {"Rooms/Description", 0.3}
            }))
        },
        DefaultScoringProfile = "main"
    };

    Index index = searchService.Indexes.Create(definition);

我像這樣設置映射:

Indexer hotelIndexer = new Indexer(
                name: "hotels-indexer",
                dataSourceName: hotelSource.Name,
                targetIndexName: index.Name,
                schedule: new IndexingSchedule(TimeSpan.FromMinutes(5)));

List<FieldMapping> map = new List<FieldMapping> {
                new FieldMapping("HotelId", "Id")
            };

Indexer roomIndexer = new Indexer(
                name: "rooms-indexer",
                dataSourceName: roomSource.Name,
                targetIndexName: index.Name,
                fieldMappings: map,
                schedule: new IndexingSchedule(TimeSpan.FromMinutes(5)));

Rooms 表包含一列“HotelId”,它指向它所屬酒店的 ID。

結果應該是酒店索引中的房間列表由 roomIndexer 填充了房間,但實際結果是房間與酒店一起被索引,就好像它們是酒店本身一樣。 房間列表保持空白。

我希望我提供了足夠的信息。

Azure 搜索不支持附加到集合字段(酒店索引中的房間) - 似乎您已經對數據進行了建模,希望它可以這樣做。

相反,您可以嘗試將酒店中的所有房間合並為一個字段(可能是 Azure 搜索可以使用的字符串化 JSON 表示)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM