首页 \ 问答 \ 弹性搜索模糊匹配,首先显示精确匹配(Elastic search fuzzy match with exact matches showing first)

弹性搜索模糊匹配,首先显示精确匹配(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 ...
  • 而不是使用Singleton反模式 ,只是一个全局变量,并用它来完成。 这更诚实。 Singleton的主要优点是当你想要延迟初始化时,或者比初始化顺序更精细的控制,而不是全局变量允许的。 它看起来不像这些东西中的任何一个都是你的问题,所以只需使用全局。 就个人而言,我认为全局变量或Singletons的设计几乎肯定会被破坏。 但是对每个h(是/ er)拥有。 如果您倾向于使用Singleton,那么您提出的性能问题很有意思,但可能不是问题,因为函数调用开销可能小于100ns。 正如已经指出的那样,你应该分 ...
  • 您发布的课程似乎不是您的单身课程。 该代码会更有帮助。 无论如何,是的,如果计时器超出范围并且被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 ...
  • 有什么方法可以通过更改代码来添加扩展属性,并且不会更改配置文件。 有一个${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(); } ...
  • 开发存储使用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.)
  • 我个人总是创建一个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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。