T
T
tutnet2014-07-04 12:24:44
MySQL
tutnet, 2014-07-04 12:24:44

How to merge the result of multiple SphinxQL queries, grouped by key?

On the Russian forum of the sphinx, the question hung for two weeks without an answer. I'll try to ask here.
There are two requests:

SELECT *, (10*weight()) AS qweight FROM elverIndex WHERE MATCH('ZONESPAN:(h1,h2)
ТоЧтоЯИщу') LIMIT 0,1000

and
SELECT *, (5*weight()) AS qweight FROM elverIndex WHERE MATCH('ZONESPAN:(h3,h4)
ТоЧтоЯИщу') LIMIT 0,1000

Separately, they work correctly. I need to combine their result in one query
with grouping by id_attr field, summing qweight and sorting in descending order of
total weight.
I do:
SELECT *, tweight AS SUM(`qweight`) FROM (SELECT *, (10*weight()) AS qweight FROM
elverIndex WHERE MATCH('ZONESPAN:(h1,h2) ТоЧтоЯИщу') LIMIT 0,1000 UNION SELECT *,
(5*weight()) AS qweight FROM elverIndex WHERE MATCH('ZONESPAN:(h3,h4) ТоЧтоЯИщу') LIMIT
0,1000) t GROUP BY `id_attr` ORDER BY `tweight` DESC LIMIT 0,1000;

At the output I get
ERROR 1064 (42000): sphinxql: syntax error, unexpected '(', expecting FROM or ',' near
'(`qweight`) FROM (SELECT *, (10*weight()).......

The question of what I'm doing wrong, in general, is not worth it (the obvious answer is everything). The question is how
to do it right or at least where to read about how to do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
whats, 2014-07-04
@whats

tweight AS SUM(`qweight`)

D
Denis, 2014-07-04
Baydarov @4er

SphinxQL does not know how to work with subqueries. I myself faced a similar problem, I had to implement 2 separate requests, and then process them manually.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question