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



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

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

搜索直接从根 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)
});

最新更新