Pnpjs: PNP Search in list

Created on 29 Oct 2020  Â·  5Comments  Â·  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [ ] Bug
  • [x] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [ v2 ]

Please specify what version(s) of SharePoint you are targeting: [ SPO ]

If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.

Expected / Desired Behavior / Question

I'm using pnp search in a custom webpart to find items based on text/search query. Can you help with the below questions?

  1. is pnp search security trimmed?
  2. is it possible to scope the search with a single library? I tried using the below but it gives error.

import { Search } from "@pnp/sp";

const search = new Search("Your URL");

const results = await search.execute({your query object or string})

code answered question

All 5 comments

Hi @Namrata99sah,

  1. Yes, the search API is security trimmed.
  2. Yes, search API allows it, e.g. by providing Path property in KQL:
import { sp } from '@pnp/sp/presets/all';

(async () => {

  const rootAbsPath = 'https://contoso.sharepoint.com/sites/site/Shared%20Documents';
  const res = await sp.search(`* Path:"${rootAbsPath}"`);

  console.log(res.PrimarySearchResults);

})().catch(console.log);

To add to what @koltyakov says here, there is no special pnp search. We call the REST search service in SharePoint, meaning all the features and security remain in effect.

Hi,

I'm getting below error when trying to map the results into Details List.

Uncaught TypeError: Cannot read property 'length' of undefined
at Selection.IDeG.Selection.setItems (Selection.js:70)
at DetailsListBase.DfTE.DetailsListBase.componentWillReceiveProps

Any ideas?

On Thu, Oct 29, 2020 at 6:16 PM Patrick Rodgers notifications@github.com
wrote:

To add to what @koltyakov https://github.com/koltyakov says here, there
is no special pnp search. We call the REST search service in SharePoint,
meaning all the features and security remain in effect.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/pnp/pnpjs/issues/1423#issuecomment-718729207, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AO5XI2PG2SOOMBAA5J7ZW7TSNFPZVANCNFSM4TDT2LIQ
.

You're evoking length property for the object which is undefined, in a custom JS file with name Selection.js (oh, it looks like Office UI Fabric) on a line number 70. =) Anyways, this is not connected with PnPjs.

Going to close this.

Was this page helpful?
0 / 5 - 0 ratings