【问题标题】:Get the internal id for a refineablestring获取可细化字符串的内部 id
【发布时间】:2019-04-03 15:48:51
【问题描述】:

我正在构建一个查询,它将用户重定向到包含相关查询信息的搜索页面。我的问题是我知道如何获取 refinablestring 的内部 id 的唯一方法是通过地址栏,我需要一种能够通过 JavaScript 获取内部 id 的方法。

当我说内部 ID 时,我的意思是:

名称:Refinablestring00

内部标识:ǂǂ446f63756d656e7460547970652031

生成(解码)的查询:

/sites/example/pages/Search.aspx#Default={"k":"*","r": 
[{"n":"RefinableString00","t": 
["\"ǂǂ4469736363706c696e652032\""],"o":"and","k":false,"m":null}]}

为了澄清,我希望能够获得内部 ID,并且我可以访问 JSOM/客户端。我有什么选择?

谢谢,

【问题讨论】:

    标签: javascript sharepoint sharepoint-2013 sharepoint-online sharepoint-search


    【解决方案1】:

    这没有官方记录,但我们开始了。 我们来看看refiner filter是如何表示的:

    { 
         "k": queryText,    //search query 
         "r": [   //<- the list of refiners
                  { 
                      "n": propertyName,   //property value 
                      "t": [token],  //encoded property value (see below for a more details)  
                      "o": "and",    //(or,and) operators
                      "k": false, 
                      "m": null 
                  }
          ],
          //another refiners go here.. 
          "l": lcid   //language 
    } 
    

    其中token 表示编码属性值,可以这样生成:

    var strToHex = function (value) {
         var hex = unescape(encodeURIComponent(value))
            .split('').map(function(v){
                 return v.charCodeAt(0).toString(16)
            }).join('')
         return hex; 
    };
    
    
    //Usage
    var propertyValue = "Jon Doe";
    var token = "\"ǂǂ" + strToHex(propertyValue) + "\"";
    console.log(token);

    示例

    以下示例演示如何生成搜索 url,其中包含属性名称为 DisplayAuthor 和值 Jon Doe 的精炼器过滤器

    function createRefiner(queryText,propertyName, propertyValue,lcid) {
         lcid = lcid || 1033;
         var strToHex = function (value) {
                    var hex = unescape(encodeURIComponent(value))
                        .split('').map(function(v){
                             return v.charCodeAt(0).toString(16)
                       }).join('')
                    return hex; 
         };
         var token = "\"ǂǂ" + strToHex(propertyValue) + "\"";
         return { 
                  "k": queryText, 
                  "r": [{ "n": propertyName, "t": [token], "o": "and", "k": false, "m": null }], 
                  "l": lcid 
         };
    }
    
    
    //Usage
    var refiner = createRefiner("*","DisplayAuthor","Jon Doe");
    var queryGroupName = "Default";
    var refinerFilter = queryGroupName + '=' + encodeURIComponent(JSON.stringify(refiner));
    var pageUrl = "/_layouts/15/osssearchresults.aspx" + '#' + refinerFilter;
    console.log(pageUrl);

    【讨论】:

    • 嘿伙计,回复有点晚,但答案非常好!我昨天测试了它,它按预期工作 - 谢谢。
    猜你喜欢
    • 2019-07-30
    • 2020-06-02
    • 1970-01-01
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    • 2013-11-05
    • 2017-10-03
    • 2016-11-11
    相关资源
    最近更新 更多