xtf-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/APACHE-2-LICENSE +13 -0
  6. data/CHANGELOG.md +12 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +50 -0
  10. data/LICENSE.txt +202 -0
  11. data/NOTICE.txt +1 -0
  12. data/README.md +51 -0
  13. data/Rakefile +9 -0
  14. data/lib/xtf/result/element/base.rb +54 -0
  15. data/lib/xtf/result/element/doc_hit.rb +61 -0
  16. data/lib/xtf/result/element/facet.rb +29 -0
  17. data/lib/xtf/result/element/group.rb +37 -0
  18. data/lib/xtf/result/element/result.rb +91 -0
  19. data/lib/xtf/result/element.rb +13 -0
  20. data/lib/xtf/result.rb +6 -0
  21. data/lib/xtf/ruby/version.rb +7 -0
  22. data/lib/xtf/ruby.rb +10 -0
  23. data/lib/xtf/search/element/all_docs.rb +23 -0
  24. data/lib/xtf/search/element/and.rb +13 -0
  25. data/lib/xtf/search/element/base.rb +32 -0
  26. data/lib/xtf/search/element/clause.rb +57 -0
  27. data/lib/xtf/search/element/exact.rb +8 -0
  28. data/lib/xtf/search/element/facet.rb +26 -0
  29. data/lib/xtf/search/element/near.rb +17 -0
  30. data/lib/xtf/search/element/not.rb +7 -0
  31. data/lib/xtf/search/element/or.rb +13 -0
  32. data/lib/xtf/search/element/or_near.rb +11 -0
  33. data/lib/xtf/search/element/phrase.rb +28 -0
  34. data/lib/xtf/search/element/query.rb +42 -0
  35. data/lib/xtf/search/element/range.rb +44 -0
  36. data/lib/xtf/search/element/result_data.rb +18 -0
  37. data/lib/xtf/search/element/section_type.rb +19 -0
  38. data/lib/xtf/search/element/term.rb +51 -0
  39. data/lib/xtf/search/element.rb +15 -0
  40. data/lib/xtf/search.rb +11 -0
  41. data/lib/xtf/xml.rb +85 -0
  42. data/lib/xtf.rb +31 -0
  43. data/sig/xtf/ruby.rbs +6 -0
  44. metadata +158 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 116b59564d3fdc2617d10aafd81de5687ed500f81cc0c6f2410f67253a5758f5
4
+ data.tar.gz: 183ee193cafb4066d333bdb890ed35948bbff5ddfac29cc79451661303bf8181
5
+ SHA512:
6
+ metadata.gz: 1ba39ee24617a9b2ead5fcc73bc8b03f36f4740a319973d6590422819bf1478f118cbf6fddbca9627eae976542f7aa25e0ed3dcc546c3788a9d057342bce328b
7
+ data.tar.gz: 1e1f4af74a91aa0359f648e21c478bd5ce7796e2f4b07f8856d262fd7b1a13b420995c060f57ff521e1cb782808f2066b2c479ea552ef5b4d80172320527a222
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ xtf-ruby-1.0.0
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.7.5
data/APACHE-2-LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2007-2022 James (Jamie) Edward Orchard-Hays
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## [1.0.0] - 2022-02-17
2
+
3
+ - Initial release of the old plugin as a Ruby Gem
4
+ - Upgraded to RSpec ~>3
5
+ - Upgraded Specs
6
+ - Improved many Spec examples
7
+ - A few LibXML compatibility updates
8
+
9
+ ## [Previously]
10
+
11
+ - This gem was originally a Rails plugin
12
+ - See https://github.com/jamieorc/xtf-ruby/tree/rails-plugin-0.2.1
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jamieorc@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in xtf-ruby.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ xtf-ruby (1.0.0)
5
+ activesupport
6
+ libxml-ruby (~> 3.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (7.0.2.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ concurrent-ruby (1.1.9)
17
+ diff-lcs (1.5.0)
18
+ i18n (1.10.0)
19
+ concurrent-ruby (~> 1.0)
20
+ libxml-ruby (3.2.2)
21
+ minitest (5.15.0)
22
+ rake (13.0.6)
23
+ rexml (3.2.3.1)
24
+ rspec (3.11.0)
25
+ rspec-core (~> 3.11.0)
26
+ rspec-expectations (~> 3.11.0)
27
+ rspec-mocks (~> 3.11.0)
28
+ rspec-core (3.11.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-expectations (3.11.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-mocks (3.11.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-support (3.11.0)
37
+ tzinfo (2.0.4)
38
+ concurrent-ruby (~> 1.0)
39
+
40
+ PLATFORMS
41
+ arm64-darwin-20
42
+
43
+ DEPENDENCIES
44
+ rake (~> 13.0)
45
+ rexml (~> 3.2)
46
+ rspec (~> 3.0)
47
+ xtf-ruby!
48
+
49
+ BUNDLED WITH
50
+ 2.3.7
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/NOTICE.txt ADDED
@@ -0,0 +1 @@
1
+ XTF-Ruby includes software developed at The Apache Software Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # XTF-Ruby
2
+
3
+ == Ruby Interface to XTF
4
+
5
+ === Summary
6
+
7
+ XTF-Ruby brings a Ruby interface to the XTF framework. For searches, it allows you to use Ruby to generate XML queries for XTF's RawQuery servlet which then responds with XTF's raw XML response.
8
+
9
+ === Status of Code
10
+
11
+ Currently, the search section of the library is robust and employed in a production environment. For results, XTF-Ruby provides an API for parsing XTF's raw XML results into Ruby objects. This area is currently a work-in-progress, as I extract the code from a project for generalized use.
12
+
13
+ In February of 2022 the old plugin was converted to a Ruby Gem, Specs were updated for RSpec ~>3 and improved, and a few small compatibility updates were made.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'xtf-ruby'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle install
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install xtf-ruby
30
+
31
+ ## Usage
32
+
33
+ TODO: Write usage instructions here
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jamieorc/xtf-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/jamieorc/xtf-ruby/blob/gem-conversion/CODE_OF_CONDUCT.md).
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [APACHE-2.0 License](https://opensource.org/licenses/Apache-2.0).
48
+
49
+ ## Code of Conduct
50
+
51
+ Everyone interacting in the XTF::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jamieorc/xtf-ruby/blob/gem-conversion/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ desc "Run all specs by default"
9
+ task default: :spec
@@ -0,0 +1,54 @@
1
+ class XTF::Result::Element::Base
2
+
3
+ # require 'rubygems'
4
+ # require 'libxml_helper'
5
+ # require 'erb'
6
+ # include ERB::Util
7
+ # include ExportableDocument
8
+
9
+ attr_reader :xml,
10
+ :doc,
11
+ :rank,
12
+ :path,
13
+ :raw_path,
14
+ :score,
15
+ :total_hits,
16
+ :query
17
+
18
+
19
+ # Converts +maxSnippets+ to a value of -1 (all), so that proper hit counts are shown
20
+ # in the XTF-rendered document. An instance variable is lazily loaded.
21
+ def query_with_all_snippets
22
+ self.query.gsub(/maxSnippets=("|')\d+("|')/, %Q{maxSnippets="-1"})
23
+ end
24
+
25
+ def initialize(xml, query_params="")
26
+ start = Time.now
27
+ parse_xml(xml, query_params)
28
+ yield self if block_given?
29
+ # RAILS_DEFAULT_LOGGER.debug("~~~~~ #{self.class.name} initialized in #{Time.now - start} seconds.")
30
+ end
31
+
32
+ def self.create(xml, query_params="")
33
+ new(xml.to_s, query_params)
34
+ end
35
+
36
+ def parse_xml(xml, query)
37
+ @xml = xml.to_s.gsub(/\s+/, " ").strip
38
+ @query = query
39
+ @doc = XML::Document.parse_string(xml).root
40
+ doc_hit = @doc.at('//docHit')
41
+ meta = doc_hit.at('//meta')
42
+
43
+ @rank = doc_hit['rank']
44
+ @path = @raw_path = doc_hit['path']
45
+
46
+ @score = doc_hit['score']
47
+
48
+ # NOTE if there are totalHits, then use them, else use meta_hit_count. XTF gives a count for all hits when
49
+ # there are totalHits, but none at all when only metadata hits.
50
+ @meta_hit_count = doc_hit.search('//meta//hit').size rescue 0
51
+ @total_hits = doc_hit['totalHits'].to_i > 0 ? doc_hit['totalHits'] : @meta_hit_count.to_s
52
+ end
53
+
54
+ end
@@ -0,0 +1,61 @@
1
+ class XTF::Result::Element::DocHit
2
+
3
+ # require 'rubygems'
4
+ # require 'libxml_helper'
5
+ # require 'erb'
6
+ # include ERB::Util
7
+ # include ExportableDocument
8
+
9
+ attr_reader :xml,
10
+ :doc,
11
+ :rank,
12
+ :path,
13
+ :raw_path,
14
+ :score,
15
+ :total_hits,
16
+ :query,
17
+ :snippets,
18
+ :raw_snippets
19
+
20
+
21
+ # Converts +maxSnippets+ to a value of -1 (all), so that proper hit counts are shown
22
+ # in the XTF-rendered document. An instance variable is lazily loaded.
23
+ def query_with_all_snippets
24
+ self.query.gsub(/maxSnippets=("|')\d+("|')/, %Q{maxSnippets="-1"})
25
+ end
26
+
27
+ def initialize(xml, query_params="")
28
+ start = Time.now
29
+ parse_xml(xml, query_params)
30
+ yield self if block_given?
31
+ # RAILS_DEFAULT_LOGGER.debug("~~~~~ #{self.class.name} initialized in #{Time.now - start} seconds.")
32
+ end
33
+
34
+ def self.create(xml, query_params="")
35
+ new(xml.to_s, query_params)
36
+ end
37
+
38
+ def parse_xml(xml, query)
39
+ @xml = xml.to_s.gsub(/\s+/, " ").strip
40
+ @query = query
41
+ @doc = XML::Document.parse_string(xml).root
42
+ doc_hit = @doc.at('//docHit')
43
+ # meta = doc_hit.at('//meta')
44
+
45
+ @rank = doc_hit['rank']
46
+ @path = @raw_path = doc_hit['path']
47
+
48
+ @score = doc_hit['score']
49
+
50
+ # only retrieves the non-meta snippets
51
+ @snippets = @raw_snippets = @doc.search('//docHit/snippet').collect { |s| s.to_s }
52
+
53
+ # NOTE if there are totalHits, then use them, else use meta_hit_count. XTF gives a count for all hits when
54
+ # there are totalHits, but none at all when only metadata hits.
55
+ # NOTE some of the XTF devs argued against counting Meta Data Hits.
56
+ # @meta_hit_count = doc_hit.search('//meta//hit').size rescue 0
57
+ # @total_hits = doc_hit['totalHits'].to_i > 0 ? doc_hit['totalHits'] : @meta_hit_count.to_s
58
+ @total_hits = doc_hit['totalHits']
59
+ end
60
+
61
+ end
@@ -0,0 +1,29 @@
1
+ class XTF::Result::Element::Facet
2
+ # require 'rubygems'
3
+ # require 'libxml_helper'
4
+ attr_reader :query,
5
+ :field,
6
+ :total_groups,
7
+ :total_docs,
8
+ :groups
9
+
10
+ def initialize(xml=nil, search=nil)
11
+ start = Time.now
12
+ @groups = []
13
+ @query = query
14
+ parse_xml(xml) if xml
15
+ # RAILS_DEFAULT_LOGGER.debug("~~~~~ #{self.class.name} initialized #{@groups.size} hits in #{Time.now - start} seconds.")
16
+ end
17
+
18
+ # Parses the important bits out of the XTF search results using LibXML-Ruby.
19
+ def parse_xml(xml)
20
+ @xml = xml.to_s.squish #.gsub(/\s+/, " ").strip
21
+ @doc = XML::Document.parse_string(@xml).root
22
+ # the query metadata
23
+ @field = @doc.at('/facet')['field']
24
+ @total_groups = @doc.at('/facet')['totalGroups']
25
+ @total_docs = @doc.at('/facet')['totalDocs']
26
+
27
+ @groups = @doc.search('/facet/group').collect { |h| XTF::Result::Element::Group.new(h, @query) }.compact
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ class XTF::Result::Element::Group
2
+ # require 'rubygems'
3
+ # require 'libxml_helper'
4
+ attr_reader :query,
5
+ :value,
6
+ :total_sub_groups,
7
+ :total_docs,
8
+ :start_doc,
9
+ :end_doc,
10
+ :doc_hits
11
+
12
+ alias :hits :doc_hits
13
+
14
+ def initialize(xml=nil, query="")
15
+ start = Time.now
16
+ @doc_hits = []
17
+ @query = query
18
+ parse_xml(xml) if xml
19
+ # RAILS_DEFAULT_LOGGER.debug("~~~~~ #{self.class.name} initialized #{@doc_hits.size} hits in #{Time.now - start} seconds.")
20
+ end
21
+
22
+ # Parses the important bits out of the XTF search results using LibXML-Ruby.
23
+ def parse_xml(xml)
24
+ @xml = xml.to_s.squish #.gsub(/\s+/, " ").strip
25
+ @doc = XML::Document.parse_string(@xml).root
26
+
27
+ @value = @doc.at('/group')['value']
28
+ @total_sub_groups = @doc.at('/group')['totalSubGroups']
29
+ @total_docs = @doc.at('/group')['totalDocs']
30
+ @start_doc = @doc.at('/group')['startDoc']
31
+ @end_doc = @doc.at('/group')['endDoc']
32
+
33
+ ## TODO subgroups
34
+ @doc_hits = @doc.search('/group/docHit').collect { |h| XTF::Result::Element::DocHit.create(h, @query) }.compact
35
+ end
36
+
37
+ end