I
I
Igor Yatsevich2014-01-14 14:11:25
Sphinx
Igor Yatsevich, 2014-01-14 14:11:25

How to get the value of the attribute specified in the select parameter in SphinxQL?

There is a query that searches for all groups of products that satisfy the search query

select
  *

from
  SearchCatalog
  
where
  SearchCatalog.`query` = 'рюшь рюшь*;groupby=attr:rubric_id;select=*, @count as items_count_all;limit=100'

if you use the select parameter, as for example I have
select=*, @count as items_count;
then the question arises - how then to take the result from the specified column items_count?
If you refer to a non-existent field in the table - an error. If you create such a field, then it remains empty when the request is executed.
Has anyone experienced something similar?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Yatsevich, 2014-01-15
@IgoNsk

I'll add a little.
via Sphinx php API this is done like this (sphinx version - 2.0.8 - linux):

$sphinx_obj->SetGroupBy("rubric_id", SPH_GROUPBY_ATTR, "@count desc");
    $sphinx_obj->SetLimits(0, 100, 100);
    $sphinx_obj->SetSelect('rubric_id, @count as items_count');
    $search_res = $sphinx_obj->Query($query, 'catalog_index');

and this result:
[6345248] => Array
  (
    [weight] => 1
    [attrs] => Array
      (
        [rubric_id] => 3763337
        [@count] => 5
      )
  )
[3465352] => Array
  (
    [weight] => 1
    [attrs] => Array
      (
        [rubric_id] => 3756960
        [@count] => 2
      )
  )

Ideally achieve the same through SphinxQL

K
kshmatov, 2014-01-15
@kshmatov

No need to mix approaches.
select rubric_id, count(*) as cnt from SearchCatalog where match('ruch quill*') group by rubric_id sort by cnt desc limit 100
Everything is quite banal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question