idol-search 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = idol-search
2
2
 
3
- lightweight dsl for Autonomy Idol search
3
+ lightweight library for Autonomy Idol search
4
4
 
5
5
  == Contributing to idol-search
6
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/examples.rb CHANGED
@@ -1,6 +1,12 @@
1
+ require './lib/idol-search'
1
2
 
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)
3
+ query = Idol::Suggest.new("http://stg-autonomy-02.moxie.ext")
4
+ query.reference("http://zkloeppingdev.moxiespaces.com:3000/documents/50c753bdf80bdb819c000004")
5
+ puts query.execute
6
+
7
+ query = Idol::Query.new("http://stg-autonomy-02.moxie.ext")
8
+ query.text("test test").max_results(5).combine("simple").print('fields').print_fields("NGEN_TYPE,ID").abridged(false)
4
9
  filter1 = Idol::FieldTextFilter.new("NGEN_TYPE", Idol::Filters::MATCH, "Document")
10
+
5
11
  query.filters.add(filter1)
6
- puts query.execute
12
+ puts query.execute
data/idol-search.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "idol-search"
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Shane Sherman"]
data/lib/idol-search.rb CHANGED
@@ -38,32 +38,33 @@ module Idol
38
38
  TERM_PHRASE = "TERMPHRASE"
39
39
  end
40
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
41
+ module OptionalParams
42
+ def has_optional_params(*params)
43
+ params.flatten.each do |opt_param|
44
+ define_method :"#{opt_param}" do |value|
45
+ instance_variable_set("@#{opt_param}", value)
46
+ @parameters[opt_param.gsub("_", "")] = value
47
+ return self
48
+ end
52
49
  end
53
50
  end
54
51
 
55
- def initialize(url, text, parameters = {})
52
+ end
53
+
54
+ module BasicIdolFunctionality
55
+ attr_accessor :url, :filters, :parameters, :raw_results
56
+ attr_reader :action
57
+
58
+ def initialize(url, parameters = {})
56
59
  @raw_results = false
57
60
  @url = url
58
- @action = "Query"
59
- @text = text
60
61
  @parameters = parameters
61
62
  @filters = FieldTextFilterCollection.new
62
63
  end
63
64
 
64
65
  def filters
65
66
  @filters
66
- end
67
+ end
67
68
 
68
69
  def execute
69
70
  post_fields = generate_post_fields
@@ -71,9 +72,8 @@ module Idol
71
72
  status = nil
72
73
  body = nil
73
74
 
74
- full_url = "#{@url}/?action=#{@action}"
75
75
  request = Curl::Easy.new do |r|
76
- r.url = "#{@url}/?action=Query"
76
+ r.url = "#{@url}/?action=#{@action}"
77
77
  r.on_complete do |data|
78
78
  status = data.response_code
79
79
  body = data.body_str
@@ -81,7 +81,6 @@ module Idol
81
81
  end
82
82
 
83
83
  request.http_post(*post_fields)
84
- #[status, body]
85
84
  results = @raw_results ? body : Hash.from_xml(body)
86
85
  if !@raw_results && results[:autnresponse][:responsedata][:abridged]
87
86
  # TODO: parse the abridged results
@@ -95,14 +94,36 @@ module Idol
95
94
  if @filters.count > 0
96
95
  post_fields << Curl::PostField.content("fieldtext", @filters.to_idol_syntax)
97
96
  end
98
- post_fields << Curl::PostField.content("text", @text)
99
97
 
98
+ puts "@params: #{@parameters.inspect}"
100
99
  @parameters.each do |name, values|
101
100
  post_fields << Curl::PostField.content(name, values)
102
101
  end
103
102
  post_fields
104
103
  end
104
+ end
105
105
 
106
+ class Query
107
+ extend OptionalParams
108
+ include BasicIdolFunctionality
109
+ OPTIONAL_PARAMETERS = %w(text 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) unless defined? OPTIONAL_PARAMETERS
110
+ has_optional_params OPTIONAL_PARAMETERS
111
+ def initialize(url, parameters = {})
112
+ super
113
+ @action = "Query"
114
+ end
115
+
116
+ end
117
+
118
+ class Suggest
119
+ extend OptionalParams
120
+ include BasicIdolFunctionality
121
+ OPTIONAL_PARAMETERS = %w(abs_weight case_sensitive characters cluster combine combine_number dah_end_state dah_start_state database_match delete dont_match_id dont_match_reference encrypt_response end_tag field_check field_recurse file_name force_template_refresh highlight highlight_tag_term id irs language_type match_encoding match_id match_language match_language_type match_reference max_date max_id max_print_chars max_results max_score min_date min_id min_links min_score min_term_length output output_encoding predict print print_fields query_summary reference reference_field security_info sentences single_match sort start start_tag state_dont_match_id state_id state_match_id stemming store_state stored_state_field summary template template_params_csvs timeout_ms total_results weigh_field_text xml_meta)
122
+ has_optional_params OPTIONAL_PARAMETERS
123
+ def initialize(url, parameters = {})
124
+ super
125
+ @action = "Suggest"
126
+ end
106
127
  end
107
128
 
108
129
  class FieldTextFilter
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idol-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -159,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
159
  version: '0'
160
160
  segments:
161
161
  - 0
162
- hash: 2874440438630988744
162
+ hash: 3603824292240643303
163
163
  required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  none: false
165
165
  requirements: