Permalink
Browse files

advertise search fields, with semantics

  • Loading branch information...
1 parent 31e8704 commit 6d30688117c3dc5375d5521a69c4496d6f657d79 @jrochkind committed May 16, 2012
@@ -104,6 +104,17 @@ def self.max_per_page
100
end
+ def self.search_field_definitions
+ { "intitle" => {:semantic => :title},
+ "inauthor" => {:semantic => :author},
+ "inpublisher" => {:semantic => :publisher},
+ "subject" => {:semantic => :subject},
+ "isbn" => {:semantic => :isbn}
+ }
+ end
+
+
+
#############
# Our own implementation code
##############
@@ -8,6 +8,11 @@ module BentoSearch
#
# ==Using a SearchEngine
#
+ # * init/config
+ # * search
+ # * pagination, with max per_page
+ # * search fields, with semantics. ask for supported search fields.
+ #
# == Implementing a SearchEngine
#
# `include BentoSearch::SearchEngine`
@@ -25,6 +30,8 @@ module BentoSearch
# * implement a class-level `self.required_configuration' returning
# an array of config keys or dot keypaths, and it'll raise on init
# if those config's weren't supplied.
+ # * max per page
+ # * search fields
#
module SearchEngine
extend ActiveSupport::Concern
@@ -49,6 +56,9 @@ def initialize(aConfiguration = Confstruct::Configuration.new)
end
end
+
+
+
protected
def parse_search_arguments(*orig_arguments)
@@ -93,6 +103,19 @@ def parse_search_arguments(*orig_arguments)
return arguments
end
+ module ClassMethods
+ def search_field_keys
+ return [] unless respond_to? :search_field_definitions
+ return search_field_definitions.keys
+ end
+
+ def semantic_search_fields
+ return [] unless respond_to? :search_field_definitions
+ search_field_definitions.collect do |k, v|
+ v[:semantic] if v
+ end.compact
+ end
+ end
end
end
@@ -14,6 +14,14 @@ def self.max_per_page
40
end
+ def self.search_field_definitions
+ {
+ "my_title" => {:semantic => :title},
+ "my_author" => {:semantic => :author},
+ "my_other" => nil
+ }
+ end
+
end
@@ -89,6 +97,10 @@ def test_enforce_max_per_page
assert_raise(ArgumentError) { d.test_parse(:query => "query", :per_page => 1000) }
end
+ def test_search_field_keys
+ assert_equal ["my_title", "my_author", "my_other"], Dummy.search_field_keys
+ assert_equal [:title, :author], Dummy.semantic_search_fields
+ end
end

0 comments on commit 6d30688

Please sign in to comment.