sylius / search-bundle
您的 Symfony2 应用程序的产品目录。
Requires
- php: ^5.6|^7.0
- doctrine/orm: ^2.4.8,<2.5
- friendsofsymfony/elastica-bundle: ~3.0.2
- sylius/channel: ^0.19
- sylius/product-bundle: ^0.19
- sylius/resource-bundle: ^0.19
- symfony/framework-bundle: ^2.8
- symfony/property-access: ^2.8
- twig/twig: ~1.11
Requires (Dev)
- phpspec/phpspec: ^2.4
- sylius/taxonomy: ^0.19
This package is not auto-updated.
Last update: 2020-01-24 15:45:29 UTC
README
为 Symfony2 应用程序提供搜索系统。
它支持 mysql 和 elastic search 的搜索功能。
用法
将以下代码片段放在 twig 视图中,即可使用。
{% render controller('SyliusSearchBundle:Search:form', {'request':app.request}) %} {% include 'SyliusSearchBundle::filter_form.html.twig' %}
如果您想以实用方式使用搜索,目前有两种查询类型:字符串查询和分类查询。
$finder = $this->get('sylius_search.finder') ->setTargetIndex('product') // target index searches in a specific type, if it's not set it searches in all types ->setFacetGroup('search_set') // configuration based, uses the relevant facet set, if not set it does not show facets ->find(new SearchStringQuery(...));
分类
$finder = $this->get('sylius_search.finder') ->setFacetGroup('categories_set') ->find(new TaxonQuery(...));
基本配置指南
表单
form: 'SyliusSearchBundle::form.html.twig'
您想要用于执行搜索的实际表单。只要元素命名相同,您就可以定义一个带有自定义设计的新的 twig 文件。
请求方法
搜索和过滤器表单的默认值都是 GET,但您可以在配置中添加以下片段来使用 POST。
request_method: POST
引擎
engine: orm
可能的值:orm, elasticsearch
如果选择 orm,则搜索使用 mysql 作为引擎;如果选择 elasticsearch,则使用 elastic search 搜索引擎,它必须通过 fos_elastica 包进行配置。有关 fos_elastica 的文档,请参阅 fos_elastica github 页面。
查询日志记录器
默认情况下,查询日志记录器是禁用的。
如果您想使用它,需要添加以下配置参数。查询日志记录器目前支持 orm 用于小型网站,以及 elasticsearch 用于具有更高交易量的网站。将来我们需要引入队列支持。
query_logger: enabled: true engine: orm
索引
orm_indexes: # it is being used only when orm is selected as a driver product: # indentifier of an index class: Sylius\Component\Core\Model\Product # the corresponding model mappings: # appart from the id, the rest of the fields will be used to compile the searchable content id: ~ name: ~ description: ~
如果选择 elasticsearch,以下是一个示例配置
fos_elastica: clients: elasticsearch: servers: - { host: 10.0.0.100, port: 9200, logger: true } - { host: 10.0.0.101, port: 9200, logger: true } #for clustering you need to define the logger because of the https://github.com/FriendsOfSymfony/FOSElasticaBundle/issues/543 indexes: sylius: client: elasticsearch finder: ~ settings: analysis: filter: synonym: type: synonym synonyms: synonym.txt analyzer: my_analyzer: filter: synonym type: standard tokenizer: standard types: product: mappings: id: { type: integer, index: not_analyzed } name: { type: string, analyzer: my_analyzer } description: { type: string } price: { type: integer } shortDescription: { type: string } slug: { type: string, index: not_analyzed } translations: type: nested properties: locale: { type: string, index: not_analyzed } name: { type: string } metaKeywords: { type: string } metaDescription: { type: string } variants: type: nested properties: code: { type: string } availableOn: { type: date, index: not_analyzed } availableUntil: { type: date } name: { type: string } onHand: { type: integer, index: not_analyzed } onHold: { type: integer, index: not_analyzed } attributes: type: nested properties: value: { type: string } channels: { type: string, index: not_analyzed } taxons: { type: string, index: not_analyzed } enabled: { type: boolean } persistence: driver: orm model: Sylius\Component\Core\Model\Product model_to_elastica_transformer: service: sylius.search.transformers.model.product provider: ~ listener: ~ finder: ~ search_log: mappings: search_term: ~ ip_address: ~
过滤器
filters: search_filter: # the small drop down menu on the side of the search field enabled: true taxon: category # possible values are taxons codes (category, brand for sylius) facet_groups: # possible facet groups, you assign them in a finder object search_set: values: [taxons, price, made_of, color] categories_set: values: [price, made_of, color] all_set: values: [taxons, price, made_of] facets: # possible facets, as long as a model exposes attributes, options or getters with the given name, it will be used as a facet taxons: display_name: 'Basic categories' type: terms value: ~ price: display_name: 'Available prices' type: range values: - { from: 0, to: 2000} - { from: 2001, to: 5000} - { from: 5001, to: 10000} made_of: display_name: 'Material' type: terms value: ~ color: display_name: 'Available colors' type: terms value: ~
索引数据
配置索引器后,执行以下命令以填充适当的引擎
app/console sylius:search:index
Sylius
Sylius - 为 Symfony2 提供的现代电子商务。访问 Sylius.org。
phpspec 示例
$ composer install $ bin/phpspec run -fpretty
behat 为搜索包提供的示例
$ composer install $ /bin/behat --suite=search
文档
文档可在 docs.sylius.org 上找到。
贡献
有关向 Sylius 贡献的所有信息,请参阅 此页面。
邮件列表
用户
有问题?请随时在用户邮件列表上提问。
开发者
要贡献和开发此包,请使用开发者邮件列表。
Sylius推特账号
如果您想了解更新,请关注Sylius官方推特账号。
错误跟踪
此包使用GitHub问题。如果您发现了错误,请创建一个问题。
版本控制
版本号将按照格式主.次.补丁
进行编号。
以下是一些指导原则。
- 破坏向后兼容性将增加主版本号。
- 没有破坏向后兼容性的新功能将增加次版本号。
- 错误修复和杂项更改将增加补丁版本号。
有关SemVer的更多信息,请访问semver.org网站。此版本控制方法适用于所有Sylius包和应用程序。
MIT许可证
许可证可以在这里找到。
作者
此包最初由Argyrios Gounaris创建。查看贡献者列表。