Вопрос

I'm using Sphinx PHP API, but the methods provided seems to be simple, a single select and single index, but how to build a query that involves a join of 2 indices? for example something like

select * from index1,index2 where index1.key1=index2.key2;

below are the key methods from Sphinx API Client:

$cl->SetServer ( $host, $port );
$cl->SetConnectTimeout ( 1 );
$cl->SetArrayResult ( true );
$cl->SetWeights ( array ( 100, 1 ) );
$cl->SetMatchMode ( $mode );
if ( count($filtervals) )   $cl->SetFilter ( $filter, $filtervals );
if ( $groupby )             $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );
if ( $sortby )              $cl->SetSortMode ( SPH_SORT_EXTENDED, $sortby );
if ( $sortexpr )            $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
if ( $distinct )            $cl->SetGroupDistinct ( $distinct );
if ( $select )              $cl->SetSelect ( $select );
if ( $limit )               $cl->SetLimits ( 0, $limit, ( $limit>1000 ) ? $limit : 1000 );
$cl->SetRankingMode ( $ranker );
$res = $cl->Query ( $q, $index );
Это было полезно?

Решение

Sphinx does not support 'joins'

You can search multiple indexes at once via way of 'UNION', ie search each index in turn and append the results (and get results using an overall sort order).

But one row in the result set will always be from one index.

(remember sphinx is a full text query engine, NOT a relational database engine, even though it does provide a SQL like query language - just because its a familiar concept )

Другие советы

Even it's make a lot of row, you can create an index joining datas of source use in index 1 & 2 (but remember you need have a unique id on first col)

and so have all data in one index.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top