E commerce 如何扩展Shopware 6搜索,使其能够按自定义字段、制造商名称、产品id等进行搜索?

E commerce 如何扩展Shopware 6搜索,使其能够按自定义字段、制造商名称、产品id等进行搜索?,e-commerce,shopware,subscriber,E Commerce,Shopware,Subscriber,当前的Shopware 6搜索没有搜索所有产品属性 如何更改它,以便按自定义字段、属性、ean等进行搜索 我试图创建ProductSuggestResultEvent的订阅服务器,但没有结果。您应该在src/Resources/config/services.xml中装饰Shopware\Core\Content\Product\SearchKeyword\ProductSearchKeywordAnalyzer 在您自己的分析器中,您可以通过执行父函数获得原始响应: 类CustomAnal

当前的Shopware 6搜索没有搜索所有产品属性

如何更改它,以便按自定义字段、属性、ean等进行搜索


我试图创建ProductSuggestResultEvent的订阅服务器,但没有结果。

您应该在
src/Resources/config/services.xml
中装饰
Shopware\Core\Content\Product\SearchKeyword\ProductSearchKeywordAnalyzer


在您自己的分析器中,您可以通过执行父函数获得原始响应:

类CustomAnalyzer实现ProductSearchKeywordAnalyzer接口{
[...]
公共函数分析(ProductEntity$product,Context$Context):AnalyzedKeywordCollection{
$keywords=$this->originalService->analyze($product,$context);
[...]
}
}

如果您想添加其他实体,您可以通过在
services.xml
中定义这些实体来实现。正如您所说,我实现了ProductSearchKeyWordAnalyzer接口。在构造函数中,我使用了相同的类公共函数uu构造(ProductSearchKeywordAnalyzerInterface$ProductSearchKeywordAnalyzerInterface){$this->originalService=$ProductSearchKeywordAnalyzerInterface;}然后我尝试添加自定义字段。这是正确的方向吗?公共函数分析(ProductEntity$product,Context$Context):AnalyzedKeywordCollection{$keywords=$this->originalService->Analysis($product,$Context);if($product->getCustomFields()){$customFields=$product->getCustomFields();foreach($customFields as$customField){$keywords->add(newanalyzedkeyword($customField,500));}}返回$keywords;}这是正确的方法。即使您应该检查$customField是哪种类型。自定义字段也可以是开关或关联Id。AnalyzedKeyword只需要字符串。您可以(但不应该)将所有$customFields强制转换为字符串,或检查其后面的类型/值。如果您想添加相关值,如
标记
或类似内容,则需要在productRepository中搜索添加了关联的产品。由
analyze
函数注入的
ProductEntity
只包含一些基本数据。我尝试使用ProductEntity的默认get方法,但没有任何结果。这就是我所做的$关键词=$this->originalService->analyze($product,$context);if($product->getWeight()){$keywords->add(新分析关键字(strval($product->getWeight()),500));}