弹性搜索模糊匹配,首先显示精确匹配(Elastic search fuzzy match with exact matches showing first)
我想在查询中使用模糊匹配,但在结果的顶部显示完全匹配。
我尝试了以下内容。
$return = $this->_client->search( array( 'index' => self::INDEX, 'type' => self::TYPE, 'body' => array( 'query' => array( 'bool' => array( 'must' => array( 'multi_match' => array( 'query' => $query, 'fields' => array('name', 'brand', 'description'), 'boost' => 10, ), 'fuzzy_like_this' => array( 'like_text' => $query, 'fields' => array('name', 'brand', 'description'), 'fuzziness' => 1, ), ), ), ), 'size' => '5000', ), ) );
由于格式错误的查询错误,这不起作用。
有任何想法吗?
I am wanting to use fuzzy matching on a query but with exact matches showing at the top of the results.
I've tried the following.
$return = $this->_client->search( array( 'index' => self::INDEX, 'type' => self::TYPE, 'body' => array( 'query' => array( 'bool' => array( 'must' => array( 'multi_match' => array( 'query' => $query, 'fields' => array('name', 'brand', 'description'), 'boost' => 10, ), 'fuzzy_like_this' => array( 'like_text' => $query, 'fields' => array('name', 'brand', 'description'), 'fuzziness' => 1, ), ), ), ), 'size' => '5000', ), ) );
This doesn't work due a malformed query error.
Any ideas?
原文:https://stackoverflow.com/questions/24528933
更新时间:2022-06-08 15:06
最满意答案
您根本不需要使用静态变量,
<?php Class Base{ public $Config; } Class System Extends Base{ Public static $obj = null; Public static Function HelloWorld() { if (!System::$obj) System::$obj = new System(); // call the object functions // $obj->HelloWorld(); } Public Function __Construct() { $this->Config = 2; } } Class Core Extends Base{ Public Function __Construct() { $this->Config = 3; } } ?>
You don't need to use static variable at all,
<?php Class Base{ public $Config; } Class System Extends Base{ Public static $obj = null; Public static Function HelloWorld() { if (!System::$obj) System::$obj = new System(); // call the object functions // $obj->HelloWorld(); } Public Function __Construct() { $this->Config = 2; } } Class Core Extends Base{ Public Function __Construct() { $this->Config = 3; } } ?>
相关问答
更多-
当你构造函数调用load()时,Autowired依赖关系仍然没有连线。 接线在构造器完成后进行。 可以使configService为final,并使用构造函数自动装配或从构造函数中移除load(),但使用@PostConstruct注释load()。 When you constructor calls load() the Autowired dependencies are still unwired. The wiring takes place after the constructor has ...
-
我将在非常高的层次上解释这一点,但是一种方法是将GetStates()逻辑重定位到它自己的类 - 即StateRepository或类似的东西。 也许您围绕这个“存储库”概念构建了几个接口: public interface IRepository
where TEntity : class { IEnumerable All(); } public interface IStateRepository : IRepository { IE ... -
静态对象和单例(Static objects and singletons)[2023-02-21]
而不是使用Singleton反模式 ,只是一个全局变量,并用它来完成。 这更诚实。 Singleton的主要优点是当你想要延迟初始化时,或者比初始化顺序更精细的控制,而不是全局变量允许的。 它看起来不像这些东西中的任何一个都是你的问题,所以只需使用全局。 就个人而言,我认为全局变量或Singletons的设计几乎肯定会被破坏。 但是对每个h(是/ er)拥有。 如果您倾向于使用Singleton,那么您提出的性能问题很有意思,但可能不是问题,因为函数调用开销可能小于100ns。 正如已经指出的那样,你应该分 ... -
线程和单身(Threading and Singletons)[2022-11-01]
您发布的课程似乎不是您的单身课程。 该代码会更有帮助。 无论如何,是的,如果计时器超出范围并且被GC'ed,那么它将停止发射事件。 更有可能的是,调度程序立即超出了范围,并且发生时间和GC发生之间只有一段延迟。 发布你的单身代码可以让我或其他人给出更具体的答案。 编辑 鉴于单身人士课程的简单性,跳出我的唯一潜在问题是Current属性上的竞争条件。 假设你没有锁定任何东西,那么当两个线程同时访问Current属性时,它们可能会以不同的引用结束,而最后一个被设置的线程将是唯一一个引用的范围将会扩展的引用超出了 ... -
根据Cocoa内存管理约定, new -prefixed方法等同于alloc + init对。 静态分析器假设您的newGroup方法返回一个具有+1保留计数的对象,而不是自动释放的对象。 重命名方法(例如, group或makeGroup ),或者如果无法更改名称,请添加NS_RETURNS_NOT_RETAINED属性 。 new-prefixed methods are equivalent to an alloc+init pair according to Cocoa memory managem ...
-
NLog中的扩展属性(Extended properties in NLog)[2023-08-14]
有什么方法可以通过更改代码来添加扩展属性,并且不会更改配置文件。 有一个${all-event-properties}渲染器 ,它有多个参数如何渲染。 Is there any way, through which I can add extended properties only by changing code, and no change in config file. There is a ${all-event-properties} renderer and it has multiple p ... -
您根本不需要使用静态变量, HelloWorld(); } ...
-
Windows Azure表服务 - 扩展属性和表架构(Windows Azure Table Services - Extended Properties and Table Schema)[2023-03-29]
开发存储使用SQL Express来模拟云表存储。 忽略你在那里看到的......生产存储系统不存储任何模式,因此在表中拥有大量独特属性没有任何开销。 Development storage uses SQL Express to simulate cloud table storage. Ignore what you see there... the production storage system doesn't store any schema, so there's no overhead to ... -
静态方法遵循“低耦合和高相干”的规则 - 比单身更多。 (只要它们的实现不依赖于静态成员变量。) Static methods follow the "low coupling and high coherence"-rule more than singletons do. (As long as their implementations don't rely on static member variables.)
-
单例类中“静态最终记录器”字段背后的任何原因?(Any reason behind “static final Logger” field in singletons classes?)[2022-03-13]
我个人总是创建一个private static final Logger LOGGER = LogManager.getLogger(); 作为我创建的任何类的第一行(Spring bean,DAO,内部类,域对象等)。 LogManager充当我的各个Logger对象的工厂: https://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/LogManager.html 我非常关注这一点,以至于我在Eclips ...