搜索API忽略匿名用户的TrimDuplicates参数 [英] Search API Ignores TrimDuplicates Parameter for Anonymous Users

查看:64
本文介绍了搜索API忽略匿名用户的TrimDuplicates参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些利用REST API搜索文档的代码。以下是一些示例JavaScript:

I have some code that leverages the REST API to search for documents. Here is some sample JavaScript:

var url = "https://www.wecc.org/_api/search/query?";
var query = "querytext='CalendarEventID:*13957*'";
var opts = "&trimduplicates=false&rowlimit=25";
var file = "&QueryTemplatePropertiesUrl='spfile://webroot/queryparametertemplate.xml'";
jQuery.ajax({
  url:url+query+opts+file,
  method:'GET',
  headers:{'Accept':'application/json; odata=verbose'},
  success:function(d){
    var table = d.d.query.PrimaryQueryResult.RelevantResults.Table;
    console.log(table.Rows.results);
  }
});

如果用户通过身份验证,这样可以正常工作,但对于匿名用户,它会忽略trimduplicates参数,只强制值为true。我可以在返回的对象中看到,因为TotalRowsIncludingDuplicates属性是18,而TotalRows是
只有16.它还在实际查询中显示返回为SerializedQuery属性的XML:

This works fine if the user is authenticated, but for anonymous users it ignores the trimduplicates parameter and just forces a value of true. I can see that in the returned object as the TotalRowsIncludingDuplicates property is 18 while the TotalRows is just 16. It also shows in the actual query XML that is returned as SerializedQuery property:

<Query
 Culture="en-US"
 EnableStemming="True"
 EnablePhonetic="False"
 EnableNicknames="False"
 IgnoreAllNoiseQuery="True"
 SummaryLength="180"
 MaxSnippetLength="180"
 DesiredSnippetLength="90"
 KeywordInclusion="0"
 QueryText="CalendarEventID:*13957*"
 QueryTemplate=""
 TrimDuplicates="True"
 Site="98fc0bfe-6425-4d22-b2d0-f9891844bba1"
 Web="4bd63098-0c83-43cf-abdd-085f2cc55a51"
 KeywordType="True"
 HiddenConstraints="" />


我是否需要做些什么来通过REST API为经过身份验证的用户和匿名用户获取一致的行为?

Is there something I need to do to get consistent behavior for authenticated and anonymous users through the REST API?

推荐答案

嗨Greg,

这是默认情况。 SharePoint Search Rest API将为匿名访问用户设置"TrimDuplicates"设置。

This is by default. SharePoint Search Rest API will igore "TrimDuplicates" setting for anonymous access users.

解决方法是将较大的值设置为"TrimDuplicatesKeepCount"。例如100,此属性表示"指定TrimDuplicates为true时要保留的文档数":

A workaround is to set a large value to "TrimDuplicatesKeepCount" such as 100, this property means "specify the number of documents to retain when TrimDuplicates is true":

KeywordQueryProperties.TrimDuplicatesKeepCount Property

所以它将返回所有项目,即使它是重复的。

So it will return all items even it is duplicated.

在StackOverflow中检查同一个问题线程:

Check this same question thread in StackOverflow:

匿名用户和经过身份验证的用户之间的搜索结果有所不同吗?

这是一个详细解释的博客:

And here is a blog with detailed explain:

在匿名网站上使用SharePoint Search REST API

谢谢

最好的问候


这篇关于搜索API忽略匿名用户的TrimDuplicates参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆