qiita-elasticsearch 0.14.1 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e852197dfad43b0c2230341419e69f091f689ddd
4
- data.tar.gz: 8ddb459eff2ee0089d157c11768f819f6e898705
3
+ metadata.gz: ae5f80e83a36a13265613558a8c0ac97e8723850
4
+ data.tar.gz: a2ec7213540de6dda2a2e5004cffa09bd5eccc68
5
5
  SHA512:
6
- metadata.gz: 1ad2bf864ecf37539f5f0f9a0ce090783d2dc4def9b048d77225685b118d14708421cc394abf6e8979d9d8396f5ec770189b4d65e1e3165cdb089181139309fd
7
- data.tar.gz: a20121e19b23be7149e2f473d403358b2448b29d076fdd2dcba23f5a30027e2bf75cdcac35db8e119ae9964053cec11e4b2812666b5a1f52f09a661fef035803
6
+ metadata.gz: fc9aa9b37c7bf0b96f95fdff0d985c4020cf15c510e4c0036496de00e40ad71c8d889c59d33f9605a3139a897a0dbc6a0d549612effac1cb2682212a285849b2
7
+ data.tar.gz: 4e95b016526f3144eb336fe04f8d4fc275aeecd992338ad863f4a6c677e4fbebef7b65c31b4d15eabab7eba59a822fb7f0181837b78c113e8f840737498c52df
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.14.2
2
+ - Combine phrase and best_fields queries for unquoted matchable token
3
+
1
4
  ## 0.14.1
2
5
  - Nest match query with "query" property in must not
3
6
 
@@ -3,27 +3,39 @@ require "qiita/elasticsearch/token"
3
3
  module Qiita
4
4
  module Elasticsearch
5
5
  class MatchableToken < Token
6
+ RELATIVE_BEST_FIELDS_QUERY_WEIGHT = 0.5
7
+
6
8
  attr_writer :matchable_fields
7
9
 
8
10
  # @return [Hash]
9
11
  def to_hash
10
- if @matchable_fields.nil?
11
- {
12
- quoted? ? "match_phrase" : "match" => {
13
- "_all" => @term,
14
- }
15
- }
12
+ if quoted?
13
+ build_multi_match_query(type: "phrase")
16
14
  else
17
- hash = {
18
- "multi_match" => {
19
- "fields" => @matchable_fields,
20
- "query" => @term,
15
+ {
16
+ "bool" => {
17
+ "should" => [
18
+ build_multi_match_query(type: "phrase"),
19
+ build_multi_match_query(type: "best_fields", boost: RELATIVE_BEST_FIELDS_QUERY_WEIGHT),
20
+ ],
21
21
  },
22
22
  }
23
- hash["multi_match"]["type"] = "phrase" if quoted?
24
- hash
25
23
  end
26
24
  end
25
+
26
+ private
27
+
28
+ # @return [Hash]
29
+ def build_multi_match_query(type: nil, boost: 1)
30
+ {
31
+ "multi_match" => {
32
+ "boost" => boost,
33
+ "fields" => @matchable_fields || ["_all"],
34
+ "query" => @term,
35
+ "type" => type,
36
+ },
37
+ }
38
+ end
27
39
  end
28
40
  end
29
41
  end
@@ -1,5 +1,5 @@
1
1
  module Qiita
2
2
  module Elasticsearch
3
- VERSION = "0.14.1"
3
+ VERSION = "0.14.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-21 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
- rubygems_version: 2.4.5
156
+ rubygems_version: 2.2.2
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: Elasticsearch client helper for Qiita.