代码之家  ›  专栏  ›  技术社区  ›  Thomas Segato

带镶嵌面的SearchIndexClient

  •  0
  • Thomas Segato  · 技术社区  · 7 年前

    results = indexClient.Documents.Search<Hotel>("budget", parameters);
    

    在搜索服务资源管理器中,它类似于:

    &facet=Group
    

    结果:

    {
        "@odata.context": "https://xxx-dev.search.windows.net/indexes('influencers')/$metadata#docs",
        "@search.facets": {
            "Group@odata.type": "#Collection(Microsoft.Azure.Search.V2017_11_11.QueryResultFacet)",
            "Group": [
                {
                    "count": 426,
                    "value": "Gaming"
                },
                {
                    "count": 388,
                    "value": "Action Sports"
                },
                {
                    "count": 379,
                    "value": "Music"
                },
                {
                    "count": 378,
                    "value": "Sport"
                }
            ]
        },
        "value": [
            {
                "@search.score": 1,
                "id": "fc4b1200-fb91-4fe0-a251-beb351ee2988",
                "FirstName": "Chase",
                "LastName": "Powell",
                "Mobile": "500-0545772",
                "Country": "Sweden",
                "Group": "Music",
                "SubGroups": [
                    "Jazz",
                    "Electronic Dance",
                    "Rock Music",
                    "Pop",
                    "Techno",
                    "Indie Rock",
                    "Dubstep"
                ]
            },
            {
                "@search.score": 1,
                "id": "131f3d54-9b36-4b60-bb38-4d412bcc1682",
                "FirstName": "Ian",
                "LastName": "Bryant",
                "Mobile": "236-3224487",
                "Country": "Denmark",
                "Group": "Gaming",
                "SubGroups": [
                    "World of Warcraft ",
                    "Counter-Strike",
                    "League of Legends"
                ]
            }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Tom Sun    7 年前

    然而,我找不到任何东西时,与方面的工作。您如何使用SearchServiceClient和facets?

    demo source code 为了得到答案。 以下是Azure搜索演示中的代码片段。

    SearchParameters sp = new SearchParameters()    
    {    
        ...
        Select = new List<String>() {"id", "agency", "posting_type",...},
        ....
        // Add facets    
        Facets = new List<String>() { "business_title", "posting_type", "level", "salary_range_from,interval:50000" },
    
    };
    // Add filtering
    
    string filter = null;
    if (businessTitleFacet != "")
    filter = "business_title eq '" + businessTitleFacet + "'";
    if (postingTypeFacet != "")
    
      {
        if (filter != null)
        filter += " and ";
        filter += "posting_type eq '" + postingTypeFacet + "'";
    
      }
     ....
     sp.Filter = filter;
     _indexClient.Documents.Search(searchText, sp);
    
    推荐文章