solr_lite 0.0.5 → 0.0.6
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 +4 -4
- data/lib/highlights.rb +21 -0
- data/lib/response.rb +6 -0
- data/lib/search_params.rb +20 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4130e04f0ee49e7d45b2bc833a4e9bec1b404f5f
|
|
4
|
+
data.tar.gz: 8a812c8c94f95756cd6ba9001b9ff921e676dac6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d55a65d9d56e681d7e92e2297d82a067a3e49a10007665b88961e511c74a2b9bb3d6661c674ec7e9e230f1c81d06c7bbeb694b75e792f6a9202940cc7c0f8c41
|
|
7
|
+
data.tar.gz: 4bea5f25c2caf7d525c48a2cacd98d8d460aa53ee7e0071cdaf4277e6b5ead40277c5b6b2533d01ecee9a5f6ac4664fa3352b863c4b72a749f7715ad97cbed50
|
data/lib/highlights.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module SolrLite
|
|
2
|
+
class Highlights
|
|
3
|
+
|
|
4
|
+
# solr_response_hash a Solr HTTP response parsed via JSON.parse()
|
|
5
|
+
def initialize(solr_reponse_hash)
|
|
6
|
+
@highlighting = solr_reponse_hash.fetch("highlighting", {})
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# solr_response (string) is the Solr HTTP response from a query
|
|
10
|
+
def self.from_response(solr_response)
|
|
11
|
+
hash = JSON.parse(solr_response)
|
|
12
|
+
Highlights.new(hash)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Returns the highlight information for the given document ID.
|
|
16
|
+
def for(id)
|
|
17
|
+
return nil if @highlighting[id] == nil
|
|
18
|
+
@highlighting[id]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/response.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "facet_field.rb"
|
|
2
2
|
require "explainer.rb"
|
|
3
3
|
require "spellcheck.rb"
|
|
4
|
+
require "highlights.rb"
|
|
4
5
|
module SolrLite
|
|
5
6
|
class Response
|
|
6
7
|
attr_accessor :items, :solr_response
|
|
@@ -9,6 +10,8 @@ module SolrLite
|
|
|
9
10
|
@solr_response = solr_response
|
|
10
11
|
@params = params
|
|
11
12
|
@explainer = nil
|
|
13
|
+
@highlights = nil
|
|
14
|
+
|
|
12
15
|
set_facet_values()
|
|
13
16
|
|
|
14
17
|
# This value can be set by the client if we want to use a custom
|
|
@@ -110,5 +113,8 @@ module SolrLite
|
|
|
110
113
|
@spellcheck ||= SolrLite::Spellcheck.new(@solr_response)
|
|
111
114
|
end
|
|
112
115
|
|
|
116
|
+
def highlights()
|
|
117
|
+
@highlights ||= SolrLite::Highlights.new(@solr_response)
|
|
118
|
+
end
|
|
113
119
|
end # class
|
|
114
120
|
end # module
|
data/lib/search_params.rb
CHANGED
|
@@ -2,7 +2,8 @@ require "filter_query.rb"
|
|
|
2
2
|
require "facet_field.rb"
|
|
3
3
|
module SolrLite
|
|
4
4
|
class SearchParams
|
|
5
|
-
attr_accessor :q, :fq, :facets, :page, :page_size, :fl, :sort, :facet_limit
|
|
5
|
+
attr_accessor :a, :q, :fq, :facets, :page, :page_size, :fl, :sort, :facet_limit,
|
|
6
|
+
:spellcheck, :hl, :hl_fl, :hl_snippets
|
|
6
7
|
|
|
7
8
|
DEFAULT_PAGE_SIZE = 20
|
|
8
9
|
|
|
@@ -15,6 +16,11 @@ module SolrLite
|
|
|
15
16
|
@fl = nil
|
|
16
17
|
@sort = ""
|
|
17
18
|
@facet_limit = nil
|
|
19
|
+
@spellcheck = false
|
|
20
|
+
# Solr's hit highlighting parameters
|
|
21
|
+
@hl = false
|
|
22
|
+
@hl_fl = nil
|
|
23
|
+
@hl_snippets = 1
|
|
18
24
|
end
|
|
19
25
|
|
|
20
26
|
def facet_for_field(field)
|
|
@@ -91,6 +97,19 @@ module SolrLite
|
|
|
91
97
|
if sort != ""
|
|
92
98
|
qs += "&sort=#{CGI.escape(@sort)}"
|
|
93
99
|
end
|
|
100
|
+
if @spellcheck
|
|
101
|
+
qs += "&spellcheck=on"
|
|
102
|
+
end
|
|
103
|
+
# hit highlighting parameters
|
|
104
|
+
if @hl
|
|
105
|
+
qs += "&hl=true"
|
|
106
|
+
if @hl_fl != nil
|
|
107
|
+
qs += "&hl.fl=#{@hl_fl}"
|
|
108
|
+
end
|
|
109
|
+
if @hl_snippets > 1
|
|
110
|
+
qs += "&hl.snippets=#{@hl_snippets}"
|
|
111
|
+
end
|
|
112
|
+
end
|
|
94
113
|
if @facets.count > 0
|
|
95
114
|
qs += "&facet=on"
|
|
96
115
|
@facets.each do |f|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solr_lite
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hector Correa
|
|
@@ -21,6 +21,7 @@ files:
|
|
|
21
21
|
- lib/explainer.rb
|
|
22
22
|
- lib/facet_field.rb
|
|
23
23
|
- lib/filter_query.rb
|
|
24
|
+
- lib/highlights.rb
|
|
24
25
|
- lib/response.rb
|
|
25
26
|
- lib/search_params.rb
|
|
26
27
|
- lib/solr.rb
|
|
@@ -46,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
46
47
|
version: '0'
|
|
47
48
|
requirements: []
|
|
48
49
|
rubyforge_project:
|
|
49
|
-
rubygems_version: 2.5.1
|
|
50
|
+
rubygems_version: 2.5.2.1
|
|
50
51
|
signing_key:
|
|
51
52
|
specification_version: 4
|
|
52
53
|
summary: A lightweight gem to connect to Solr and run queries
|