Pnpjs: Search doesn't work

Created on 8 Nov 2018  路  13Comments  路  Source: pnp/pnpjs

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

pnp\js [ 1.2.4 ]
SharePoint [ OnPremise 2016 / OnPremise 2019 ]

Expected / Desired Behavior / Question

Expected to get Sharepoint Search Results

Observed Behavior

Got OData error:

{"odata.error":{"code":"-1, Microsoft.Data.OData.ODataException","message":{"lang":"en-US","value":"An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected."}}}

Steps to Reproduce

Run this code:

const results: SearchResults = await sp.search("test");

code fixed bug

Most helpful comment

Hey @koltyakov , i have added a PR to fix this regression. Can you take a quick look ?

All 13 comments

Can you share any additional code or configuration around your usage? How is the code deployed?

The code is in an async method triggered by an input change event. The project is a POC with React, packed with webpack. There is not much else.

I tried it on a SP2016 and SP2019 Machine, both have the same error.

Search service is working, and JSOM can get the results.

Was able to reproduce in SPO too. The difference with the previous version looks to be in the payload.
Seems that having an empty array for QueryTag prop leading to the error:

image

Trying some raw requests to figure the reason out.

UPD:

Confirming, this is because of this change #320. Assumably, QueryTag should be a string, but not the array. As it was your PR, @gautamdsheth, could you please take a look too?

I used this piece of code for quick tests in SP Editor's console:

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

const siteUrl = "https://contoso.sharepoint.com/sites/site";

const client = new SPHttpClient();

client.post(`${siteUrl}/_api/search/postquery`, {
    body: JSON.stringify({
        request: {
            HitHighlightedProperties: {results: []},
            Properties: {results: []},
            // QueryTag: {results: []}, // Causes error if to uncomment // QueryTag should be a string?
            Querytext: "test",
            RefinementFilters: {results: []},
            ReorderingRules: {results: []},
            SelectProperties: {results: []},
            SortList: {results: []},
            __metadata: {type: "Microsoft.Office.Server.Search.REST.SearchRequest"}
        }
    })
})
    .then(r => r.json())
    .then(console.log)
    .catch(console.log);

OK, this was then a regression as that was just added in the last version. We'll need to get it fixed then and likely push an interim release.

For the quick fix in the dist of sp.js and sp.es5.js
Search for

QueryTag:
look for these lines
QueryTag: this.fixArrPop(query.QueryTag)
replace with
QueryTag: query.QueryTag

Hey @koltyakov , i have added a PR to fix this regression. Can you take a quick look ?

I just pushed 1.2.5 release that contains the fix from @gautamdsheth. Please grab that version and give it a try.

Looking good. Thanks for the update! 馃憤

Great, glad to hear it.

I've confirmed this resolves the issue. Thanks for taking care of this so quickly. It directly affected a web part I was developing.

Yep, hate to see regressions get in, but it happens. We do our best to test things but occasionally stuff gets missed. Best we can do is get a fix out fast for folks. Thanks everyone who let us know.

Apologies to all for breaking it in the first place , i am really sorry :(

All good, it was reported, identified, and fixed very quickly. That's the best any of us can do. You're doing great work and it is much appreciated by myself and everyone else!

Was this page helpful?
0 / 5 - 0 ratings