mediashowrooom/sphinxsearch-bundle

Sphinx搜索包,适用于Symfony 2

安装: 7

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 33

类型:symfony-bundle

1.2.5 2018-04-19 13:06 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:10 UTC


README

安装

  1. 下载此包
  2. 配置此包

步骤 1:下载此包

您实际上如何下载此包完全取决于您。最简单的方法是从packagist.org获取。

步骤 2:配置此包

sphinxsearch:
    indexes:
        Categories: %sphinxsearch_index_categories%
        Items:      %sphinxsearch_index_items%
    searchd:
        host:   %sphinxsearch_host%
        port:   %sphinxsearch_port%
        socket: %sphinxsearch_socket%
    indexer:
        bin:    %sphinxsearch_indexer_bin%

必须定义至少一个索引,您可以根据需要定义任意多个。

在上面的示例配置中,使用Categories作为名为%sphinxsearch_index_categories%(如您的sphinxsearch.conf中定义)的索引的标签。这允许您避免在代码中硬编码原始索引名称。

使用示例

使用上述配置作为示例,最基本的搜索可能是

$indexesToSearch = array('Items');
$sphinxSearch = $this->get('search.sphinxsearch.search');
$searchResults = $sphinxSearch->search('search query', $indexesToSearch);

这将在Items标签的索引中进行对search query的搜索。搜索结果存储在$searchResults中。

您还可以执行更复杂的搜索,例如

$indexesToSearch = array('Items');
$options = array(
  'result_offset' => 0,
  'result_limit' => 25,
  'field_weights' => array(
    'Name' => 2,
    'SKU' => 3,
  ),
);
$sphinxSearch = $this->get('search.sphinxsearch.search');
$sphinxSearch->setMatchMode(SPH_MATCH_EXTENDED2);
$sphinxSearch->setFilter('disabled', array(1), true);
$searchResults = $sphinxSearch->search('search query', $indexesToSearch, $options);

这将在Items索引中再次搜索search query,但现在它将仅返回前25个匹配项,并将NameSKU字段的权重高于正常。请注意,为了定义result_offsetresult_limit,您必须显式定义这两个值。此外,此搜索将使用扩展查询语法,并排除所有将disabled属性设置为1的结果。

许可

Copyright (c) 2012, Ryan Rogers
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.