SOLVED

pnp.sp.search > syntax question (from SharePoint search API URL to PnP)

%3CLINGO-SUB%20id%3D%22lingo-sub-114246%22%20slang%3D%22en-US%22%3Epnp.sp.search%20%26gt%3B%20syntax%20question%20(from%20SharePoint%20search%20API%20URL%20to%20PnP)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-114246%22%20slang%3D%22en-US%22%3E%3CP%3EFor%20the%20first%20time%20I%20do%20some%20testing%20using%20pnp.sp.search.%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20first%20simple%20test%20is%20like%20this%3A%3C%2FP%3E%3CPRE%3Epnp.sp.search(%22SharePoint%22).then((result%20%3A%20SearchResults)%3C%2FPRE%3E%3CP%3ENow%20I%20want%20to%20convert%20an%20api%20search%20to%20pnp.%20My%20query%20is%20like%20this%3A%3C%2FP%3E%3CPRE%3Ehttps%3A%2F%2Fblabla.sharepoint.com%2Fsites%2Ftest%2F_api%2Fsearch%2Fquery%3Fquerytext%3D'ContentType%3ATEST_matters'%26amp%3Brefinementfilters%3D'RefinableString18%3Aequals(%22false%22)'%3C%2FPRE%3E%3CP%3EI've%20done%20some%20searching%20on%20the%20internet%20to%20find%20the%20syntax%20to%20covert%20this%20to%20pnp%20but%20no%20luck%20so%20far.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20how%20do%20I%20change%20my%20querystring%20in%20order%20to%20get%20it%20working%20with%20PnP%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%20Mike%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-114246%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-115017%22%20slang%3D%22en-US%22%3ERe%3A%20pnp.sp.search%20%26gt%3B%20syntax%20question%20(from%20SharePoint%20search%20API%20URL%20to%20PnP)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-115017%22%20slang%3D%22en-US%22%3E%3CP%3EGot%20it!!%20I%20tried%20to%20put%20the%20filter%20in%20the%20querytekst.%20Seems%20to%20be%20a%20wrong%20approach.%20This%20is%20the%20working%20code%3A%3C%2FP%3E%3CPRE%3E%20pnp.sp.search(%26lt%3BSearchQuery%26gt%3B%7B%0A%20%20%20%20%20%20Querytext%3A%20%22ContentType%3ATEST_matters%22%2C%0A%20%20%20%20%20%20RowLimit%3A%2010%2C%0A%20%20%20%20%20%20EnableInterleaving%3A%20true%2C%0A%20%20%20%20%20%20RefinementFilters%3A%20%5B%22RefinableString18%3Aequals('false')%22%5D%2C%0A%20%20%20%20%20%20%7D).then((result%3A%20SearchResults)%20%3D%26gt%3B%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-114635%22%20slang%3D%22en-US%22%3ERe%3A%20pnp.sp.search%20%26gt%3B%20syntax%20question%20(from%20SharePoint%20search%20API%20URL%20to%20PnP)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-114635%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F24453%22%20target%3D%22_blank%22%3E%40Patrick%20Rodgers%3C%2FA%3E.%20I%20tried%20this%20but%20it%20looks%20like%20I'm%20doing%20something%20wrong.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3Epnp.sp.search(%26lt%3BSearchQuery%26gt%3B%7B%20%20%20%20Querytext%3A%20%22ContentType%3ATEST_matters%26amp%3Brefinementfilters%3DRefinableString18%3Aequals(%22false%22)%22%2C%0A%20%20%20%20RowLimit%3A%2010%2C%0A%20%20%20%20EnableInterleaving%3A%20true%2C%0A%7D).then((r%3A%20SearchResults)%3C%2FPRE%3E%3CP%3ECan%20you%20help%20me%20out%20here%3F%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-114494%22%20slang%3D%22en-US%22%3ERe%3A%20pnp.sp.search%20%26gt%3B%20syntax%20question%20(from%20SharePoint%20search%20API%20URL%20to%20PnP)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-114494%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20pass%20a%20plain%20object%20of%20the%20search%20properties%20from%20the%20query%20string%20into%20the%20search%20method.%20You%20can%20check%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-JS-Core%2Fwiki%2FWorking-With%3A-Search%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20wiki%20page%20on%20search%3C%2FA%3E%20to%20help%20get%20you%20started.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular Contributor

For the first time I do some testing using pnp.sp.search. 

My first simple test is like this:

pnp.sp.search("SharePoint").then((result : SearchResults)

Now I want to convert an api search to pnp. My query is like this:

https://blabla.sharepoint.com/sites/test/_api/search/query?querytext='ContentType:TEST_matters'&refinementfilters='RefinableString18:equals("false")'

I've done some searching on the internet to find the syntax to covert this to pnp but no luck so far.

 

So how do I change my querystring in order to get it working with PnP?

 

Thanks, Mike

3 Replies
Highlighted

You can pass a plain object of the search properties from the query string into the search method. You can check the wiki page on search to help get you started.

Highlighted

Hi @Patrick Rodgers. I tried this but it looks like I'm doing something wrong.

 

pnp.sp.search(<SearchQuery>{    Querytext: "ContentType:TEST_matters&refinementfilters=RefinableString18:equals("false")",
    RowLimit: 10,
    EnableInterleaving: true,
}).then((r: SearchResults)

Can you help me out here?

Thanks

Highlighted
Best Response confirmed by Mike Jansen (Regular Contributor)
Solution

Got it!! I tried to put the filter in the querytekst. Seems to be a wrong approach. This is the working code:

 pnp.sp.search(<SearchQuery>{
      Querytext: "ContentType:TEST_matters",
      RowLimit: 10,
      EnableInterleaving: true,
      RefinementFilters: ["RefinableString18:equals('false')"],
      }).then((result: SearchResults) =>