activedocument 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -20,19 +20,21 @@
|
|
20
20
|
# * value_constraints - this is a #Hash of value constraint names to their options. e.g. search_options_object.value_constraints["Region"] = {"namespace" => "http://wits.nctc.gov", "element" => "Region"}
|
21
21
|
module ActiveDocument
|
22
22
|
class SearchOptions
|
23
|
-
attr_accessor :return_facets, :value_constraints
|
23
|
+
attr_accessor :return_facets, :value_constraints, :word_constraints, :range_constraints
|
24
24
|
|
25
25
|
def initialize
|
26
26
|
@return_facets = true;
|
27
27
|
@value_constraints = Hash.new
|
28
|
+
@word_constraints = Hash.new
|
29
|
+
@range_constraints = Hash.new
|
28
30
|
end
|
29
31
|
|
30
32
|
|
31
33
|
# outputs the object in correctly formatted XML suitable for use in a search
|
32
34
|
def to_s
|
33
|
-
|
35
|
+
constraints = String.new
|
34
36
|
@value_constraints.each do |key, value|
|
35
|
-
|
37
|
+
constraints << <<-XML
|
36
38
|
<constraint name="#{key}">
|
37
39
|
<value>
|
38
40
|
<element ns="#{value["namespace"]}" name="#{value["element"]}"/>
|
@@ -41,16 +43,35 @@ module ActiveDocument
|
|
41
43
|
XML
|
42
44
|
end
|
43
45
|
|
46
|
+
@word_constraints.each do |key, value|
|
47
|
+
constraints << <<-XML
|
48
|
+
<constraint name="#{key}">
|
49
|
+
<word>
|
50
|
+
<element ns="#{value["namespace"]}" name="#{value["element"]}"/>
|
51
|
+
</word>
|
52
|
+
</constraint>
|
53
|
+
XML
|
54
|
+
end
|
55
|
+
|
56
|
+
@range_constraints.each do |key, value|
|
57
|
+
constraints << <<-XML
|
58
|
+
<constraint name="#{key}">
|
59
|
+
<range>
|
60
|
+
<element ns="#{value["namespace"]}" name="#{value["element"]}"/>
|
61
|
+
</range>
|
62
|
+
</constraint>
|
63
|
+
XML
|
64
|
+
end
|
65
|
+
|
44
66
|
value = <<-XML
|
45
67
|
<options xmlns="http://marklogic.com/appservices/search">
|
46
68
|
<return-facets>#{@return_facets}</return-facets>
|
47
69
|
XML
|
48
70
|
|
49
71
|
# add in constraints
|
50
|
-
unless
|
51
|
-
value <<
|
72
|
+
unless constraints.empty?
|
73
|
+
value << constraints
|
52
74
|
end
|
53
|
-
|
54
75
|
# close the options node
|
55
76
|
value << "</options>"
|
56
77
|
|
@@ -19,9 +19,19 @@ require 'ActiveDocument/search_result'
|
|
19
19
|
module ActiveDocument
|
20
20
|
class SearchResults
|
21
21
|
include Enumerable
|
22
|
+
attr_reader :facets
|
22
23
|
|
23
24
|
def initialize(results)
|
24
25
|
@results_document = Nokogiri::XML(results)
|
26
|
+
@facets = Hash.new
|
27
|
+
@results_document.xpath("/search:response/search:facet").each do |facet|
|
28
|
+
name = facet.xpath("./@name").to_s
|
29
|
+
detail = Hash.new
|
30
|
+
@facets[name] = detail
|
31
|
+
facet.xpath("search:facet-value").each do |facet_value|
|
32
|
+
detail[facet_value.xpath("./@name").to_s] = facet_value.xpath("./@count").to_s
|
33
|
+
end
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
def total
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: "0.
|
7
|
+
- 2
|
8
|
+
version: "0.2"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Clark D. Richey, Jr.
|
@@ -13,7 +13,7 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2010-04-
|
16
|
+
date: 2010-04-05 00:00:00 -04:00
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|