inquisitio 1.5.0 → 2.0.0

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: 44d14d9abac6f0abd9b664a401bdf7f1b33669d6
4
- data.tar.gz: 96cbec3963eabe249499d6b1f127d484419c8292
3
+ metadata.gz: dff28f9b5d191622a0c07139b2f03edb8ec8c87d
4
+ data.tar.gz: f03905452101150efceed98062cd8a9a9666b13b
5
5
  SHA512:
6
- metadata.gz: 0f21bef26aaabfb05976b59383fc37eca267808167a45fb2ef821cb4a3c095bfb88e3a0ed33e02af69e89f4f2c61760f70cc3b5b6cbe8999939b7a70136d6758
7
- data.tar.gz: 4b53556037160c92ed3c8f824473ce08b8e7b71155d703fef576b1d18ef08f1b0a3354aca1733690c3e2fe865135b24bcf3d84a88e59bd3fc306c224db5648ff
6
+ metadata.gz: 40362fa85a4a8bb8b71aa3b51f1d2aead37829b82cea692649fd0217d9936ac76e3b75f36de5cd467317d4d4bac606a98e325f03cd586a583bbf347ea819a2a7
7
+ data.tar.gz: 5068a7af2ad3f093d11821332c60cc0d3be383ec4dffa7fec84779a77d820a6d6caa84aefb48dcafaeee0a7006a2cddb9864a311696c157df92409a719d7f8ec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ 2.0.0 / 2015-07-21
2
+ [FEATURE] Removed support for 2011-02-01 api
3
+
1
4
  1.5.0 / 2015-07-17
2
5
  [FEATURE] Searcher now supports q.parser option as Search#parser
3
6
  [BUGFIX] Searcher no longer removes ' from simple queries
@@ -34,7 +34,7 @@ module Inquisitio
34
34
  def get_or_raise(setting)
35
35
  val = instance_variable_get("@#{setting.to_s}")
36
36
  if setting == :api_version && val.nil?
37
- val = '2011-02-01'
37
+ val = '2013-01-01'
38
38
  end
39
39
  val.nil?? raise(InquisitioConfigurationError.new("Configuration for #{setting} is not set")) : val
40
40
  end
@@ -8,15 +8,11 @@ module Inquisitio
8
8
  @type = type
9
9
  @id = id
10
10
  @version = version
11
- @fields = fields.reject { |k, v| v.nil? }
11
+ @fields = fields.reject { |_, v| v.nil? }
12
12
  end
13
13
 
14
- def to_SDF
15
- if Inquisitio.config.api_version == '2011-02-01'
16
- "{ \"type\": \"#{type}\", \"id\": \"#{id}\", \"version\": #{version}, \"lang\": \"en\", \"fields\": #{fields.to_json} }"
17
- elsif Inquisitio.config.api_version == '2013-01-01'
18
- "{ \"type\": \"#{type}\", \"id\": \"#{id}\", \"fields\": #{fields.to_json} }"
19
- end
14
+ def to_sdf
15
+ "{ \"type\": \"#{type}\", \"id\": \"#{id}\", \"fields\": #{fields.to_json} }"
20
16
  end
21
17
  end
22
18
  end
@@ -26,7 +26,7 @@ module Inquisitio
26
26
  private
27
27
 
28
28
  def body
29
- @body ||= "[#{@documents.map(&:to_SDF).join(", ")}]"
29
+ @body ||= "[#{@documents.map(&:to_sdf).join(", ")}]"
30
30
  end
31
31
 
32
32
  def batch_index_url
@@ -7,11 +7,11 @@ module Inquisitio
7
7
 
8
8
  def initialize(options = {})
9
9
  @query = options[:query]
10
- @filters = options[:filters] || {}
10
+ @named_fields = options[:named_fields] || {}
11
11
  @q_options = options[:q_options] || {}
12
12
  @expressions = options[:expressions] || {}
13
13
  @arguments = options[:arguments] || {}
14
- @return_fields = options[:return_fields]
14
+ @return_fields = options[:return_fields] || []
15
15
  @size = options[:size] || Inquisitio.config.default_search_size
16
16
  @start = options[:start] || 0
17
17
  @sort = options[:sort] || {}
@@ -22,7 +22,7 @@ module Inquisitio
22
22
  components = [url_root]
23
23
  components << (is_simple? ? simple_query : boolean_query)
24
24
  components << "&q.parser=#{@q_parser}" if @q_parser && Inquisitio.config.api_version == '2013-01-01'
25
- components << return_fields_query_string
25
+ components << "&return=#{CGI::escape(@return_fields.join(',').gsub('\'', ''))}" unless @return_fields.empty?
26
26
  components << arguments
27
27
  components << '&q.options=' + CGI::escape(@q_options.to_json) unless @q_options.empty?
28
28
  @expressions.each do |name, expression|
@@ -35,7 +35,7 @@ module Inquisitio
35
35
  end
36
36
 
37
37
  def is_simple?
38
- @filters.empty? && Array(@query).size == 1
38
+ @named_fields.empty? && Array(@query).size == 1
39
39
  end
40
40
 
41
41
  private
@@ -55,7 +55,7 @@ module Inquisitio
55
55
  query_blocks << "(or #{@query.map { |q| "'#{sanitise(q)}'" }.join(' ')})"
56
56
  end
57
57
 
58
- query_blocks += @filters.map do |key, value|
58
+ query_blocks += @named_fields.map do |key, value|
59
59
  if value.is_a?(String)
60
60
  "#{sanitise(key)}:'#{sanitise(value)}'"
61
61
  elsif value.is_a?(Array)
@@ -65,25 +65,13 @@ module Inquisitio
65
65
  end
66
66
  end
67
67
 
68
- if Inquisitio.config.api_version == '2011-02-01'
69
- "bq=#{CGI::escape("(and #{query_blocks.join(' ')})").gsub('&', '%26')}"
70
- elsif Inquisitio.config.api_version == '2013-01-01'
71
- "q=#{CGI::escape("(and #{query_blocks.join(' ')})").gsub('&', '%26')}"
72
- end
68
+ "q=#{CGI::escape("(and #{query_blocks.join(' ')})").gsub('&', '%26')}"
73
69
  end
74
70
 
75
71
  def sanitise(value)
76
72
  value.to_s.gsub('\'', '')
77
73
  end
78
74
 
79
- def return_fields_query_string
80
- return '' if @return_fields.nil?
81
- if Inquisitio.config.api_version == '2011-02-01'
82
- "&return-fields=#{CGI::escape(@return_fields.join(',').gsub('\'', ''))}"
83
- elsif Inquisitio.config.api_version == '2013-01-01'
84
- "&return=#{CGI::escape(@return_fields.join(',').gsub('\'', ''))}"
85
- end
86
- end
87
75
 
88
76
  def arguments
89
77
  return '' if @arguments.nil?
@@ -11,15 +11,14 @@ module Inquisitio
11
11
 
12
12
  def initialize(params = nil)
13
13
  @params = params || {
14
- criteria: [],
15
- filters: {},
16
- per: 10,
17
- page: 1,
18
- returns: [],
19
- with: {},
20
- sort: {},
21
- q_options: {},
22
- expressions: {}
14
+ criteria: [],
15
+ named_fields: {},
16
+ per: 10,
17
+ page: 1,
18
+ returns: [],
19
+ sort: {},
20
+ q_options: {},
21
+ expressions: {}
23
22
  }
24
23
  @failed_attempts = 0
25
24
 
@@ -72,11 +71,11 @@ module Inquisitio
72
71
  elsif value.is_a?(Hash)
73
72
  value.each do |k, v|
74
73
  k = k.to_sym
75
- s.params[:filters][k] ||= []
74
+ s.params[:named_fields][k] ||= []
76
75
  if v.is_a?(Array)
77
- s.params[:filters][k] = v
76
+ s.params[:named_fields][k] = v
78
77
  else
79
- s.params[:filters][k] << v
78
+ s.params[:named_fields][k] << v
80
79
  end
81
80
  end
82
81
  else
@@ -125,12 +124,6 @@ module Inquisitio
125
124
  end
126
125
  end
127
126
 
128
- def with(value)
129
- clone do |s|
130
- s.params[:with].merge!(value)
131
- end
132
- end
133
-
134
127
  def sort(value)
135
128
  clone do |s|
136
129
  s.params[:sort].merge!(value)
@@ -152,13 +145,12 @@ module Inquisitio
152
145
  response = Excon.get(search_url)
153
146
  raise InquisitioError.new("Search failed with status code: #{response.status} Message #{response.body}") unless response.status == 200
154
147
  body = JSON.parse(response.body)
155
- time_ms = body['info']['time-ms'] if Inquisitio.config.api_version == '2011-02-01'
156
- time_ms = body['status']['time-ms'] if Inquisitio.config.api_version == '2013-01-01'
148
+ time_ms = body['status']['time-ms']
157
149
  @results = Results.new(body['hits']['hit'],
158
- params[:page],
159
- params[:per],
160
- body['hits']['found'],
161
- time_ms)
150
+ params[:page],
151
+ params[:per],
152
+ body['hits']['found'],
153
+ time_ms)
162
154
  rescue => e
163
155
  @failed_attempts += 1
164
156
  Inquisitio.config.logger.error("Exception Performing search: #{search_url} #{e}")
@@ -173,23 +165,16 @@ module Inquisitio
173
165
 
174
166
  def search_url
175
167
  @search_url ||= begin
176
- if Inquisitio.config.api_version == '2011-02-01'
177
- return_fields = params[:returns].empty? ? [:type, :id] : params[:returns]
178
- elsif Inquisitio.config.api_version == '2013-01-01'
179
- return_fields = params[:returns].empty? ? nil : params[:returns]
180
- end
181
-
182
168
  SearchUrlBuilder.build(
183
- query: params[:criteria],
184
- filters: params[:filters],
185
- arguments: params[:with],
186
- size: params[:per],
187
- start: params[:per] * (params[:page] - 1),
188
- sort: params[:sort],
189
- q_options: params[:q_options],
190
- expressions: params[:expressions],
191
- q_parser: params[:q_parser],
192
- return_fields: return_fields
169
+ query: params[:criteria],
170
+ named_fields: params[:named_fields],
171
+ size: params[:per],
172
+ start: params[:per] * (params[:page] - 1),
173
+ sort: params[:sort],
174
+ q_options: params[:q_options],
175
+ expressions: params[:expressions],
176
+ q_parser: params[:q_parser],
177
+ return_fields: params[:returns]
193
178
  )
194
179
  end
195
180
  end
@@ -1,3 +1,3 @@
1
1
  module Inquisitio
2
- VERSION = '1.5.0'
2
+ VERSION = '2.0.0'
3
3
  end
data/lib/inquisitio.rb CHANGED
@@ -1,14 +1,13 @@
1
- require "inquisitio/version"
2
- require "inquisitio/inquisitio_error"
3
- require "inquisitio/logger"
4
- require "inquisitio/active_support"
5
-
6
- require "inquisitio/configuration"
7
- require "inquisitio/document"
8
- require "inquisitio/search_url_builder"
9
- require "inquisitio/searcher"
10
- require "inquisitio/results"
11
- require "inquisitio/indexer"
1
+ require 'inquisitio/version'
2
+ require 'inquisitio/inquisitio_error'
3
+ require 'inquisitio/logger'
4
+ require 'inquisitio/active_support'
5
+ require 'inquisitio/configuration'
6
+ require 'inquisitio/document'
7
+ require 'inquisitio/search_url_builder'
8
+ require 'inquisitio/searcher'
9
+ require 'inquisitio/results'
10
+ require 'inquisitio/indexer'
12
11
 
13
12
  module Inquisitio
14
13
 
@@ -71,13 +70,6 @@ module Inquisitio
71
70
  Searcher.returns(num)
72
71
  end
73
72
 
74
- # Specify any other fields you want to send as part of the request.
75
- #
76
- # @param query An array of fields.
77
- def self.with(num)
78
- Searcher.with(num)
79
- end
80
-
81
73
  # Index a batch of documents.
82
74
  #
83
75
  # @param [Array] documents. A list of Documents to index.
@@ -4,7 +4,7 @@ module Inquisitio
4
4
  class ConfigurationTest < Minitest::Test
5
5
 
6
6
  def setup
7
- Inquisitio.instance_variable_set("@config", nil)
7
+ Inquisitio.instance_variable_set('@config', nil)
8
8
  end
9
9
 
10
10
  def test_obtaining_singletion
@@ -12,7 +12,7 @@ module Inquisitio
12
12
  end
13
13
 
14
14
  def test_block_syntax
15
- test_search_endpoint = "foobar-123-endpoint"
15
+ test_search_endpoint = 'foobar-123-endpoint'
16
16
  Inquisitio.config do |config|
17
17
  config.search_endpoint = test_search_endpoint
18
18
  end
@@ -20,12 +20,11 @@ module Inquisitio
20
20
  end
21
21
 
22
22
  def test_api_version
23
- assert_equal '2011-02-01', Inquisitio.config.api_version
23
+ assert_equal '2013-01-01', Inquisitio.config.api_version
24
24
  Inquisitio.config.api_version = '2013-01-01'
25
25
  assert_equal '2013-01-01', Inquisitio.config.api_version
26
26
  Inquisitio.config.api_version = nil
27
- assert_equal '2011-02-01', Inquisitio.config.api_version
28
- Inquisitio.config.api_version = '2011-02-01'
27
+ assert_equal '2013-01-01', Inquisitio.config.api_version
29
28
  end
30
29
 
31
30
  def test_search_endpoint
@@ -33,7 +32,7 @@ module Inquisitio
33
32
  end
34
33
 
35
34
  def test_search_endpoint
36
- search_endpoint = "test-search-endpoint"
35
+ search_endpoint = 'test-search-endpoint'
37
36
  Inquisitio.config.search_endpoint = search_endpoint
38
37
  assert_equal search_endpoint, Inquisitio.config.search_endpoint
39
38
  end
@@ -45,7 +44,7 @@ module Inquisitio
45
44
  end
46
45
 
47
46
  def test_document_endpoint
48
- document_endpoint = "test-document-endpoint"
47
+ document_endpoint = 'test-document-endpoint'
49
48
  Inquisitio.config.document_endpoint = document_endpoint
50
49
  assert_equal document_endpoint, Inquisitio.config.document_endpoint
51
50
  end
@@ -57,7 +56,7 @@ module Inquisitio
57
56
  end
58
57
 
59
58
  def test_default_search_size
60
- default_search_size = "test-default_search_size"
59
+ default_search_size = 'test-default_search_size'
61
60
  Inquisitio.config.default_search_size = default_search_size
62
61
  assert_equal default_search_size, Inquisitio.config.default_search_size
63
62
  end
@@ -25,25 +25,17 @@ module Inquisitio
25
25
  assert_equal fields, document.fields
26
26
  end
27
27
 
28
- def test_create_valid_SDF_json_for_2011
29
- expected_SDF = '{ "type": "add", "id": "12345", "version": 1, "lang": "en", "fields": { "title": "The Title", "author": "The Author" } }'
30
- document = Document.new('add', '12345', 1, {:title => 'The Title', :author => 'The Author'})
31
- assert_equal JSON.parse(expected_SDF).to_json, JSON.parse(document.to_SDF).to_json
32
- end
33
-
34
- def test_create_valid_SDF_json_for_2013
35
- Inquisitio.config.api_version = '2013-01-01'
28
+ def test_create_valid_SDF_json
36
29
  expected_SDF = '{ "type": "add", "id": "12345", "fields": { "title": "The Title", "author": "The Author" } }'
37
30
  document = Document.new('add', '12345', 1, {:title => 'The Title', :author => 'The Author'})
38
- assert_equal JSON.parse(expected_SDF).to_json, JSON.parse(document.to_SDF).to_json
39
- Inquisitio.config.api_version = nil
31
+ assert_equal JSON.parse(expected_SDF).to_json, JSON.parse(document.to_sdf).to_json
40
32
  end
41
33
 
42
34
  def test_should_ignore_null_field_values_when_creating_SDF_json
43
- expected_SDF = '{ "type": "add", "id": "12345", "version": 1, "lang": "en", "fields": { "title": "The Title" } }'
35
+ expected_SDF = '{ "type": "add", "id": "12345", "fields": { "title": "The Title" } }'
44
36
  fields = {:title => 'The Title', :author => nil}
45
37
  document = Document.new('add', '12345', 1, fields)
46
- assert_equal JSON.parse(expected_SDF).to_json, JSON.parse(document.to_SDF).to_json
38
+ assert_equal JSON.parse(expected_SDF).to_json, JSON.parse(document.to_sdf).to_json
47
39
  end
48
40
  end
49
41
  end
@@ -1,12 +1,12 @@
1
1
  require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  module Inquisitio
4
- class IndexerFor2011Test < Minitest::Test
4
+ class IndexerTest < Minitest::Test
5
5
  def setup
6
6
  @document_endpoint = 'http://my.document-endpoint.com'
7
7
  Inquisitio.config.document_endpoint = @document_endpoint
8
8
  #def initialize(type, id, version, fields)
9
- @documents = [Document.new("add", "12345", 1, {})]
9
+ @documents = [Document.new('add', '12345', 1, {})]
10
10
 
11
11
  Inquisitio.config.dry_run = false
12
12
  end
@@ -21,36 +21,29 @@ module Inquisitio
21
21
  end
22
22
 
23
23
  def test_indexer_should_raise_exception_if_documents_nil
24
- assert_raises(InquisitioError, "Documents is nil") do
24
+ assert_raises(InquisitioError, 'Documents is nil') do
25
25
  Indexer.index(nil)
26
26
  end
27
27
  end
28
28
 
29
29
  def test_indexer_should_raise_exception_if_documents_empty
30
- assert_raises(InquisitioError, "Documents is empty") do
30
+ assert_raises(InquisitioError, 'Documents is empty') do
31
31
  Indexer.index([])
32
32
  end
33
33
  end
34
34
 
35
35
  def test_create_correct_index_url
36
- indexer = Indexer.new(@documents)
37
- assert_equal 'http://my.document-endpoint.com/2011-02-01/documents/batch', indexer.send(:batch_index_url)
38
- end
39
-
40
- def test_create_correct_index_url_2013
41
- Inquisitio.config.api_version = '2013-01-01'
42
36
  indexer = Indexer.new(@documents)
43
37
  assert_equal 'http://my.document-endpoint.com/2013-01-01/documents/batch', indexer.send(:batch_index_url)
44
- Inquisitio.config.api_version = nil
45
38
  end
46
39
 
47
40
  def test_create_correct_body
48
41
  doc1 = mock()
49
- doc1.expects(:to_SDF).returns("sdf1")
42
+ doc1.expects(:to_sdf).returns('sdf1')
50
43
  doc2 = mock()
51
- doc2.expects(:to_SDF).returns("sdf2")
44
+ doc2.expects(:to_sdf).returns('sdf2')
52
45
  doc3 = mock()
53
- doc3.expects(:to_SDF).returns("sdf3")
46
+ doc3.expects(:to_sdf).returns('sdf3')
54
47
 
55
48
  documents = [ doc1, doc2, doc3 ]
56
49
  indexer = Indexer.new(documents)
@@ -64,7 +57,7 @@ module Inquisitio
64
57
 
65
58
  indexer = Indexer.new(@documents)
66
59
 
67
- assert_raises(InquisitioError, "Indexer failed with status code 500") do
60
+ assert_raises(InquisitioError, 'Indexer failed with status code 500') do
68
61
  indexer.index
69
62
  end
70
63
  end
data/test/results_test.rb CHANGED
@@ -6,17 +6,24 @@ module Inquisitio
6
6
  super
7
7
  @search_endpoint = 'http://my.search-endpoint.com'
8
8
  Inquisitio.config.search_endpoint = @search_endpoint
9
- Inquisitio.config.api_version = nil
10
- @result_1 = {'data' => {'id' => ['1'], 'title' => ["Foobar"], 'type' => ["Cat"]}}
11
- @result_2 = {'data' => {'id' => ['2'], 'title' => ["Foobar"], 'type' => ["Cat"]}}
12
- @result_3 = {'data' => {'id' => ['20'], 'title' => ["Foobar2"], 'type' => ["Module_Dog"]}}
9
+ @result_1 = {'data' => {'id' => ['1'], 'title' => ['Foobar'], 'type' => ['Cat']}}
10
+ @result_2 = {'data' => {'id' => ['2'], 'title' => ['Foobar'], 'type' => ['Cat']}}
11
+ @result_3 = {'data' => {'id' => ['20'], 'title' => ['Foobar2'], 'type' => ['Module_Dog']}}
13
12
  @expected_results = [@result_1, @result_2, @result_3]
14
13
  @start = 5
15
14
  @found = 8
16
15
 
17
- @body = <<-EOS
18
- {"rank":"-text_relevance","match-expr":"(label 'star wars')","hits":{"found":#{@found},"start":#{@start},"hit":#{@expected_results.to_json}},"info":{"rid":"9d3b24b0e3399866dd8d376a7b1e0f6e930d55830b33a474bfac11146e9ca1b3b8adf0141a93ecee","time-ms":3,"cpu-time-ms":0}}
19
- EOS
16
+ @body = {
17
+ 'status' => {
18
+ 'rid' => '9d3b24b0e3399866dd8d376a7b1e0f6e930d55830b33a474bfac11146e9ca1b3b8adf0141a93ecee',
19
+ 'time-ms' => 3
20
+ },
21
+ 'hits' => {
22
+ 'found' => @found,
23
+ 'start' => @start,
24
+ 'hit' => @expected_results,
25
+ }
26
+ }.to_json
20
27
 
21
28
  Excon.defaults[:mock] = true
22
29
  Excon.stub({}, {body: @body, status: 200})
@@ -28,30 +35,23 @@ module Inquisitio
28
35
  end
29
36
 
30
37
  def test_should_return_total_count
31
- searcher = Searcher.where("star_wars")
38
+ searcher = Searcher.where('star_wars')
32
39
  searcher.search
33
40
  assert_equal @found, searcher.total_entries
34
41
  end
35
42
 
36
- def test_should_return_time_taken_for_2011
37
- searcher = Searcher.where("star_wars")
38
- searcher.search
39
- assert_equal 3, searcher.time_ms
40
- end
41
-
42
- def test_should_return_time_taken_for_2013
43
- Inquisitio.config.api_version = '2013-01-01'
43
+ def test_should_return_time_taken
44
44
  body = "{\"status\": {\"rid\" : \"u9aP4eYo8gIK0csK\", \"time-ms\": 4}, \"hits\" : {\"#{@found}\": 33, \"#{@start}\": 0, \"hit\":#{@expected_results.to_json} }}"
45
45
  Excon.stubs.clear
46
46
  Excon.stub({}, {body: body, status: 200})
47
47
 
48
- searcher = Searcher.where("star_wars")
48
+ searcher = Searcher.where('star_wars')
49
49
  searcher.search
50
50
  assert_equal 4, searcher.time_ms
51
51
  end
52
52
 
53
53
  def test_total_entries_should_proxy
54
- searcher = Searcher.where("star_wars")
54
+ searcher = Searcher.where('star_wars')
55
55
  searcher.search
56
56
  assert_equal @found, searcher.total_count
57
57
  end
@@ -101,7 +101,7 @@ module Inquisitio
101
101
  def test_nums_pages_should_proxy
102
102
  per = 3
103
103
  searcher = Searcher.per(per)
104
- searcher.search
104
+ # searcher.search
105
105
  assert_equal 3, searcher.num_pages
106
106
  end
107
107
 
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  module Inquisitio
4
- class SearchUrlBuilderFor2013Test < Minitest::Test
4
+ class SearchUrlBuilderTest < Minitest::Test
5
5
  def setup
6
6
  super
7
7
  @search_endpoint = 'http://my.search-endpoint.com'
@@ -22,7 +22,7 @@ module Inquisitio
22
22
  assert_equal expected_url, url
23
23
  end
24
24
 
25
- def test_create_correct_search_url_with_multiple_criteria_should_create_boolean_query
25
+ def test_create_correct_search_url_with_multiple_criteria_should_use_structured_parser
26
26
  url = SearchUrlBuilder.build(query: ['Star Wars', 'Episode One'])
27
27
  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%28or+%27Star+Wars%27+%27Episode+One%27%29%29&q.parser=structured&size=10'
28
28
  assert_equal expected_url, url
@@ -34,37 +34,12 @@ module Inquisitio
34
34
  assert_equal expected_url, url
35
35
  end
36
36
 
37
-
38
37
  def test_create_correct_search_url_including_return_fields
39
- url = SearchUrlBuilder.build(query: ['Star Wars'], return_fields: [ 'title', 'year', '%' ] )
38
+ url = SearchUrlBuilder.build(query: ['Star Wars'], return_fields: %w(title year %))
40
39
  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&return=title%2Cyear%2C%25&size=10'
41
40
  assert_equal expected_url, url
42
41
  end
43
42
 
44
- def test_create_boolean_query_search_url_with_only_filters
45
- url = SearchUrlBuilder.build(filters: {title: 'Star Wars'})
46
- expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+title%3A%27Star+Wars%27%29&q.parser=structured&size=10'
47
- assert_equal expected_url, url
48
- end
49
-
50
- def test_create_boolean_query_search_url_with_query_and_filters
51
- url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'})
52
- expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&q.parser=structured&size=10'
53
- assert_equal expected_url, url
54
- end
55
-
56
- def test_create_boolean_query_search_url_with_query_and_filters_and_return_fields
57
- url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, return_fields: [ 'title', 'year', '%' ])
58
- expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&q.parser=structured&return=title%2Cyear%2C%25&size=10'
59
- assert_equal expected_url, url
60
- end
61
-
62
- def test_create_search_url_with_added_arguments
63
- url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, :arguments => { facet: 'genre', 'facet-genre-constraints' => 'Animation', 'facet-genre-top-n' => '5'})
64
- expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&q.parser=structured&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
65
- assert_equal expected_url, url
66
- end
67
-
68
43
  def test_create_search_url_with_default_size
69
44
  url = SearchUrlBuilder.build(query: ['Star Wars'])
70
45
  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&size=10'
@@ -72,41 +47,30 @@ module Inquisitio
72
47
  end
73
48
 
74
49
  def test_create_search_url_overriding_default_size
75
- url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { size: '200' })
50
+ url = SearchUrlBuilder.build(query: ['Star Wars'], size: '200')
76
51
  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&size=200'
77
52
  assert_equal expected_url, url
78
53
  end
79
54
 
80
55
  def test_create_search_url_with_start_and_default_size
81
- url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '20' })
82
- expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&start=20&size=10'
83
- assert_equal expected_url, url
56
+ url = SearchUrlBuilder.build(query: ['Star Wars'], start: '20')
57
+ assert /(&|\?)start=20(&|$)/ =~ url
58
+ assert /(&|\?)size=10(&|$)/ =~ url
84
59
  end
85
60
 
86
61
  def test_create_search_url_with_start_and_size
87
- url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '2', size: '200' })
88
- expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&start=2&size=200'
89
- assert_equal expected_url, url
62
+ url = SearchUrlBuilder.build(query: ['Star Wars'], start: '2', size: '200')
63
+ assert /(&|\?)start=2(&|$)/ =~ url
64
+ assert /(&|\?)size=200(&|$)/ =~ url
90
65
  end
91
66
 
92
- def test_create_correct_search_url_with_sanatised_query_string
93
- url = SearchUrlBuilder.build(query: ['Star\' Wars'], filters: {genre: 'Anim\'ation'}, :arguments => { facet: 'ge\'nre', 'facet-genr\'e-constraints' => 'Anim\'ation', 'facet-gen\'re-top-n' => '\'5'}, return_fields: [ 't\'itle', 'y\'ear' ])
94
- expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&q.parser=structured&return=title%2Cyear&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
95
- assert_equal expected_url, url
96
- end
97
-
98
- def test_create_search_url_with_filter_array
99
- url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: ['Animation', 'Action']})
67
+ def test_create_search_url_with_named_fields_array
68
+ url = SearchUrlBuilder.build(query: ['Star Wars'], named_fields: {genre: ['Animation', 'Action']})
69
+ #TODO make the result use fq
100
70
  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+%28or+genre%3A%27Animation%27+genre%3A%27Action%27%29%29&q.parser=structured&size=10'
101
71
  assert_equal expected_url, url
102
72
  end
103
73
 
104
- def test_throws_exception_when_using_unsupported_filter_value_type
105
- assert_raises(InquisitioError) do
106
- SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: {}})
107
- end
108
- end
109
-
110
74
  def test_create_search_url_with_query_options
111
75
  url = SearchUrlBuilder.build(query: ['Star Wars'], q_options: {fields: %w(title^2.0 plot^0.5)})
112
76
  expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&q.options=%7B%22fields%22%3A%5B%22title%5E2.0%22%2C%22plot%5E0.5%22%5D%7D&size=10'
@@ -31,9 +31,17 @@ module Inquisitio
31
31
  @start = 5
32
32
  @found = 8
33
33
 
34
- @body = <<-EOS
35
- {"rank":"-text_relevance","match-expr":"(label 'star wars')","hits":{"found":#{@found},"start":#{@start},"hit":#{@expected_results.to_json}},"info":{"rid":"9d3b24b0e3399866dd8d376a7b1e0f6e930d55830b33a474bfac11146e9ca1b3b8adf0141a93ecee","time-ms":3,"cpu-time-ms":0}}
36
- EOS
34
+ @body = {
35
+ 'status' => {
36
+ 'rid' => '9d3b24b0e3399866dd8d376a7b1e0f6e930d55830b33a474bfac11146e9ca1b3b8adf0141a93ecee',
37
+ 'time-ms' => 3
38
+ },
39
+ 'hits' => {
40
+ 'found' => @found,
41
+ 'start' => @start,
42
+ 'hit' => @expected_results,
43
+ }
44
+ }.to_json
37
45
 
38
46
  Excon.defaults[:mock] = true
39
47
  Excon.stub({}, {body: @body, status: 200})
@@ -69,31 +77,31 @@ module Inquisitio
69
77
  refute_same searcher1, searcher2
70
78
  end
71
79
 
72
- def test_where_sets_filters
73
- filters = {genre: 'Animation'}
74
- searcher = Searcher.where(filters)
75
- assert_equal({genre: ['Animation']}, searcher.params[:filters])
80
+ def test_where_sets_named_fields
81
+ named_fields = {genre: 'Animation'}
82
+ searcher = Searcher.where(named_fields)
83
+ assert_equal({genre: ['Animation']}, searcher.params[:named_fields])
76
84
  end
77
85
 
78
- def test_where_merges_filters
79
- filters1 = {genre: 'Animation'}
80
- filters2 = {foobar: 'Cat'}
81
- searcher = Searcher.where(filters1).where(filters2)
82
- assert_equal({genre: ['Animation'], foobar: ['Cat']}, searcher.params[:filters])
86
+ def test_where_merges_named_fields
87
+ named_fields1 = {genre: 'Animation'}
88
+ named_fields2 = {foobar: 'Cat'}
89
+ searcher = Searcher.where(named_fields1).where(named_fields2)
90
+ assert_equal({genre: ['Animation'], foobar: ['Cat']}, searcher.params[:named_fields])
83
91
  end
84
92
 
85
93
  def test_symbolizes_where_keys
86
- filters1 = {'genre' => 'Animation'}
87
- filters2 = {'foobar' => 'Cat'}
88
- searcher = Searcher.where(filters1).where(filters2)
89
- assert_equal({genre: ['Animation'], foobar: ['Cat']}, searcher.params[:filters])
94
+ named_fields1 = {'genre' => 'Animation'}
95
+ named_fields2 = {'foobar' => 'Cat'}
96
+ searcher = Searcher.where(named_fields1).where(named_fields2)
97
+ assert_equal({genre: ['Animation'], foobar: ['Cat']}, searcher.params[:named_fields])
90
98
  end
91
99
 
92
- def test_where_merges_filters_with_same_key
93
- filters1 = {genre: 'Animation'}
94
- filters2 = {genre: 'Action'}
95
- searcher = Searcher.where(filters1).where(filters2)
96
- assert_equal({genre: %w(Animation Action)}, searcher.params[:filters])
100
+ def test_where_merges_named_fields_with_same_key
101
+ named_fields1 = {genre: 'Animation'}
102
+ named_fields2 = {genre: 'Action'}
103
+ searcher = Searcher.where(named_fields1).where(named_fields2)
104
+ assert_equal({genre: %w(Animation Action)}, searcher.params[:named_fields])
97
105
  end
98
106
 
99
107
  def test_where_gets_correct_url
@@ -102,14 +110,7 @@ module Inquisitio
102
110
  assert(search_url.include?('q=Star+Wars'), "Search url should include search term: #{search_url}")
103
111
  end
104
112
 
105
- def test_where_gets_correct_url_with_filters_for_2011
106
- searcher = Searcher.where(title: 'Star Wars')
107
- search_url = searcher.send(:search_url)
108
- assert(search_url.include?('bq=%28and+%28or+title%3A%27Star+Wars%27%29%29'), "Search url should include query: #{search_url}")
109
- end
110
-
111
- def test_where_gets_correct_url_with_filters_for_2013
112
- Inquisitio.config.api_version = '2013-01-01'
113
+ def test_where_gets_correct_url_with_fields_in_search
113
114
  searcher = Searcher.where(title: 'Star Wars')
114
115
  search_url = searcher.send(:search_url)
115
116
  assert(search_url.include?('q=%28and+%28or+title%3A%27Star+Wars%27%29%29&q.parser=structured'), "Search url should include query: #{search_url}")
@@ -118,14 +119,14 @@ module Inquisitio
118
119
  def test_where_works_with_array_in_a_hash
119
120
  criteria = {thing: %w(foo bar)}
120
121
  searcher = Searcher.where(criteria)
121
- assert_equal criteria, searcher.params[:filters]
122
+ assert_equal criteria, searcher.params[:named_fields]
122
123
  end
123
124
 
124
125
  def test_where_works_with_string_and_array
125
126
  str_criteria = 'Star Wars'
126
127
  hash_criteria = {thing: %w(foo bar)}
127
128
  searcher = Searcher.where(str_criteria).where(hash_criteria)
128
- assert_equal hash_criteria, searcher.params[:filters]
129
+ assert_equal hash_criteria, searcher.params[:named_fields]
129
130
  assert_equal [str_criteria], searcher.params[:criteria]
130
131
  end
131
132
 
@@ -205,13 +206,7 @@ module Inquisitio
205
206
  assert searcher.params[:returns].include?('foobar')
206
207
  end
207
208
 
208
- def test_returns_gets_correct_urlns_appends_variable_for_2011
209
- searcher = Searcher.returns('foobar')
210
- assert searcher.send(:search_url).include? '&return-fields=foobar'
211
- end
212
-
213
- def test_returns_gets_correct_urlns_appends_variable_for_2013
214
- Inquisitio.config.api_version = '2013-01-01'
209
+ def test_returns_gets_correct_url_returns_appends_variable
215
210
  searcher = Searcher.returns('foobar')
216
211
  assert searcher.send(:search_url).include? '&return=foobar'
217
212
  end
@@ -221,14 +216,7 @@ module Inquisitio
221
216
  assert_equal %w(dog cat), searcher.params[:returns]
222
217
  end
223
218
 
224
- def test_returns_with_array_gets_correct_url_for_2011
225
- searcher = Searcher.returns('id', 'foobar')
226
- search_url = searcher.send(:search_url)
227
- assert(search_url.include?('&return-fields=id%2Cfoobar'), "Search url should include return fields: #{search_url}")
228
- end
229
-
230
- def test_returns_with_array_gets_correct_url_for_2013
231
- Inquisitio.config.api_version = '2013-01-01'
219
+ def test_returns_with_array_gets_correct_url
232
220
  searcher = Searcher.returns('id', 'foobar')
233
221
  search_url = searcher.send(:search_url)
234
222
  assert(search_url.include?('&return=id%2Cfoobar'), "Search url should include return: #{search_url}")
@@ -239,21 +227,6 @@ module Inquisitio
239
227
  assert_equal %w(id foobar), searcher.params[:returns]
240
228
  end
241
229
 
242
- def test_with_saves_variable
243
- searcher = Searcher.with(foo: 'bar')
244
- assert_equal({foo: 'bar'}, searcher.params[:with])
245
- end
246
-
247
- def test_with_appends_to_variable
248
- searcher = Searcher.with(foo: 'bar').with(cat: 'dog')
249
- assert_equal({foo: 'bar', cat: 'dog'}, searcher.params[:with])
250
- end
251
-
252
- def test_with_gets_correct_url
253
- searcher = Searcher.with(foo: 'bar').with(cat: 'dog')
254
- assert searcher.send(:search_url).include? '&foo=bar&cat=dog'
255
- end
256
-
257
230
  def test_search_calls_search_url_builder
258
231
  SearchUrlBuilder.any_instance.expects(build: 'http://www.example.com')
259
232
  searcher = Searcher.where('Star Wars')
@@ -329,19 +302,11 @@ module Inquisitio
329
302
  2.times { searcher.search }
330
303
  end
331
304
 
332
- def test_should_return_type_and_id_by_default_for_2011
333
- searcher = Searcher.where('Star Wars')
334
- assert_equal [], searcher.params[:returns]
335
- search_url = searcher.send(:search_url)
336
- assert(search_url.include?('&return-fields=type%2Cid'), "Search url should include return for type and id: #{search_url}")
337
- end
338
-
339
- def test_should_not_specify_return_by_default_for_2013
305
+ def test_should_not_specify_return_by_default
340
306
  Inquisitio.config.api_version = '2013-01-01'
341
307
  searcher = Searcher.where('Star Wars')
342
308
  assert_equal [], searcher.params[:returns]
343
309
  refute searcher.send(:search_url).include? '&return='
344
- refute searcher.send(:search_url).include? '&return-fields='
345
310
  end
346
311
 
347
312
  def test_should_return_ids
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inquisitio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-07-17 00:00:00.000000000 Z
14
+ date: 2015-07-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: excon
@@ -103,11 +103,7 @@ email:
103
103
  - charles@meducation.net
104
104
  - malcolm@meducation.net
105
105
  - rob@meducation.net
106
- executables:
107
- - boolean_query
108
- - facet_query
109
- - index
110
- - search
106
+ executables: []
111
107
  extensions: []
112
108
  extra_rdoc_files: []
113
109
  files:
@@ -119,10 +115,6 @@ files:
119
115
  - LICENCE.md
120
116
  - README.md
121
117
  - Rakefile
122
- - bin/boolean_query
123
- - bin/facet_query
124
- - bin/index
125
- - bin/search
126
118
  - inquisitio.gemspec
127
119
  - lib/inquisitio.rb
128
120
  - lib/inquisitio/active_support.rb
@@ -137,11 +129,10 @@ files:
137
129
  - lib/inquisitio/version.rb
138
130
  - test/configuration_test.rb
139
131
  - test/document_test.rb
140
- - test/indexer_for_2011_test.rb
132
+ - test/indexer_test.rb
141
133
  - test/logger_test.rb
142
134
  - test/results_test.rb
143
- - test/search_url_builder_for_2011_test.rb
144
- - test/search_url_builder_for_2013_test.rb
135
+ - test/search_url_builder_test.rb
145
136
  - test/searcher_test.rb
146
137
  - test/test_helper.rb
147
138
  homepage: https://github.com/meducation/inquisition
@@ -171,11 +162,10 @@ summary: This wraps AWS CloudSearch in a Ruby Gem
171
162
  test_files:
172
163
  - test/configuration_test.rb
173
164
  - test/document_test.rb
174
- - test/indexer_for_2011_test.rb
165
+ - test/indexer_test.rb
175
166
  - test/logger_test.rb
176
167
  - test/results_test.rb
177
- - test/search_url_builder_for_2011_test.rb
178
- - test/search_url_builder_for_2013_test.rb
168
+ - test/search_url_builder_test.rb
179
169
  - test/searcher_test.rb
180
170
  - test/test_helper.rb
181
171
  has_rdoc:
data/bin/boolean_query DELETED
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- lib = File.expand_path('../../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
-
6
- require "inquisitio"
7
-
8
- # Perform a search containing a boolean query against AWS CloudSearch
9
- #
10
- # example usage:
11
- #
12
- # ruby ./bin/search <enddpoint> "Star Wars" "genre" "Animation" "title"
13
-
14
- endpoint = ARGV[0]
15
- query = ARGV[1]
16
- filter_name = ARGV[2]
17
- filter_value = ARGV[3]
18
- return_fields = [ ARGV[4] ]
19
-
20
- Inquisitio.config do |config|
21
- config.search_endpoint = endpoint
22
- end
23
-
24
- puts Inquisitio.search(query, { filter_name.to_sym => filter_value.to_sym, :return_fields => return_fields} )
data/bin/facet_query DELETED
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- lib = File.expand_path('../../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
-
6
- require "inquisitio"
7
-
8
- # Perform a search containing a boolean query against AWS CloudSearch
9
- #
10
- # example usage:
11
- #
12
- # ruby ./bin/search <enddpoint> "Star Wars" "genre" "Animation" "title"
13
-
14
- endpoint = ARGV[0]
15
- query = ARGV[1]
16
- filter_name = ARGV[2]
17
- filter_value = ARGV[3]
18
- return_fields = [ARGV[4]]
19
-
20
- Inquisitio.config do |config|
21
- config.search_endpoint = endpoint
22
- end
23
-
24
- puts Inquisitio.search(query,
25
- {filter_name.to_sym => filter_value.to_sym,
26
- :arguments => {:facet => 'genre',
27
- 'facet-genre-constraints' => 'Animation',
28
- 'facet-genre-top-n' => '5'
29
- },
30
- :return_fields => return_fields
31
- })
data/bin/index DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- lib = File.expand_path('../../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
-
6
- require "inquisitio"
7
-
8
- # Index a spdf file in AWS CloudSearch
9
- #
10
- # example usage:
11
- #
12
- # ruby ./bin/index <document_endpoint> "id" "version" "field_name" "field_value"
13
-
14
- endpoint = ARGV[0]
15
- id = ARGV[1]
16
-
17
- version = Time.now.to_i
18
-
19
- Inquisitio.config do |config|
20
- config.document_endpoint = endpoint
21
- end
22
-
23
- fields = { :title => 'The Title',
24
- :author => 'The Author' }
25
- document = Inquisitio::Document.new("add",
26
- id,
27
- version,
28
- fields)
29
- Inquisitio.index(document)
data/bin/search DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- lib = File.expand_path('../../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
-
6
- require "inquisitio"
7
-
8
- # Perform a search against AWS CloudSearch
9
- #
10
- # example usage:
11
- #
12
- # ruby ./bin/search <enddpoint> "Star Wars" "title"
13
-
14
- endpoint = ARGV[0]
15
- query = ARGV[1]
16
- return_fields = [ ARGV[2] ]
17
-
18
- Inquisitio.config do |config|
19
- config.search_endpoint = endpoint
20
- end
21
-
22
- if return_fields.nil?
23
- puts Inquisitio.search(query)
24
- else
25
- puts Inquisitio.search(query, { "return_fields" => return_fields} )
26
- end
@@ -1,109 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- module Inquisitio
4
- class SearchUrlBuilderFor2011Test < Minitest::Test
5
- def setup
6
- super
7
- @search_endpoint = 'http://my.search-endpoint.com'
8
- Inquisitio.config.search_endpoint = @search_endpoint
9
- Inquisitio.config.default_search_size = '10'
10
- end
11
-
12
- def test_create_correct_search_url_with_single_criteria_query
13
- url = SearchUrlBuilder.build(query: ['Star Wars'])
14
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&size=10'
15
- assert_equal expected_url, url
16
- end
17
-
18
- def test_create_correct_search_url_with_ampersand
19
- url = SearchUrlBuilder.build(query: ['Star&Wars'])
20
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star%26Wars&size=10'
21
- assert_equal expected_url, url
22
- end
23
-
24
- def test_create_correct_search_url_with_multiple_criteria_should_create_boolean_query
25
- url = SearchUrlBuilder.build(query: ['Star Wars', 'Episode One'])
26
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%28or+%27Star+Wars%27+%27Episode+One%27%29%29&size=10'
27
- assert_equal expected_url, url
28
- end
29
-
30
- def test_create_correct_search_url_with_multiple_criteria_with_ampersand
31
- url = SearchUrlBuilder.build(query: ['Star&Wars', 'Episode One'])
32
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%28or+%27Star%26Wars%27+%27Episode+One%27%29%29&size=10'
33
- assert_equal expected_url, url
34
- end
35
-
36
-
37
- def test_create_correct_search_url_including_return_fields
38
- url = SearchUrlBuilder.build(query: ['Star Wars'], return_fields: [ 'title', 'year', '%' ] )
39
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&return-fields=title%2Cyear%2C%25&size=10'
40
- assert_equal expected_url, url
41
- end
42
-
43
- def test_create_boolean_query_search_url_with_only_filters
44
- url = SearchUrlBuilder.build(filters: {title: 'Star Wars'})
45
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+title%3A%27Star+Wars%27%29&size=10'
46
- assert_equal expected_url, url
47
- end
48
-
49
- def test_create_boolean_query_search_url_with_query_and_filters
50
- url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'})
51
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&size=10'
52
- assert_equal expected_url, url
53
- end
54
-
55
- def test_create_boolean_query_search_url_with_query_and_filters_and_return_fields
56
- url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, return_fields: [ 'title', 'year', '%' ])
57
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&return-fields=title%2Cyear%2C%25&size=10'
58
- assert_equal expected_url, url
59
- end
60
-
61
- def test_create_search_url_with_added_arguments
62
- url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, :arguments => { facet: 'genre', 'facet-genre-constraints' => 'Animation', 'facet-genre-top-n' => '5'})
63
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
64
- assert_equal expected_url, url
65
- end
66
-
67
- def test_create_search_url_with_default_size
68
- url = SearchUrlBuilder.build(query: ['Star Wars'])
69
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&size=10'
70
- assert_equal expected_url, url
71
- end
72
-
73
- def test_create_search_url_overriding_default_size
74
- url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { size: '200' })
75
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&size=200'
76
- assert_equal expected_url, url
77
- end
78
-
79
- def test_create_search_url_with_start_and_default_size
80
- url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '20' })
81
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&start=20&size=10'
82
- assert_equal expected_url, url
83
- end
84
-
85
- def test_create_search_url_with_start_and_size
86
- url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '2', size: '200' })
87
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&start=2&size=200'
88
- assert_equal expected_url, url
89
- end
90
-
91
- def test_create_correct_search_url_with_sanatised_query_string
92
- url = SearchUrlBuilder.build(query: ['Star\' Wars'], filters: {genre: 'Anim\'ation'}, :arguments => { facet: 'ge\'nre', 'facet-genr\'e-constraints' => 'Anim\'ation', 'facet-gen\'re-top-n' => '\'5'}, return_fields: [ 't\'itle', 'y\'ear' ])
93
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&return-fields=title%2Cyear&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
94
- assert_equal expected_url, url
95
- end
96
-
97
- def test_create_search_url_with_filter_array
98
- url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: ['Animation', 'Action']})
99
- expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+%28or+genre%3A%27Animation%27+genre%3A%27Action%27%29%29&size=10'
100
- assert_equal expected_url, url
101
- end
102
-
103
- def test_throws_exception_when_using_unsupported_filter_value_type
104
- assert_raises(InquisitioError) do
105
- SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: {}})
106
- end
107
- end
108
- end
109
- end