Filtrage avancé
4 min
dans la section "facettage", nous mettons en évidence comment on peut obtenir les filtres disponibles pour une requête de recherche et appliquer des filtres pour affiner les résultats de recherche par exemple, après avoir recherché "chaussures", un acheteur peut vouloir affiner les résultats en appliquant un filtre sur l'attribut couleur et en choisissant une valeur telle que rouge ce faisant, seules les chaussures "rouges" apparaîtront dans les résultats si à ce stade, l'acheteur choisit une autre couleur, par exemple, bleu, klevu affichera maintenant à la fois les chaussures "rouges" et les "bleues" ainsi, il appliquera l'opération ou entre les valeurs du même attribut si à ce stade, l'acheteur choisit "coton" comme matériau, le système affichera à la fois les chaussures rouges et bleues, mais il s'assurera également que tous les produits ont "coton" comme matériau en d'autres termes, il applique l'opération et entre les différents types d'attributs sélectionnés cependant, il arrive un moment où l'on peut vouloir effectuer des opérations de filtrage complexes, ou en d'autres termes, des opérations de filtrage avancées par exemple, vous pouvez vouloir afficher un groupe de chaussures où "la couleur est rouge", et "la marque n'est pas adidas" vous pouvez également vouloir ajouter un autre groupe de chaussures à cet ensemble de résultats par exemple, où "la couleur est bleue ou noire", "la marque est nike", et "la fourchette de prix est entre 100 et 400" comme vous pouvez le voir, contrairement au comportement du "facettage", dans notre exemple ici, nous souhaitons avoir un ou plusieurs groupes de produits correspondant à différents groupes de conditions pour l'ensemble final des produits à retourner c'est avec cette intention de permettre des opérations de filtrage avancées sur l'ensemble des résultats que nous avons introduit une nouvelle fonctionnalité appelée "filtrage avancé" dans notre api avant l'introduction du filtrage avancé, si un utilisateur avait demandé que des filtres soient retournés ou que certains soient appliqués, klevu cherchait à trouver un ensemble de produits pertinents correspondant à la requête de l'utilisateur il incluait/excluait ensuite tous les produits demandés explicitement dans cet ensemble de résultats c'est après cette étape qu'il calcule tous les filtres possibles à retourner et applique également les filtres sélectionnés pour affiner les résultats de recherche ainsi, si un produit ajouté explicitement ne correspondait pas au filtre appliqué, il serait exclu de l'ensemble final des résultats avec l'ajout du filtrage avancé, klevu identifie maintenant un ensemble de produits pertinents correspondant à la requête il applique ensuite le filtrage avancé à cela c'est après cette étape qu'il inclut/exclut tous les produits demandés explicitement, calcule les filtres basés sur cet ensemble de résultats, et enfin applique les filtres sélectionnés pour affiner les résultats de recherche de cette manière, s'il y a un filtrage à appliquer avant d'inclure/exclure des produits explicitement, le filtrage avancé doit être utilisé veuillez noter que le filtrage avancé peut également être utilisé avec les api de marchandisage par catégorie et de recommandation le groupcondition l'objet peut être utilisé pour appliquer les conditions de filtrage avancé afin que vos clients puissent affiner leurs résultats en fonction des attributs pertinents { "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", "language" "javascript", "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}", "customlabel" "request body (json)" }, { "id" "kzctsnc3rkjgprbccf8m9", "language" "php", "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", "customlabel" "" }, { "id" "0km4dtw6lhpnb6pvye38z", "language" "javascript", "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);", "customlabel" "" }, { "id" "kziqnera bmhmph 5wfvo", "language" "java", "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();", "customlabel" "" }, { "id" "zhiqfphbhfqcszstcylq ", "language" "nodejs", "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", "customlabel" "" } ], "selectedlanguageid" "ckgzyslv7r8qjuvathyzf" }, "description" "example is as below ", "currentnewparameter" { "label" "body parameter", "value" "bodydataparameters" }, "hastryitout" false, "autogeneratedanchorslug" "apply advanced filtering", "legacyhash" "btm8bodgnphz0z4dy56ub" }