四、POST方式 - JSON调用实例
1、调用结果显示
2、核心代码
$.ajax( { url: , type: "Post", dataType: "application/json;odata=verbose", data: JSON.stringify({ 'request': { 'Querytext': queryText, 'StartRow': 1, 'RowLimit': 8, 'SelectProperties': { 'results': ['Title', 'ContentSource', 'DisplayAuthor', 'Path'] }, 'TrimDuplicates': true, 'Refiners': 'companies,contentclass,FileType(filter=6/0/*)', //'RefinementFilters': { 'results': ['filetype:equals("txt")'] } } }), headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": xRequestDigest }, complete: ProcessSearchResult });注:本来自己想写个调用JSON的博客,但是看到CSDN上有人写过了,自己就不写了,把最重要的那段代码贴给大家参考,大家有兴趣可以参考下,博客地址附后!
五、常用的查询参数:
查询关键字(querytext)
?querytext='sharepoint'
JSON实例:
{ '__metadata' : {'type' : 'Microsoft.Office.Server.Search.REST.SearchRequest'}, 'Querytext' : 'sharepoint' }起始行(StartRow)
?querytext='sharepoint'&startrow=10
JSON实例:
{ '__metadata' : {'type' : 'Microsoft.Office.Server.Search.REST.SearchRequest'}, 'Querytext' : 'sharepoint', 'StartRow' : '10' }返回行限制(RowLimit)
?querytext='sharepoint'&rowlimit=30
JSON实例:
{ '__metadata' : {'type' : 'Microsoft.Office.Server.Search.REST.SearchRequest'}, 'Querytext' : 'sharepoint', 'RowLimit' : '30' }选择属性(SelectProperties)
?querytext='sharepoint'&selectproperties='Title,Author'
JSON实例:
{ '__metadata' : {'type' : 'Microsoft.Office.Server.Search.REST.SearchRequest'}, 'Querytext' : 'sharepoint', 'SelectProperties' : { 'results' : [ 'Title, Author' ] } }扩展名(RefinementFilters)
?querytext='sharepoint'&refinementfilters='fileExtension:equals("docx")'
JSON实例:
{ '__metadata' : {'type' : 'Microsoft.Office.Server.Search.REST.SearchRequest'}, 'Querytext' : 'sharepoint', 'RefinementFilters' : { 'results' : ['fileExtension:equals("docx")'] } }排序(SortList)
?querytext='sharepoint'&sortlist='rank:descending,modifiedby:ascending'
JSON实例:
{ '__metadata' : {'type':'Microsoft.Office.Server.Search.REST.SearchRequest'}, 'Querytext' : 'sharepoint', 'SortList' : { 'results' : [ { 'Property':'Created', 'Direction': '0' }, { 'Property':'FileExtension', 'Direction': '1' } ] } }返回总长度(SummaryLength)
?querytext='sharepoint'&summarylength=150
JSON实例:
{ '__metadata':{'type':'Microsoft.Office.Server.Search.REST.SearchRequest'}, 'Querytext' : 'sharepoint', 'Summarylength' : '150' }