【问题标题】:SharePoint Search C# with Keyword Query Filter based on Search Keyword and Content Type基于搜索关键字和内容类型的带有关键字查询筛选器的 SharePoint 搜索 C#
【发布时间】:2020-07-12 20:44:30
【问题描述】:

我正在尝试基于“财务”等关键字进行 SharePoint 搜索,然后根据 2 种内容类型过滤结果。

我可以根据关键字“财务”搜索网站,但无法确定在哪里添加过滤查询。

C# 代码:

ClientContext clientContext = new ClientContext("SITE_URL");
            clientContext.Credentials = credentials;
            KeywordQuery keywordQuery = new KeywordQuery(clientContext)
            {
                QueryText = "Finance",
                RowLimit = 50
            };

            SearchExecutor searchExecutor = new SearchExecutor(clientContext);

            ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
            clientContext.ExecuteQuery();

            Console.WriteLine("Title");
            Console.WriteLine("--------------------------------------------------");
            foreach (var resultRow in results.Value[0].ResultRows)
            {
                Console.WriteLine(resultRow["Title"]);
            }

来自 SharePoint 页面的搜索过滤器:

{searchboxquery} Path:{Site.URL}* (ContentTypeID:0x012002* AND CustomArticleAttachment:null) OR ContentTypeID:0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D000B78192FF0604947A8C72A5A95B15DD5*  (contentclass:STS_List OR contentclass:STS_List_DocumentLibrary)

欢迎提出任何建议。

谢谢

【问题讨论】:

    标签: office365 sharepoint-online sharepoint-search


    【解决方案1】:

    我认为 CSOM 不会让您在代码中提供过滤器指令,但您可以创建一个 SharePoint search scope(结果源)来预先进行过滤。然后,在您的 CSOM 中引用该搜索范围。

    请参阅this SE thread 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多