Search code examples
angularsharepointsharepoint-2010

Sharepoint: Multiple refinement filters with and condition (Using rest API for Angular4)


I m using SharePoint rest api to retrieve data:

myURL/_api/search/query?rowlimit=500&trimduplicates=false+ .... +
refinementfilters=%27CountryCDH:("USA")%27,%27(ColorChoiceCDH:("Red"),ColorChoiceCDH:("Blue"))%27

Here is my requirement: I do have three column which can have mixed search on data.

  • Country ( It can be USA, UK, ..)

  • Color ( it can be red/blue/green)

  • Type ( S, M, L, XL)

How do I create refinement filter query out of it?

Currently getting the issue for building a query.

-1, Microsoft.SharePoint.Client.InvalidClientQueryException
 The expression "'CountryCDH:("USA")','(ColorChoiceCDH:("Red"),ColorChoiceCDH:("Blue"))'" is not valid.

Thanks in advance. Help me to build query


Solution

  • As a general pattern for ANDs and ORs:

    &refinementfilters='or(fileExtension:equals("docx"),fileExtension:equals("pptx"))'
    

    Assuming you are using refinable properties, them maybe something like:

    &refinementfilters='and(CountryCDH:equals("USA"),ColorChoiceCDH:equals("Red"),ColorChoiceCDH:equals("Blue"))'