Add to composer.json:
"require": {
// ...,
"vtdesignworks/sphinx-search-bundle": "~1.3.1" // or latest stable
}Install:
composer update vtdesignworks/sphinx-search-bundleAdd add to app/AppKernel.php:
$bundles = array(
// ...,
new Vdw\SphinxSearchBundle\SphinxSearchBundle(),
);# app/config/config.yml
sphinxsearch:
indexes:
Entity: index_name_from_sphinx_conf
searchd:
host: %sphinx_search_host%
port: %sphinx_search_port%
socket: %sphinx_search_socket%
indexer:
bin: %sphinx_search_indexer_bin%At least one index must be defined, and you may define as many as you like.
In the above sample configuration, Entity is used as a label for the index named index_name_from_sphinx_conf (as defined in sphinx/etc/sphinx.conf).
The most basic search, using the above configuration as an example, would be:
$indexesToSearch = array('Entity');
$sphinxSearch = $this->get('vdw.sphinx_search.search');
$searchResults = $sphinxSearch->search('search query (or keywords)', $indexesToSearch);This performs a search for search query or keywords against the index labeled Entity. The results of the search are stored in $searchResults.
You can also perform more advanced searches, such as:
$indexesToSearch = array('Entity');
$options = array(
'result_offset' => 0,
'result_limit' => 25, // use 100000+ for 'no limit'
'field_weights' => array(
'Name' => 2,
'SKU' => 3,
),
);
$sphinxSearch = $this->get('vdw.sphinx_search.search');
$sphinxSearch->setFilter('disabled', array(1), true);
$searchResults = $sphinxSearch->search('search query (or keywords)', $indexesToSearch, $options);This would again search Entity for search query or keywords, but now it will only return up to the first 25 matches and weight the Name and SKU fields higher than normal. Note that in order to define a result_offset or a result_limit, you must explicitly define both values and pass them in options as an associative array. Also, this search will use the Extended query syntax, and exclude all results with a disabled attribute set to 1.
Copyright (c) 2012, Ryan Rogers
Copyright (c) 2014, Vermont Design Works
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.