Guide
Smart Search
Advanced Filtering
4 min
in the "faceting" section, we highlight how one can obtain available filters for a search query and apply filters to narrow down search results for example, after searching for "shoes", a shopper may want to narrow down results by applying a filter on the color attribute and choosing a value such as red doing so will show only "red" shoes in the results if at this point, the shopper chooses yet another color, e g blue, klevu will now show both the "red" and the "blue" shoes thus, it will apply the or operation between the values of the same attribute if at this stage, the shopper chooses "cotton" as a material, the system will show both the red and blue shoes, but it will also ensure all products have "cotton" as a material as well in other words, it applies the and operation among the different types of selected attributes however, there comes a time when one may want to perform complex filtering operations, or in other words, advanced filtering operations for example, you may want to show a group of shoes where the "color is red" and the "brand is not adidas" you may also want to add another group of shoes to this result set for example, where the "color is blue or black", "brand is nike" and the "price range is between 100 and 400" as you can see, unlike the behaviour of "faceting", in our example here, we like to have one or more groups of products matching different groups of conditions for the final set of products to be returned it is with this intention to allow advanced filtering operations on the result set, we have introduced a new functionality called "advanced filtering" in our api before the introduction of advanced filtering, if a user had requested filters to be returned or some to be applied, klevu used to find out a set of relevant products matching the user query it then included/excluded any products requested explicitly to this result set it is after this stage that it calculated all possible filters to be returned and also applied the selected filters to narrow down the search results thus, if an explicitly added product did not match the applied filter, it would be excluded in the final result set with the addition of advanced filtering, klevu now identifies a set of relevant products matching the query it then applies advanced filtering to this it is after this step that it includes/excludes any products requested explicitly, calculates filters based on this result set and finally applies the selected filters to narrow down the search results this way, if there is any filtering to be applied prior to including/excluding products explicitly, advanced filtering should be used please note the advanced filtering can also be used with category merchandising and recommendation apis the groupcondition object can be used for applying the advanced filtering conditions so your customers can fine tune their results based on relevant attributes tab examples url https hostname cs v2 search name apply advanced filtering method post request pathparameters queryparameters headerparameters bodydataparameters kind optional name groupoperator type string description defining the condition of filtering here are the options available nall of this is used to filter data using and query i e the search results are matching with all the attributes n nany of this is used to filter data using or query i e the search results are matching with at least one attributes n nnone of this is used as negation and query i e when search results are matching with none of the attribute values kind optional name key type string children description the id of the attribute to filter by eg color kind optional name valueoperator type string children description t ndefining an attribute s operation here are the options available n ninclude this is used to include specific attribute for the filter purpose n nexclude this is used to exclude specific attribute for the filter purpose n nexists this is used to find if the specific indexed attribute value exists with product n n not exists this is used to find if the specific indexed attribute value does not exist at all kind optional name singleselect type boolean children description the behaviour when specifying multiple filters or values n nif it is set to true the products returned must have both the values nif it is set to false the products returned must have at least one of the values n kind optional name excludevaluesinresult type boolean children description for numeric filter like price can be used to exclude data of the starting or ending values for example if the range is defined as 1200 1232 in values and excludevaluesinresult is set to true klevu will use range as 1201 1231 n nthis can be used to achieve greater than or less than condition for example if you want to get the products greater than price 200 the values field will be 200 and the excludevaluesinresult will be set to true kind optional name values type array children description an array of values to filter by eg red blue when using range filters specify the first value as the minimum value and the second as the max value for example to retrieve records with prices between 60 to 80 use key klevu price values 60 80 nto retrieve steps of prices for example those with values between 0 50 or 150 200 use key klevu price values 0 50 150 200 n nto retrieve exact values for example records with exact values 100 or 200 use key klevu price values 100 100 200 200 nby default all attributes submitted to klevu are indexed as string attributes which means they cannot be used as range filters the product sale price field is the only exception to this rule which is filtered using the key klevu price if you have explicitly requested and klevu has approved that certain attributes be indexed as numerical attributes you can also retrieve those as range filters formdataparameters results languages id r tjakr3 5xmiwv1krrwj code n meta n qtime 9 n responsecode 200 n n queryresults n n id productsearch n meta n qtime 7 n noofresults 2 n totalresultsfound 6 n typeofsearch wildcard and n offset 0 n debugginginformation n notificationcode 1 n searchedterm tee n apikey klevu 156925593843210765 n ispersonalised false n n records n n discount n hidegroupprices n type tees n itemgroupid 4384027344958 n freeshipping n storebasecurrency gbp n price 24 00 n toprice n imageurl https cdn shopify com s files 1 0116 9457 1582 products ws05 yellow main fe09e105 6b7e 4269 9b53 edc3735127ba medium jpg?v 1575477895 n currency gbp n instock yes n id 31366447038526 n imagehover n sku ws05 xs yellow n brand kke n baseprice 24 0 n startprice n image https cdn shopify com s files 1 0116 9457 1582 products ws05 yellow main fe09e105 6b7e 4269 9b53 edc3735127ba medium jpg?v 1575477895 n deliveryinfo n hideaddtocart n saleprice 24 0 n swatchesinfo n weight n klevu category klevu product;products;;tees ku kucategory ku n totalvariants 0 n groupprices n url https jsv2 shopify demo ksearchmisc com products desiree fitness tee yellow n tags comfort flattering fit micro sleeve summer v neck n size medium n name desiree fitness tee n shortdesc when you re too far to turn back thank yourself for choosing the desiree fitness tee its ultra lightweight ultra breathable fabric wicks sweat away from your body and helps keeps you cool for the distance short sleeves performan n category tees n typeofrecord klevu product n n n discount n hidegroupprices n type tees n itemgroupid 4384047759422 n freeshipping n storebasecurrency gbp n price 24 00 n toprice n imageurl https cdn shopify com s files 1 0116 9457 1582 products ms01 yellow main 11be227e 034a 4bb1 ae91 ef28227d26ed medium jpg?v 1575478213 n currency gbp n instock yes n id 31366478200894 n imagehover n sku ms01 xs yellow n brand mnh n baseprice 24 0 n startprice n image https cdn shopify com s files 1 0116 9457 1582 products ms01 yellow main 11be227e 034a 4bb1 ae91 ef28227d26ed medium jpg?v 1575478213 n deliveryinfo n hideaddtocart n saleprice 24 0 n swatchesinfo n weight n klevu category klevu product;products;;tees ku kucategory ku n totalvariants 0 n groupprices n url https jsv2 shopify demo ksearchmisc com products aero daily fitness tee yellow n tags comfort crew neck machine relaxed fit short sleev yellow n size medium n name aero daily fitness tee n shortdesc need an everyday action tee that helps keep you dry? the aero daily fitness tee is made of 100 polyester wicking knit that funnels moisture away from your skin don t be fooled by its classic style; this tee hides premium performance technology b n category tees n typeofrecord klevu product n n n filters n n n language 200 customlabel selectedlanguageid r tjakr3 5xmiwv1krrwj examples languages id ckgzyslv7r8qjuvathyzf code n context n apikeys n klevu 156925593843210765 n n n recordqueries n n id productsearch n typeofrequest search n settings n typeofrecords n klevu product n n groupcondition n groupoperator any of n conditions n n key klevu price n valueoperator include n singleselect true n excludevaluesinresult true n values n 20 25 n n n n key itemgroupid n valueoperator exclude n singleselect false n values n 4384028262462 n n n n key size n valueoperator exclude n singleselect false n values n small n large n n n n key brand n valueoperator exists n n n key discount n valueoperator not exists n n n n query n term tee n n limit 2 n n n n language javascript customlabel request body json id kzctsnc3rkjgprbccf8m9 code ?php n n curl curl init ; n ncurl setopt array curl array n curlopt url https eucs15v2 ksearchnet com cs v2 search n curlopt returntransfer true n curlopt encoding n curlopt maxredirs 10 n curlopt timeout 0 n curlopt followlocation true n curlopt http version curl http version 1 1 n curlopt customrequest post n curlopt postfields n context n apikeys n klevu 156925593843210765 n n n recordqueries n n id productsearch n typeofrequest search n settings n typeofrecords n klevu product n n groupcondition n groupoperator any of n conditions n n key klevu price n valueoperator include n singleselect true n excludevaluesinresult true n values n 20 25 n n n n key itemgroupid n valueoperator exclude n singleselect false n values n 4384028262462 n n n t t t t t t n t t t t t t key size n t t t t t t valueoperator exclude n t t t t t t singleselect false n t t t t t t values n t t t t t t t small n large n t t t t t t n t t t t t n n key brand n valueoperator exists n n n key discount n valueoperator not exists n n n n query n term tee n n limit 2 n n n n n curlopt httpheader array n content type application json n n ; n n response curl exec curl ; n ncurl close curl ; necho response; n language php customlabel id 0km4dtw6lhpnb6pvye38z code warning for post requests body is set to null by browsers nvar data json stringify n context n apikeys n klevu 156925593843210765 n n n recordqueries n n id productsearch n typeofrequest search n settings n typeofrecords n klevu product n n groupcondition n groupoperator any of n conditions n n key klevu price n valueoperator include n singleselect true n excludevaluesinresult true n values n 20 25 n n n n key itemgroupid n valueoperator exclude n singleselect false n values n 4384028262462 n n n n key size n valueoperator exclude n singleselect false n values n small n large n n n n key brand n valueoperator exists n n n key discount n valueoperator not exists n n n n query n term tee n n limit 2 n n n n ; n nvar xhr new xmlhttprequest ; nxhr withcredentials true; n nxhr addeventlistener readystatechange function n if this readystate 4 n console log this responsetext ; n n ; n nxhr open post https eucs15v2 ksearchnet com cs v2 search ; nxhr setrequestheader content type application json ; n nxhr send data ; language javascript customlabel id kziqnera bmhmph 5wfvo code okhttpclient client new okhttpclient newbuilder n build ; nmediatype mediatype mediatype parse application json ; nrequestbody body requestbody create mediatype r n context r n apikeys r n klevu 156925593843210765 r n r n r n recordqueries r n r n id productsearch r n typeofrequest search r n settings r n typeofrecords r n klevu product r n r n groupcondition r n groupoperator any of r n conditions r n r n key klevu price r n valueoperator include r n singleselect true r n excludevaluesinresult true r n values r n 20 25 r n r n r n r n key itemgroupid r n valueoperator exclude r n singleselect false r n values r n 4384028262462 r n r n r n t t t t t t r n t t t t t t key size r n t t t t t t valueoperator exclude r n t t t t t t singleselect false r n t t t t t t values r n t t t t t t t small r n large r n t t t t t t r n t t t t t r n r n key brand r n valueoperator exists r n r n r n key discount r n valueoperator not exists r n r n r n r n query r n term tee r n r n limit 2 r n r n r n r n ; nrequest request new request builder n url https eucs15v2 ksearchnet com cs v2 search n method post body n addheader content type application json n build ; nresponse response client newcall request execute ; language java customlabel id zhiqfphbhfqcszstcylq code var request require request ; nvar options n method post n url https eucs15v2 ksearchnet com cs v2 search n headers n content type application json n n body json stringify n context n apikeys n klevu 156925593843210765 n n n recordqueries n n id productsearch n typeofrequest search n settings n typeofrecords n klevu product n n groupcondition n groupoperator any of n conditions n n key klevu price n valueoperator include n singleselect true n excludevaluesinresult true n values n 20 25 n n n n key itemgroupid n valueoperator exclude n singleselect false n values n 4384028262462 n n n n key size n valueoperator exclude n singleselect false n values n small n large n n n n key brand n valueoperator exists n n n key discount n valueoperator not exists n n n n query n term tee n n limit 2 n n n n n n ; nrequest options function error response n if error throw new error error ; n console log response body ; n ; n language nodejs customlabel selectedlanguageid zhiqfphbhfqcszstcylq description example is as below currentnewparameter label body parameter value bodydataparameters