在Sharepoint中使用pnp搜索检索列表元素

时间:2019-03-27 08:08:53

标签: sharepoint

这是在Sharepoint中使用pnp搜索检索列表元素的正确方法

 pnp.sp.search("ListName").then((r: SearchResults) => {
        console.log(r.ElapsedTime);
        console.log(r.RowCount);
        console.log(r.PrimarySearchResults);
    });

1 个答案:

答案 0 :(得分:0)

直接从根sp对象访问搜索,并且可以采用表示查询文本的字符串,与SearchQuery接口匹配的纯对象或SearchQueryBuilder实例。前两个如下所示。

import pnp, { SearchQuery, SearchResults } from "sp-pnp-js";

// text search using SharePoint default values for other parameters
pnp.sp.search("test").then((r: SearchResults) => {

    console.log(r.ElapsedTime);
    console.log(r.RowCount);
    console.log(r.PrimarySearchResults);
});

// define a search query object matching the SearchQuery interface
pnp.sp.search(<SearchQuery>{
    Querytext: "test",
    RowLimit: 10,
    EnableInterleaving: true,
}).then((r: SearchResults) => {

    console.log(r.ElapsedTime);
    console.log(r.RowCount);
    console.log(r.PrimarySearchResults);
});

搜索Office 365组。为了确保您正在Office 365中搜索所有组,请参见下面的示例,其中包括“ EnableDynamicGroups”属性。

import pnp, { SearchQueryBuilder, SearchResults, SearchQuery } from "sp-pnp-js";

const _searchQuerySettings: SearchQuery = {
    TrimDuplicates: false,
    RowLimit: 500,
    SelectProperties: ["Title", "SPWebUrl", "projectID"],
    Properties: [{
      Name: "EnableDynamicGroups",
      Value: {
        BoolVal: true,
        QueryPropertyValueTypeIndex: 3
      }
    }]
}

let q = SearchQueryBuilder.create("ContentType:ProsjektInformasjon", _searchQuerySettings).rowLimit(500);

pnp.sp.search(q).then(res => { 
    console.log(res.PrimarySearchResults.length);
    console.dir(res.PrimarySearchResults)
});