Start a new topic

restrictBy condition on an attribute with multiple values

I'm developing Searchanise integration in an ERP/E-commerce platform.


I synchronize products with 2 additional custom attributes: division_id (int, single value) and area (text, multiple values).

I then want to filter on these attributes when making search queries.

Filtering on division_id works (with restrictBy), but on area it doesn't.



Here an XML feed I sent as an update request

 

<feed xmlns:cs="http://searchanise.com/ns/1.0" xmlns="http://www.w3.org/2005/Atom"><title>Searchanise data feed</title><updated>2016-03-23T10:20:57.299123+00:00</updated><id>boh</id><entry><summary><![CDATA[<p>Berretto grigio bello</p>\n]]></summary><link href="http://127.0.0.1:8069/shop/product/watch-berretto-grey-heather-carhartt-765"/><id>765</id><title><![CDATA[WATCH berretto - grey heather (carhartt)]]></title><cs:image_link><![CDATA[http://127.0.0.1:8069/website/image/product.template/765_9fbf8f2/image_medium]]></cs:image_link><cs:quantity>0.0</cs:quantity><cs:attribute name="division_id" type="int">6</cs:attribute><cs:attribute name="area" type="text"><value><![CDATA[Alta Moda]]></value></cs:attribute></entry></feed>

 

Some time after, I tried searching with a restrictBy condition on the area attribute, here is the search request sent:

http://www.searchanise.com/getwidgets?api_key=0r2N9g7j8s&q=be&restrictBy%5Bdivision_id%5D=6%2C6&restrictBy%5Barea%5D=Alta+Moda&maxResults=3&startIndex=0&items=true&pages=true&facets=false&categories=true&suggestions=true&pagesMaxResults=3&categoriesMaxResults=3&suggestionsMaxResults=4&query_correction=true&output=jsonp&callback=jQuery18305645538791561917_1458723980282&_=1458723982545
Is restrictBy for custom attributes with multiple values supported?

 I forgot to say, the search query didn't return anything, that's the problem. It should have returned the product in the XML feed i posted.

Hi Leonardo!


We'll check this case with our product development team and we'll update you at the earliest.


Thank you.

Hi Leonardo!


Thank you for your time and patience.


Unfortunately, our documentation is a little bit inaccurate. Yes, when the data is sent, attribute values should be enclosed into the <values> tag:


<cs:attribute name="area" type="text">

<values>

<value><![CDATA[Alta Moda]]></value>

</values>

</cs:attribute>


Thank you.

We apologize for our incorrect answer in our previous message.


It seems that the area field is empty in the database, that is why there are no results when search is performed by this field. Please try using the following line:


<cs:attribute name="area" type="text"> <value><![CDATA[Alta Moda]]></value></cs:attribute></entry>


instead of this one:


<cs:attribute name="area" type="text"><value><![CDATA[Alta Moda]]></value></cs:attribute></entry>


Namely a space should be specified before each <value> opening tag. Nothing should be enclosed into <value> tags.

The whitespace worked, thanks.
(you should really fix your XML parser though, why should whitespace be required?)

 

Hi Leonardo!

We are glad to hear it worked for you.

As for your suggestion, we have forwarded it to our software architects.

Thank you for your help.

 

Hello,
After some more testing turns out the filtering does not correctly work after all: seems like that for multiple values attributes, the rules are applied only on the first value sent!

For example, here is the entry for a product I've sent to Searchanise:
<feed xmlns:cs="http://searchanise.com/ns/1.0" xmlns="http://www.w3.org/2005/Atom">
  <title>Searchanise data feed</title>
  <updated>2016-06-28T09:52:42.676692+00:00</updated>
  <id>boh</id>
  <entry>
    <summary></summary>
    <link href="http://itmyit.odoo:8069/shop/product/dolce-pasqua-colomba-tradizionale-probios-473"/>
    <id>473</id>
    <title><![CDATA[DOLCE PASQUA - COLOMBA TRADIZIONALE  (PROBIOS)]]></title>
    <cs:image_link><![CDATA[http://itmyit.odoo:8069/website/image/product.template/473_1238b6d/image_medium]]></cs:image_link>
    <cs:quantity>0.0</cs:quantity>
    <cs:attribute name="division_id" type="int">5</cs:attribute>
    <cs:attribute name="base_tags" text_search="Y" weight="20" type="text"></cs:attribute>
    <cs:attribute name="base_tag_ids" type="int"></cs:attribute>
    <cs:attribute name="menu_tags" text_search="Y" weight="20" type="text">
      <value><![CDATA[Gourmet]]></value>
      <value><![CDATA[Bio]]></value>
      <value><![CDATA[Produttori]]></value>
    </cs:attribute>
    <cs:attribute name="category_tag_ids" type="int">
      <value>1</value>
      <value>2</value>
    </cs:attribute>
    <cs:attribute name="category_tags" text_search="Y" weight="30" type="text">
      <value><![CDATA[Salse & sughi]]></value>
      <value><![CDATA[Dolci]]></value>
    </cs:attribute>
    <cs:attribute name="menu_tag_ids" type="int">
      <value>2</value>
      <value>3</value>
      <value>6</value>
    </cs:attribute>
  </entry>
</feed>

 

If I then try some searches with filtering (restrictBy) based on the multi valued attributes (menu_tag_ids and category_tag_ids):

restrictBy[menu_tag_ids]=6,6:
> curl --globoff "http://www.searchanise.com/getwidgets?api_key=3n3B5m1N3L&q=colom&restrictBy[division_id]=5,5&restrictBy[menu_tag_ids]=6,6&maxResults=3&startIndex=0&items=true&pages=true&facets=true&categories=true&suggestions=true&pagesMaxResults=3&categoriesMaxResults=3&suggestionsMaxResults=4&query_correction=true&output=jsonp"
{"totalItems":0,"startIndex":0,"itemsPerPage":3,"currentItemCount":0,"suggestions":[],"items":[],"facets":[]}

 


 restrictBy[menu_tag_ids]=3,3:

> curl --globoff "http://www.searchanise.com/getwidgets?api_key=3n3B5m1N3L&q=colom&restrictBy[division_id]=5,5&restrictBy[menu_tag_ids]=3,3&maxResults=3&startIndex=0&items=true&pages=true&facets=true&categories=true&suggestions=true&pagesMaxResults=3&categoriesMaxResults=3&suggestionsMaxResults=4&query_correction=true&output=jsonp"

{"totalItems":0,"startIndex":0,"itemsPerPage":3,"currentItemCount":0,"suggestions":[],"items":[],"facets":[]}

 

 

 restrictBy[menu_tag_ids]=2,2: (2 was the first value in the update request)

> curl --globoff "http://www.searchanise.com/getwidgets?api_key=3n3B5m1N3L&q=colom&restrictBy[division_id]=5,5&restrictBy[menu_tag_ids]=2,2&maxResults=3&startIndex=0&items=true&pages=true&facets=true&categories=true&suggestions=true&pagesMaxResults=3&categoriesMaxResults=3&suggestionsMaxResults=4&query_correction=true&output=jsonp"

{"totalItems":1,"startIndex":0,"itemsPerPage":3,"currentItemCount":1,"suggestions":["colomba","colomba tradizionale"],"items":[{"product_id":"473","title":"DOLCE PASQUA - COLOMBA TRADIZIONALE  (PROBIOS)","description":"","link":"http:\/\/itmyit.odoo:8069\/shop\/product\/dolce-pasqua-colomba-tradizionale-probios-473","price":"0.0000","quantity":"0","product_code":"","image_link":"http:\/\/itmyit.odoo:8069\/website\/image\/product.template\/473_1238b6d\/image_medium"}],"facets":[]}

 

 I've tried multiple queries and filtering and all seems to validate my hypothesis that the restrictBy rule looks only at the first value of the multiple-valued attributes.

 

Thank you for your reply.


As we can see the int type is used for the menu_tag_ids attribute. There are no multiple values for attribute of such type.


We recommend to use the text type for attributes with id. For example:


<cs:attribute name="menu_tag_id" type="text">

<value>2</value>

<value>3</value>

<value>6</value>

</cs:attribute>


restrictBy[menu_tag_ids]=2,3 - the products with menu_tag_id = 2 and menu_tag_id = 3 will be found.

restrictBy[menu_tag_ids]=2|3 - the products with menu_tag_id = 2 or menu_tag_id = 3 will be found


Thank you.

Login or Signup to post a comment