idol-search 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/examples.rb +6 -0
- data/idol-search.gemspec +70 -0
- data/lib/hash_from_xml.rb +62 -0
- data/lib/idol-search.rb +159 -0
- data/test/helper.rb +18 -0
- data/test/test_idol-search.rb +90 -0
- metadata +175 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
gem "curb", "~> 0.8"
|
3
|
+
gem "nokogiri", "~> 1.5"
|
4
|
+
|
5
|
+
# Add dependencies to develop your gem here.
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
7
|
+
group :development do
|
8
|
+
gem "shoulda", ">= 0"
|
9
|
+
gem "rdoc", "~> 3.12"
|
10
|
+
gem "bundler"
|
11
|
+
gem "jeweler", "~> 1.8.4"
|
12
|
+
gem "simplecov"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.11)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
bourne (1.1.2)
|
8
|
+
mocha (= 0.10.5)
|
9
|
+
curb (0.8.3)
|
10
|
+
git (1.2.5)
|
11
|
+
i18n (0.6.1)
|
12
|
+
jeweler (1.8.4)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
rdoc
|
17
|
+
json (1.7.6)
|
18
|
+
metaclass (0.0.1)
|
19
|
+
mocha (0.10.5)
|
20
|
+
metaclass (~> 0.0.1)
|
21
|
+
multi_json (1.5.0)
|
22
|
+
nokogiri (1.5.6)
|
23
|
+
rake (10.0.3)
|
24
|
+
rdoc (3.12)
|
25
|
+
json (~> 1.4)
|
26
|
+
shoulda (3.3.2)
|
27
|
+
shoulda-context (~> 1.0.1)
|
28
|
+
shoulda-matchers (~> 1.4.1)
|
29
|
+
shoulda-context (1.0.2)
|
30
|
+
shoulda-matchers (1.4.2)
|
31
|
+
activesupport (>= 3.0.0)
|
32
|
+
bourne (~> 1.1.2)
|
33
|
+
simplecov (0.7.1)
|
34
|
+
multi_json (~> 1.0)
|
35
|
+
simplecov-html (~> 0.7.1)
|
36
|
+
simplecov-html (0.7.1)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bundler
|
43
|
+
curb (~> 0.8)
|
44
|
+
jeweler (~> 1.8.4)
|
45
|
+
nokogiri (~> 1.5)
|
46
|
+
rdoc (~> 3.12)
|
47
|
+
shoulda
|
48
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Shane Sherman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= idol-search
|
2
|
+
|
3
|
+
lightweight dsl for Autonomy Idol search
|
4
|
+
|
5
|
+
== Contributing to idol-search
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 Shane Sherman. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "idol-search"
|
18
|
+
gem.homepage = "http://github.com/ssherman/idol-search"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{ruby client for autonomy idol search}
|
21
|
+
gem.description = %Q{ruby client for autonomy idol search}
|
22
|
+
gem.email = "shane.sherman@gmail.com"
|
23
|
+
gem.authors = ["Shane Sherman"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
require 'rdoc/task'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "idol-search #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/examples.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
|
2
|
+
query = Idol::Query.new("http://stg-autonomy-02.moxie.ext", "test test")
|
3
|
+
query.max_results(5).combine("simple").print('fields').print_fields("NGEN_TYPE,ID").abridged(false)
|
4
|
+
filter1 = Idol::FieldTextFilter.new("NGEN_TYPE", Idol::Filters::MATCH, "Document")
|
5
|
+
query.filters.add(filter1)
|
6
|
+
puts query.execute
|
data/idol-search.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "idol-search"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Shane Sherman"]
|
12
|
+
s.date = "2013-01-15"
|
13
|
+
s.description = "ruby client for autonomy idol search"
|
14
|
+
s.email = "shane.sherman@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"examples.rb",
|
28
|
+
"idol-search.gemspec",
|
29
|
+
"lib/hash_from_xml.rb",
|
30
|
+
"lib/idol-search.rb",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/test_idol-search.rb"
|
33
|
+
]
|
34
|
+
s.homepage = "http://github.com/ssherman/idol-search"
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = "1.8.24"
|
38
|
+
s.summary = "ruby client for autonomy idol search"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<curb>, ["~> 0.8"])
|
45
|
+
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.5"])
|
46
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
50
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<curb>, ["~> 0.8"])
|
53
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.5"])
|
54
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
56
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
58
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<curb>, ["~> 0.8"])
|
62
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.5"])
|
63
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
65
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
67
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
|
2
|
+
require 'nokogiri'
|
3
|
+
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
|
4
|
+
|
5
|
+
class Hash
|
6
|
+
class << self
|
7
|
+
def from_xml(xml_io)
|
8
|
+
begin
|
9
|
+
result = Nokogiri::XML(xml_io)
|
10
|
+
return { result.root.name.to_sym => xml_node_to_hash(result.root)}
|
11
|
+
rescue Exception => e
|
12
|
+
# raise your custom exception here
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def xml_node_to_hash(node)
|
17
|
+
# If we are at the root of the document, start the hash
|
18
|
+
if node.element?
|
19
|
+
result_hash = {}
|
20
|
+
if node.attributes != {}
|
21
|
+
result_hash[:attributes] = {}
|
22
|
+
node.attributes.keys.each do |key|
|
23
|
+
result_hash[:attributes][node.attributes[key].name.to_sym] = prepare(node.attributes[key].value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
if node.children.size > 0
|
27
|
+
node.children.each do |child|
|
28
|
+
result = xml_node_to_hash(child)
|
29
|
+
|
30
|
+
if child.name == "text"
|
31
|
+
unless child.next_sibling || child.previous_sibling
|
32
|
+
return prepare(result)
|
33
|
+
end
|
34
|
+
elsif result_hash[child.name.to_sym]
|
35
|
+
if result_hash[child.name.to_sym].is_a?(Object::Array)
|
36
|
+
result_hash[child.name.to_sym] << prepare(result)
|
37
|
+
else
|
38
|
+
result_hash[child.name.to_sym] = [result_hash[child.name.to_sym]] << prepare(result)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
result_hash[child.name.to_sym] = prepare(result)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
return result_hash
|
46
|
+
else
|
47
|
+
return result_hash
|
48
|
+
end
|
49
|
+
else
|
50
|
+
return prepare(node.content.to_s)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def prepare(data)
|
55
|
+
(data.class == String && data.to_i.to_s == data) ? data.to_i : data
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_struct(struct_name)
|
60
|
+
Struct.new(struct_name,*keys).new(*values)
|
61
|
+
end
|
62
|
+
end
|
data/lib/idol-search.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'curb'
|
2
|
+
require_relative 'hash_from_xml'
|
3
|
+
module Idol
|
4
|
+
|
5
|
+
module Conjunctions
|
6
|
+
AND = "AND"
|
7
|
+
OR = "OR"
|
8
|
+
NOT = "NOT"
|
9
|
+
BEFORE = "BEFORE"
|
10
|
+
AFTER = "AFTER"
|
11
|
+
end
|
12
|
+
|
13
|
+
module Filters
|
14
|
+
MATCH = "MATCH"
|
15
|
+
EQUAL = "EQUAL"
|
16
|
+
GREATER = "GREATER"
|
17
|
+
LESS = "LESS"
|
18
|
+
NRANGE = "NRANGE"
|
19
|
+
NOT_EQUAL = "NOTEQUAL"
|
20
|
+
WILD = "WILD"
|
21
|
+
|
22
|
+
MATCH_ALL = "MATCHALL"
|
23
|
+
EQUAL_ALL = "EQUALALL"
|
24
|
+
|
25
|
+
NOT_MATCH = "NOTMATCH"
|
26
|
+
NOT_STRING = "NOTSTRING"
|
27
|
+
NOT_WILD = "NOTWILD"
|
28
|
+
|
29
|
+
STRING = "STRING"
|
30
|
+
STRING_ALL = "STRINGALL"
|
31
|
+
SUBSTRING = "SUBSTRING"
|
32
|
+
|
33
|
+
TERM = "TERM"
|
34
|
+
TERM_ALL = "TERMALL"
|
35
|
+
TERM_EXACT = "TERMEXACT"
|
36
|
+
TERM_EXACT_ALL = "TERMEXACTALL"
|
37
|
+
TERM_EXACT_PHRASE = "TERMEXACTPHRASE"
|
38
|
+
TERM_PHRASE = "TERMPHRASE"
|
39
|
+
end
|
40
|
+
|
41
|
+
class Query
|
42
|
+
attr_accessor :url, :text, :filters, :parameters, :raw_results, :sort
|
43
|
+
attr_reader :action
|
44
|
+
|
45
|
+
OPTIONAL_PARAMETERS = %w(abridged abs_weight agent_boolean_field agent_params_field agent_security_field any_language auto_phrase case_sensitive characters cluster combine combine_number dah_end_state dah_start_state database_match delete detect_language_type dont_match_id dont_match_reference encrypt_response end_tag field_check field_recurse field_restriction field_text_field filename force_template_refresh hard_field_restriction highlight highlight_tag_term ignore_specials irs language_type match_all_terms match_encoding match_id match_language match_language_type match_reference max_date max_id max_links_per_term max_print_chars max_query_terms max_results max_score min_date min_id min_links min_score min_term_length multi_stage multi_stage_info multi_stage_min_results multi_stage_page_backward multi_stage_start_state multi_stage_total_stages output output_encoding predict print print_fields query_summary reference_field security_info sentences single_match sort spellcheck start start_tag state_dont_match_id state_match_id stemming store_state stored_state_detail stored_state_field summary synonym template template_params_csvs text_parse vql weight_field_text xml_meta)
|
46
|
+
|
47
|
+
OPTIONAL_PARAMETERS.each do |opt_param|
|
48
|
+
define_method :"#{opt_param}" do |value|
|
49
|
+
instance_variable_set("@#{opt_param}", value)
|
50
|
+
@parameters[opt_param.gsub("_", "")] = value
|
51
|
+
return self
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize(url, text, parameters = {})
|
56
|
+
@raw_results = false
|
57
|
+
@url = url
|
58
|
+
@action = "Query"
|
59
|
+
@text = text
|
60
|
+
@parameters = parameters
|
61
|
+
@filters = FieldTextFilterCollection.new
|
62
|
+
end
|
63
|
+
|
64
|
+
def filters
|
65
|
+
@filters
|
66
|
+
end
|
67
|
+
|
68
|
+
def execute
|
69
|
+
post_fields = generate_post_fields
|
70
|
+
|
71
|
+
status = nil
|
72
|
+
body = nil
|
73
|
+
|
74
|
+
full_url = "#{@url}/?action=#{@action}"
|
75
|
+
request = Curl::Easy.new do |r|
|
76
|
+
r.url = "#{@url}/?action=Query"
|
77
|
+
r.on_complete do |data|
|
78
|
+
status = data.response_code
|
79
|
+
body = data.body_str
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
request.http_post(*post_fields)
|
84
|
+
#[status, body]
|
85
|
+
results = @raw_results ? body : Hash.from_xml(body)
|
86
|
+
if !@raw_results && results[:autnresponse][:responsedata][:abridged]
|
87
|
+
# TODO: parse the abridged results
|
88
|
+
end
|
89
|
+
results
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def generate_post_fields
|
94
|
+
post_fields = []
|
95
|
+
if @filters.count > 0
|
96
|
+
post_fields << Curl::PostField.content("fieldtext", @filters.to_idol_syntax)
|
97
|
+
end
|
98
|
+
post_fields << Curl::PostField.content("text", @text)
|
99
|
+
|
100
|
+
@parameters.each do |name, values|
|
101
|
+
post_fields << Curl::PostField.content(name, values)
|
102
|
+
end
|
103
|
+
post_fields
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
class FieldTextFilter
|
109
|
+
attr_accessor :fields, :specifier, :values
|
110
|
+
def initialize(fields, specifier, values)
|
111
|
+
@fields = fields.is_a?(Array) ? fields : [fields]
|
112
|
+
@specifier = specifier
|
113
|
+
@values = values.is_a?(Array) ? values : [values]
|
114
|
+
end
|
115
|
+
|
116
|
+
def to_idol_syntax
|
117
|
+
values_string = @values.map{|v| escape(v) }.join(",")
|
118
|
+
"#{specifier}{#{values_string}}:#{fields.join(':')}"
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
def escape(value)
|
123
|
+
value.gsub("&", "%26").gsub("\\", "%5C").gsub("%", "%25").gsub("{", "%257B").gsub("{", "%257D")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class FieldTextFilterCollection
|
128
|
+
include Enumerable
|
129
|
+
def initialize
|
130
|
+
@filters = []
|
131
|
+
@conjunctions = []
|
132
|
+
end
|
133
|
+
|
134
|
+
def <<(filter)
|
135
|
+
@filters << filter
|
136
|
+
end
|
137
|
+
|
138
|
+
def add(filter, conjunction=Idol::Conjunctions::AND)
|
139
|
+
self << filter
|
140
|
+
@conjunctions << conjunction
|
141
|
+
return self
|
142
|
+
end
|
143
|
+
|
144
|
+
def each(&block)
|
145
|
+
@filters.each(&block)
|
146
|
+
end
|
147
|
+
|
148
|
+
def to_idol_syntax
|
149
|
+
idol_syntax = []
|
150
|
+
@filters.each_with_index do |filter, index|
|
151
|
+
idol_syntax << @conjunctions[index] unless index == 0
|
152
|
+
idol_syntax << filter.to_idol_syntax
|
153
|
+
end
|
154
|
+
idol_syntax.join(" ").strip
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'idol-search'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestIdolSearch < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "an FieldTextFilterCollection" do
|
6
|
+
setup do
|
7
|
+
@filter_collection = Idol::FieldTextFilterCollection.new
|
8
|
+
end
|
9
|
+
|
10
|
+
should "should render no text when .to_idol_syntax is called" do
|
11
|
+
assert_equal "", @filter_collection.to_idol_syntax
|
12
|
+
end
|
13
|
+
|
14
|
+
context "with 1 simple filter" do
|
15
|
+
setup do
|
16
|
+
filter = Idol::FieldTextFilter.new("favorite_drink", Idol::Filters::MATCH, "Whiskey")
|
17
|
+
@filter_collection.add(filter)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "correctly generate the idol_syntax" do
|
21
|
+
assert_equal @filter_collection.to_idol_syntax, "MATCH{Whiskey}:favorite_drink"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with 2 filters with no conjunction specified" do
|
26
|
+
setup do
|
27
|
+
filter1 = Idol::FieldTextFilter.new("favorite_drink", Idol::Filters::MATCH, "Whiskey")
|
28
|
+
filter2 = Idol::FieldTextFilter.new("favorite_language", Idol::Filters::MATCH, "Ruby")
|
29
|
+
@filter_collection.add(filter1)
|
30
|
+
@filter_collection.add(filter2)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "correctly generate the idol syntax" do
|
34
|
+
expected = "MATCH{Whiskey}:favorite_drink AND MATCH{Ruby}:favorite_language"
|
35
|
+
assert_equal @filter_collection.to_idol_syntax, expected
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "with 2 filters and a conjunction specified" do
|
40
|
+
setup do
|
41
|
+
filter1 = Idol::FieldTextFilter.new("favorite_drink", Idol::Filters::MATCH, "Whiskey")
|
42
|
+
filter2 = Idol::FieldTextFilter.new("favorite_language", Idol::Filters::MATCH, "Ruby", )
|
43
|
+
@filter_collection.add(filter1)
|
44
|
+
@filter_collection.add(filter2, Idol::Conjunctions::OR)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "correctly generate the idol syntax" do
|
48
|
+
expected = "MATCH{Whiskey}:favorite_drink OR MATCH{Ruby}:favorite_language"
|
49
|
+
assert_equal @filter_collection.to_idol_syntax, expected
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with a complex array filter" do
|
54
|
+
setup do
|
55
|
+
filter1 = Idol::FieldTextFilter.new("favorite_drinks", Idol::Filters::MATCH_ALL, ["Whiskey", "Rum"])
|
56
|
+
@filter_collection.add(filter1)
|
57
|
+
end
|
58
|
+
|
59
|
+
should "correctly generate the idol syntax" do
|
60
|
+
expected = "MATCHALL{Whiskey,Rum}:favorite_drinks"
|
61
|
+
assert_equal @filter_collection.to_idol_syntax, expected
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "with a complex array filter matching multiple fields" do
|
66
|
+
setup do
|
67
|
+
filter1 = Idol::FieldTextFilter.new(["favorite_drinks", "best_drinks"], Idol::Filters::MATCH, ["Whiskey", "Rum"])
|
68
|
+
@filter_collection.add(filter1)
|
69
|
+
end
|
70
|
+
|
71
|
+
should "correctly generate the idol syntax" do
|
72
|
+
expected = "MATCH{Whiskey,Rum}:favorite_drinks:best_drinks"
|
73
|
+
assert_equal @filter_collection.to_idol_syntax, expected
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with a filter that has values that need to be escaped" do
|
78
|
+
setup do
|
79
|
+
filter1 = Idol::FieldTextFilter.new("favorite_symbols", Idol::Filters::MATCH_ALL, '%\&{}')
|
80
|
+
@filter_collection.add(filter1)
|
81
|
+
end
|
82
|
+
|
83
|
+
should "correctly generate the idol syntax" do
|
84
|
+
expected = "MATCH{%25%5C%26%257B%257D}:favorite_drinks"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: idol-search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Shane Sherman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: curb
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.8'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.8'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.5'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.5'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.4
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.4
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: simplecov
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: ruby client for autonomy idol search
|
127
|
+
email: shane.sherman@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.rdoc
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.rdoc
|
139
|
+
- Rakefile
|
140
|
+
- VERSION
|
141
|
+
- examples.rb
|
142
|
+
- idol-search.gemspec
|
143
|
+
- lib/hash_from_xml.rb
|
144
|
+
- lib/idol-search.rb
|
145
|
+
- test/helper.rb
|
146
|
+
- test/test_idol-search.rb
|
147
|
+
homepage: http://github.com/ssherman/idol-search
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
segments:
|
161
|
+
- 0
|
162
|
+
hash: 2874440438630988744
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 1.8.24
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: ruby client for autonomy idol search
|
175
|
+
test_files: []
|