Pnpjs: Format for Search RefinementFilters

Created on 30 Oct 2018  路  4Comments  路  Source: pnp/pnpjs

Hello

Due to current limitation of the metadata filtering with out of the box search, I am building a custom search with pnp.

I am having trouble filtering my refiners that comes with my search result. I know I'm probably not doing constructing the format correctly.

I'm using my initial query but adding parameters to the RefinementFilters option:

sp.search({
Querytext: 'search sharepoint',
Rowlimit: 100,
RefinementFilters: ["ANZ:莻莻414e5a"],
SelectedProperties: fieldArray
})

How should the refinement filters be structured: [refinerName + ':' + refinerToken]. I know this is not working for me.

Cheers

answered question

Most helpful comment

I've been working a lot with these refinements today and I have a better understanding so dropping a note here for future reference to myself and others.

I was very close (as usual) with the format i had in my initial question. The best answer is this:
[MappedPropertyName + ':' + 'refinerToken'] - not refiner name as i was initially using.

So example would be RefinementFilters: ["RefinableString03:'莻莻436f6f6c206d616e'"] or for multiple refinement matches use: ["or(RefinableString02:'莻莻47434e',RefinableString03:'莻莻414141')"]

If you want to use refinement values rather than refinement token, you could also construct as RefinementFilters: ["or(RefinableString02:equals('GCN'),RefinableString03:equals('AAA'))"].

But it's best to use token because when the refinement has spaces it tends to fail. So this will fail:
["RefinableString03:equals('Cool man')"]. I think you could encode the space with a plus but i haven't test this: ["RefinableString03:equals('Cool+man')"].

Hope this helps for those working on this in the future. Documentation on this really need to be improved as its so hard to find good docs on this.

There is a good documentation on doing this with CSOM but the format is slightly different. In the doc they used [refinerName + ':' + refinerToken], which is what i was trying initially but doesn't work in SPFx.

All 4 comments

Ok found the answer to my own question. I was over thinking this.

The right format is [RefinableString: RefineValue]

So example RefinementFilters: ["RefinableString02:ANZ"]

And that's it!

I've been working a lot with these refinements today and I have a better understanding so dropping a note here for future reference to myself and others.

I was very close (as usual) with the format i had in my initial question. The best answer is this:
[MappedPropertyName + ':' + 'refinerToken'] - not refiner name as i was initially using.

So example would be RefinementFilters: ["RefinableString03:'莻莻436f6f6c206d616e'"] or for multiple refinement matches use: ["or(RefinableString02:'莻莻47434e',RefinableString03:'莻莻414141')"]

If you want to use refinement values rather than refinement token, you could also construct as RefinementFilters: ["or(RefinableString02:equals('GCN'),RefinableString03:equals('AAA'))"].

But it's best to use token because when the refinement has spaces it tends to fail. So this will fail:
["RefinableString03:equals('Cool man')"]. I think you could encode the space with a plus but i haven't test this: ["RefinableString03:equals('Cool+man')"].

Hope this helps for those working on this in the future. Documentation on this really need to be improved as its so hard to find good docs on this.

There is a good documentation on doing this with CSOM but the format is slightly different. In the doc they used [refinerName + ':' + refinerToken], which is what i was trying initially but doesn't work in SPFx.

Thank you @Mike-tech for coming back with the answer. And sorry the one was not provided from our end. Such busy days.

@koltyakov nah nah thank you! You guys are always on point and have answered many of my questions quickly in the past. So i understand sometime you are busy.
With the growth of this technology you probably will get more busier in the future.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DennisGaida picture DennisGaida  路  3Comments

un-dres picture un-dres  路  3Comments

SpliceVW picture SpliceVW  路  3Comments

ahsanranjha picture ahsanranjha  路  3Comments

jcosta33 picture jcosta33  路  3Comments