stretcher 1.20.0.beta2 → 1.20.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stretcher/index_type.rb +11 -0
- data/lib/stretcher/search_results.rb +15 -10
- data/lib/stretcher/version.rb +1 -1
- data/spec/lib/stretcher_index_type_spec.rb +30 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fe7e6ae86720732abdf939c6632e6c025244ae0
|
4
|
+
data.tar.gz: 715e7729054c64b798914cb05a3d1364af9dfc23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a89263f5d9a591a5b798b04333726b5c8af8174ff3a5f68ea155fe4c881d3b1f01a8fddc91ec0dfa8eac295e1461b6a41cb0b1a4d80a60f1a3969761a6aaf992
|
7
|
+
data.tar.gz: 0a40d4f3f45ab830efe603fd50145ad4439222fe91452060b93eee3fe222fced761df86a5f2743e09540c8091ce65f2c4ec4ca71ee59c4e4e791079ea870b10e
|
data/lib/stretcher/index_type.rb
CHANGED
@@ -73,9 +73,20 @@ module Stretcher
|
|
73
73
|
false
|
74
74
|
end
|
75
75
|
|
76
|
+
# Takes a document and percolates it
|
76
77
|
def percolate(document = {})
|
77
78
|
request :get, '_percolate', nil, {:doc => document}
|
78
79
|
end
|
80
|
+
|
81
|
+
# Runs an MLT query based on the document's content.
|
82
|
+
# This is actually a search, so a Stretcher::SearchResults object is returned
|
83
|
+
#
|
84
|
+
# Equivalent to hitting /index/type/id/_mlt
|
85
|
+
# See http://www.elasticsearch.org/guide/reference/api/more-like-this/ for more
|
86
|
+
# Takens an options hash as a second argument, for things like fields=
|
87
|
+
def mlt(id, options={})
|
88
|
+
SearchResults.new(request(:get, "#{id}/_mlt", options))
|
89
|
+
end
|
79
90
|
|
80
91
|
# Retrieve the mapping for this type
|
81
92
|
def get_mapping
|
@@ -13,6 +13,8 @@ module Stretcher
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Returns a plain (string keyed) hash of the raw response
|
16
|
+
# Normally stretcher deals in Hashie::Mash-ified versions of data
|
17
|
+
# If you have truly gigantic result sets this may matter.
|
16
18
|
def raw_plain
|
17
19
|
@raw_plain
|
18
20
|
end
|
@@ -27,17 +29,14 @@ module Stretcher
|
|
27
29
|
@total ||= raw_plain['hits']['total']
|
28
30
|
end
|
29
31
|
|
32
|
+
# Returns the facet data from elasticsearch
|
33
|
+
# Equivalent to raw[:facets]
|
30
34
|
def facets
|
31
35
|
@facets ||= raw[:facets]
|
32
36
|
end
|
33
|
-
|
34
|
-
# DEPRECATED!
|
35
|
-
# Call #documents instead!
|
36
|
-
def results
|
37
|
-
documents
|
38
|
-
end
|
39
37
|
|
40
38
|
# Returns a 'prettier' version of elasticsearch results
|
39
|
+
# Also aliased as +docs+
|
41
40
|
# This will:
|
42
41
|
#
|
43
42
|
# 1. Return either '_source' or 'fields' as the base of the result
|
@@ -53,6 +52,13 @@ module Stretcher
|
|
53
52
|
doc
|
54
53
|
end
|
55
54
|
end
|
55
|
+
alias_method :docs, :documents
|
56
|
+
|
57
|
+
# DEPRECATED!
|
58
|
+
# Call #documents instead!
|
59
|
+
def results
|
60
|
+
documents
|
61
|
+
end
|
56
62
|
|
57
63
|
private
|
58
64
|
|
@@ -72,16 +78,15 @@ module Stretcher
|
|
72
78
|
def copy_underscores(hit, doc)
|
73
79
|
# Copy underscore keys into the document
|
74
80
|
hit.each do |k,v|
|
75
|
-
if k && k[0] == "_"
|
76
|
-
doc[k] = v
|
77
|
-
end
|
81
|
+
doc[k] = v if k && k[0] == "_"
|
78
82
|
end
|
83
|
+
|
79
84
|
doc
|
80
85
|
end
|
81
86
|
|
82
87
|
def copy_highlight(hit, doc)
|
83
88
|
if highlight = hit.key?("highlight")
|
84
|
-
doc[:_highlight] = highlight
|
89
|
+
doc[:_highlight] = highlight
|
85
90
|
end
|
86
91
|
doc
|
87
92
|
end
|
data/lib/stretcher/version.rb
CHANGED
@@ -17,7 +17,11 @@ describe Stretcher::IndexType do
|
|
17
17
|
before do
|
18
18
|
type.delete_query(:match_all => {})
|
19
19
|
index.refresh
|
20
|
-
type.put_mapping({"bar" => {
|
20
|
+
type.put_mapping({"bar" => {
|
21
|
+
"properties" => {
|
22
|
+
"message" => {"type" => "string", analyzer: "snowball"},
|
23
|
+
"username" => {"type" => "string"}
|
24
|
+
}}})
|
21
25
|
end
|
22
26
|
|
23
27
|
describe "searching" do
|
@@ -50,6 +54,31 @@ describe Stretcher::IndexType do
|
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
57
|
+
describe "document based mlt_searches" do
|
58
|
+
let(:doc_one) {{message: "I just saw Death Wish I with charles bronson!", :_timestamp => 1366420402}}
|
59
|
+
let(:doc_two) {{message: "Death Wish II was even better!", :_timestamp => 1366420403}}
|
60
|
+
let(:doc_three) {{message: "Death Wish III was even better, making it the best!", :_timestamp => 1366420403}}
|
61
|
+
|
62
|
+
before do
|
63
|
+
type.put(1, doc_one)
|
64
|
+
type.put(2, doc_two)
|
65
|
+
type.put(3, doc_three)
|
66
|
+
type.index.refresh
|
67
|
+
end
|
68
|
+
|
69
|
+
let (:results) {
|
70
|
+
type.mlt(1, min_term_freq: 1, min_doc_freq: 1, fields: [:message])
|
71
|
+
}
|
72
|
+
|
73
|
+
it "should return results as SearchResults" do
|
74
|
+
results.should be_a(Stretcher::SearchResults)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return expected mlt results" do
|
78
|
+
Set.new(results.docs.map(&:_id)).should == Set.new(["2", "3"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
53
82
|
describe 'mget' do
|
54
83
|
let(:doc_one) {{:message => "message one!", :_timestamp => 1366420402}}
|
55
84
|
let(:doc_two) {{:message => "message two!", :_timestamp => 1366420403}}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.20.0.
|
4
|
+
version: 1.20.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Cholakian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|