free open-source SQL full-text search engine

Need a hand?
+1-888-333-1345


Sphinx

Community

Services

Misc

 Subscribe in a reader

Tracked by ClickAider

Forums :: Register :: Login :: Forgot your password? :: Search

anonymous user


Multiple queries and sorting clarification

Common forum | 1 | 2 | 3 | 4 | 5 | ... | 273 | 274 | 275 | 276 | next »» | Create new thread

r2b2

Name: Ryan Bayona
Posts: 41

2010-07-29 12:20:35 | reply!


Hello,
In my application I have several calls to AddQuery() method. I did this because there are
many indices and not all of them have the same attributes.

The RunQueries() method returns and array of results ,indexed as 0 being the first
AddQuery() call, 1 the second call and so on.

Assuming $result = $sphinx->RunQueries();

If I want to get the total number of results :

$result[0]['total_found'] + $result[1]['total_found'] and so on

Questions:

1. Do I need to combine $result[0]['matches'] and $result[1]['matches'] and sort them ?
2. If have $sphinx->setLimits(20,20) before any AddQuery() method calls, will it be
applied to all AddQuery() method calls?

Sorry for the long read..
Thanks a lot and more power Sphinx!!

barryhunter

Name: Barry Hunter
Posts: 1697

to: r2b2, 2010-07-29 13:15:50 | reply!


> 1. Do I need to combine $result[0]['matches'] and $result[1]['matches'] and sort them ?

Yes. (if you want the results combined)

> 2. If have $sphinx->setLimits(20,20) before any AddQuery() method calls, will it be
> applied to all AddQuery() method calls?

Yes.

(but you will get (upto) 20 results from each index, not just 20 results that make up
page 2 over the overall result set. )

r2b2

Name: Ryan Bayona
Posts: 41

to: barryhunter, 2010-07-29 14:13:06 | reply!


I see.. so I will end up with 40 records then.. hmnn.. since I will combine two or more
result sets and then sort them by their weights, can I just get the first 20 records. I
think Im going to have a problem with the pagination here where records 21 and below wont
be shown. Any suggestions Sir?

barryhunter

Name: Barry Hunter
Posts: 1697

to: r2b2, 2010-07-29 14:24:44 | reply!


My only suggestion is to query all the indexes in one query, then pagination can work
easily.

(ie sphinx takes care of it for you, running multiple queries, you will have to merge
results - which is far from trivial)


- you can search indexes with different schema at once (mostly) in one query.

r2b2

Name: Ryan Bayona
Posts: 41

to: barryhunter, 2010-07-30 05:13:25 | reply!


True. In fact that's what I was doing until one of the indices should be filtered with
category_id, which is only for that index.

r2b2

Name: Ryan Bayona
Posts: 41

to: barryhunter, 2010-08-06 06:34:26 | reply!


Just to share my solution on this.

Problems :

1. I need to perform search across all indices where each of the indices can have
different attributes.
2. The results will be paginated and only 20 records will be shown at a time.


Solutions:

1. Use AddQuery() method. In this way, you can loop through your indices and assign
filters to each of them. Remember to also use ResetFilters() before each AddQuery() calls.

2. Combine all search results into one multi-dimensional array and sort using PHP
array_multisort(). In this way, you can sort using different attributes.

3. As for the pagination, since we already combined and sorted the results into one
array, we can then return the items using array_slice($results,$offset,$rows_per_page).

My initial solution to this is to store all results in one table, then let MySQL handle
the sorting. But this is very slow. Remember also to increase the max_matches parameter
in your sphinx.conf and in SphinxAPI setLimits() call. In my case, I set it fetch 10,000
records from each of indices.

Thanks !

Common forum | 1 | 2 | 3 | 4 | 5 | ... | 273 | 274 | 275 | 276 | next »» | Create new thread


Copyright © Sphinx Technologies Inc, 2009