有没有办法在一组属性中搜索Sphinx?
我有一个属性(如在building,not attribute中),除了其他属性之外,还有一个设施集合,例如游泳池,wifi。
每个物业都有多个设施
答案 0 :(得分:5)
<?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搜索:
$sp = new SphinxClient();
$sp->SetMatchMode(SPH_MATCH_ALL);
$sp->SetArrayResult(true);
$sp->SetServer('localhost', 3312);
$sp->SetFilter('facilities', array(23, 5));
$sp->Query();
答案 1 :(得分:1)
对于这种情况,最好使用Multi value attributes。
sql_attr_multi = uint facilities from query; \
SELECT id, facility_id FROM facilities
在申请中:
$cl->SetFilter('facilities', array(1, 2, 3));
$cl->Query();
但是,您可以避免使用MVA属性。只需在SQL查询中连接每个工具:
sql_query = select group_concat(facilities SEPARATOR ' ') as facilties \
from building b inner join facilities f on (b.facility_id = f.id)
在申请中:
$cl->Query("@facilities pool");
答案 2 :(得分:1)
在我的案例中,将MVA属性声明为:
<facilities>
<attr>23</attr>
<attr>5</attr>
<attr>2</attr>
<attr>1</attr>
</facilities>
没用。但是,当我这样做时:
<facilities>23,5,2,1</facilities>
......它有效!;)
(Sphinx 2.0.6-id64-release(r3473))