简体   繁体   English

如何使用 Sharepoint Server Search(KeywordQuery 类)来搜索共享点列表?

[英]How to use Sharepoint Server Search (KeywordQuery class) to search through a sharepoint list?

We have a requirement where users are to be allowed to search a list called "Reports" from the front-end, and advanced search, such as author:"John Smith" or filetype:docx , is to be supported.我们有一个要求,即允许用户从前端搜索名为“Reports”的列表,并支持高级搜索,例如author:"John Smith"filetype:docx

We decided that this can be achieved using Sharepoint Server Search API (using the Keyword Query Language ).我们决定这可以使用Sharepoint Server Search API (使用关键字查询语言)来实现。 Also, since it is possible that all users don't have access to all items in the list, we decided to go with the approach to use a web method with elevated privileges to query the list.此外,由于所有用户可能无法访问列表中的所有项目,因此我们决定采用具有提升权限的 Web 方法来查询列表的方法。

This is my attempt so far...这是我迄今为止的尝试......

public string GetSearchResults(string listname, string searchQuery)
{
    SPUser superUser = SPContext.Current.Web.AllUsers[@"SHAREPOINT\SYSTEM"];
    using (SPSite site = new SPSite(SPContext.Current.Web.Url, superUser.UserToken))
    {
        KeywordQuery keywordQuery = new KeywordQuery(site);
        keywordQuery.QueryText = searchQuery;

        //where should listname be specified?

        SearchExecutor searchExecutor = new SearchExecutor(); 
        ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery); 
        var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults); 
        ResultTable resultTable = resultTables.FirstOrDefault(); 
        DataTable dataTable = resultTable.Table; 
    }

    //how to parse result to filter only items in given list?
}

...but what I don't understand is how to restrict search to only a given list or how to parse the search result to retrieve items of the list matching the search query. ...但我不明白的是如何将搜索限制为仅给定列表或如何解析搜索结果以检索与搜索查询匹配的列表项。

I'm new to Sharepoint search, so any pointers would help.我是 Sharepoint 搜索的新手,所以任何指针都会有所帮助。

这可以在查询文本中提供列表路径或列表 guid

keywordQuery.QueryText = "Path:/Sales/Lists/Prospects/ (contentclass:STS_ListItem OR IsDocument:True) -ContentClass=urn:content-class:SPSPeople ";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM