开发者

Sphinx search within attribute collection

Is there a way of searching in Sphinx with开发者_如何学运维in a collection of attributes?

I've got a property (as in building, not attribute) which among other attributes, has a collection of facilities, e.g. pool, wifi.

Each property has multiple facilities


Figured it out, you have to use "multi" attribute, see attached xmlpipe2 doc + php search example

<?xml version="1.0" encoding="UTF-8"?>
<sphinx:docset>
 <sphinx:schema>
  <sphinx:field name="capacity"/>
  <sphinx:field name="region"/>
  <sphinx:field name="facilities"/>
  <sphinx:attr name="capacity" type="int"/>
  <sphinx:attr name="region" type="int"/>
  <sphinx:attr name="facilities" type="multi"/>
 </sphinx:schema>
 <sphinx:document id="94">
  <capacity>37</capacity>
  <region>12</region>
   <facilities>
   <attr>23</attr>
   <attr>5</attr>
   <attr>2</attr>
   <attr>1</attr>
  </facilities>
 </sphinx:document>
</sphinx:docset>

PHP search:

$sp = new SphinxClient();
$sp->SetMatchMode(SPH_MATCH_ALL);
$sp->SetArrayResult(true);
$sp->SetServer('localhost', 3312);
$sp->SetFilter('facilities', array(23, 5));
$sp->Query();


For this case, it is better to use Multi value attributes.

sql_attr_multi = uint facilities from query; \
SELECT id, facility_id FROM facilities

In the application:

$cl->SetFilter('facilities', array(1, 2, 3));
$cl->Query();

But, you can avoid using MVA attributes. Simply concat each facility in SQL query:

sql_query = select group_concat(facilities SEPARATOR ' ') as facilties \
from building b inner join facilities f on (b.facility_id = f.id)

In the application:

$cl->Query("@facilities pool");


In my case declaring MVA attributes as:

<facilities>
   <attr>23</attr>
   <attr>5</attr>
   <attr>2</attr>
   <attr>1</attr>
</facilities>

didn't work. But when I make it like:

<facilities>23,5,2,1</facilities>

...it works!;)

(Sphinx 2.0.6-id64-release (r3473))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜