Skip to content

Conversation

@chrisapl
Copy link

Sorry, had wrong commits attached to previous pull...

I have changed the search function to match the intended SphinxAPI behavior.

Previously when you searched multiple indexes with:
$indexes = array(
'All_Items' => array(
'result_offset' => 0,
'result_limit' => 1000
),
'All_Items_Delta' => array(
'result_offset' => 0,
'result_limit' => 1000
)
);

$result = $sphinxsearch->search($search_str,$indexes);
It executed SphinxAPI->query() once for each index and saved the results to a named array. This means advanced functionality like kill-lists do not work.

I have changed it so it now executes SphinxAPI->query() once with both indexes and my kill-list now works as intended which means I can have a delta index of updates and a full index but, not have results from the full index returned if that document exists in delta index (the delta being the latest version).

If someone wanted to execute a search on two different indexes independently I would expect they run SphinxSearchBundle->search() twice.

Anyhow fix my problem, not sure if you want to include it in the bundle.

Additionally I changed the sphinxsearch.xml so that bundle worked when installed to vendors/bundles/Search/SphinxSearch/ which I think would be the conventional location for the 3rd party bundle in the Symfony2 framework.

Cheers for all your hard work, made it much easier for me to integrate Sphinx and Symfony2 thats for sure!

@timewasted
Copy link
Owner

I've been thinking about this lately. I agree that the current implementation of search() isn't ideal. It fits how I had originally planned on using the bundle, but I never actually ended up using it that way.

The problem that I have with changing how it works is how the query options are passed in. The readme has the following example:

$indexesToSearch = array(
  'Items' => array(
    'result_offset' => 0,
    'result_limit' => 25,
    'field_weights' => array(
      'Name' => 2,
      'SKU' => 3,
    ),
  ),
  'Categories' => array(
    'result_offset' => 0,
    'result_limit' => 10,
  ),
);
$sphinxSearch = $this->get('search.sphinxsearch.search');
$searchResults = $sphinxSearch->search('search query', $indexesToSearch);

That works, because each listed index is queried independently of the other indexes. If search() was changed to perform one query using multiple indexes, result_limit would initially be set to 25, then get changed to 10 before the query is executed.

I think the best solution would be to specify the options for the query, as opposed to for each index. Something like this:

$indexesToSearch = array(
  'Items',
  'Categories',
);
$queryOptions = array(
  'result_offset' => 0,
  'result_limit' => 25,
);
$sphinxSearch = $this->get('search.sphinxsearch.search');
$searchResults = $sphinxSearch->search('search query', $indexesToSearch, $queryOptions);

Any thoughts?

@chrisapl
Copy link
Author

chrisapl commented Nov 7, 2012

I agree with the above, passing options for the query makes sense. My orignal fix was more intended to get me past a problem more than be an absolutely perfect solution.

Happy to help out implementing this if you like.

Ps thanks for creating this bundle in the first place. Save me lots of time integrating sphinx with our Symfony2 based apps.

@catalinux catalinux mentioned this pull request Nov 27, 2012
@bassrock
Copy link

+1 for pull request

@chrisapl
Copy link
Author

I have add another commit to this pull which adds more advanced api calls the bundle in addQuery, resetAllFilters, and runQueries.

This allows you to setup a batch of queries with different filters and pass them all to searchd at once to be run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants