SharePoint列表搜索(非全局搜索) [英] SharePoint List search (NOT global search)
问题描述
您好,
使用CSOM我想在特定列表中执行搜索并返回列表项。
Using CSOM I want to perform a search in a specific list AND return list items.
如果已尝试过
If have experimented with
KeywordQuery keywordQuery = new KeywordQuery(clientContext);
keywordQuery.QueryText = searchText;
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
clientContext.ExecuteQuery();
但这会搜索整个网站,并返回aspx页面。不列出项目,基本上这是在网站上的"全局搜索"。我需要一个'列表搜索(比如sharepoint中每个列表或库顶部的搜索框)。
But this searches the entire site, and it returns aspx pages. Not list items, basically what this does is a 'global search' on the site. I need a 'list search (like the search box on top of every list or library in sharepoint).
这可能吗?
我知道我可以编写一个caml查询来搜索我的所有40个列表列,但这是一个维护噩梦。并且由于存在列表搜索,我希望它可以通过CSOM获得
I know I could write a caml query searching all of my 40 list columns but that is a maintenance nightmare. And as list search exist I would expect it to be available through CSOM
推荐答案
Hi Mini,
Hi Mini,
如果只想搜索特定列表而不是全局搜索中的项目,可以直接使用SharePoint Rest API,如下所示:
If only want to search item in a specific list rather than global search, you could directly use SharePoint Rest API like this:
http:sp / sites / dev / _api / web / lists / getbytitle('infolist')/ items?
http:sp/sites/dev/_api/web/lists/getbytitle('infolist')/items?
filter = ID eq 2
filter=ID eq 2
这将返回Item Id列等于2,例如。
This will return the Item Id column equals to 2 for example.
更多信息供参考:
SharePoint 2013:使用REST API进行选择,过滤,排序
和SharePoint列表中的分页
对于CSOM,如果要过滤项目字段值,则必须使用CAML查询来过滤满足的项目conidtion:
And for CSOM, if want to filter item field value, it is necessary to use CAML Query to filter the items which meet conidtion:
您可以使用CAML Designer轻松构建CAML查询:
You could build CAML Query easily with CAML Designer:
https: //www.biwug.be/resources
谢谢
最好的问候
这篇关于SharePoint列表搜索(非全局搜索)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!