wgit 0.10.3 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 720cf6b84698fbd54c109319f05557ee2e29bdbda59ec23278422dc5ddc77f2f
4
- data.tar.gz: d4304bce849b404b9d2d7faa4d9a3f7969784f649a83152605b51b2e0bd21ac4
3
+ metadata.gz: 13a092ae05f0338598d0cc26d85ed828a86d60240eb996bacdbd7511aaae25a2
4
+ data.tar.gz: 3835b8aa3c06d49c1230dd42316c30315e39b0b33f0c433ff8df60eb6be2ecaa
5
5
  SHA512:
6
- metadata.gz: a8743ec17b3caaa9b6c5dd5c9b9b18902561927dfd992003f25db88334cc2b4364a4c6ce2dea34629f801d5d7dbe9761b15e7f2f034e00ba526db36ce828dcaf
7
- data.tar.gz: 00cf954a86c8b0d96f2e694359c1c75e3193e0e6d146ffba19b3857bef4c15ca93d25f1310ebebf815de8da93ede1b97e325dc54aade699219b9ab35f2976e49
6
+ metadata.gz: 41a88d424925e3ba670104e69d027a5656c66616ab59bc85c62ec3359afd78230073e5a8f50697cbfc553b8dc9a012cf2ad2f2d857f7840fc668e0e43cdbfb33
7
+ data.tar.gz: 17bd6ddaba4cb53bd5cff4f9b36d5930f4bf496ee588163d190e10274438844f1a5e764c08fc7f82dc6c5c6b2efebaa52dc624be134e38a7d9d3ff9b970d1430
data/CHANGELOG.md CHANGED
@@ -9,6 +9,15 @@
9
9
  - ...
10
10
  ---
11
11
 
12
+ ## v0.10.4
13
+ ### Added
14
+ - `Database#search_text` method which returns a Hash of `url => text_results` instead of `Wgit::Documents` (like `#search`).
15
+ ### Changed/Removed
16
+ - ...
17
+ ### Fixed
18
+ - ...
19
+ ---
20
+
12
21
  ## v0.10.3
13
22
  ### Added
14
23
  - ...
@@ -348,6 +348,58 @@ module Wgit
348
348
  results
349
349
  end
350
350
 
351
+ # Searches the database's Documents for the given query and then searches
352
+ # each result in turn using `doc.search`. Instead of an Array of Documents,
353
+ # this method returns a Hash of the docs url => search_results creating a
354
+ # search engine like result set for quick access to text matches.
355
+ #
356
+ # @param query [String] The text query to search with.
357
+ # @param case_sensitive [Boolean] Whether character case must match.
358
+ # @param whole_sentence [Boolean] Whether multiple words should be searched
359
+ # for separately.
360
+ # @param limit [Integer] The max number of results to return.
361
+ # @param skip [Integer] The number of results to skip.
362
+ # @param sentence_limit [Integer] The max length of each search result
363
+ # sentence.
364
+ # @param top_result_only [Boolean] Whether to return all of the documents
365
+ # search results or just the top (most relavent) result.
366
+ # @yield [doc] Given each search result (Wgit::Document) returned from the
367
+ # DB.
368
+ # @return [Hash<String, String | Array<String>>] The search results obtained
369
+ # from the DB having mapped the docs url => search_results. The format of
370
+ # search_results depends on the value of `top_result_only`.
371
+ def search_text(
372
+ query, case_sensitive: false, whole_sentence: true,
373
+ limit: 10, skip: 0, sentence_limit: 80, top_result_only: false
374
+ )
375
+ results = search(
376
+ query,
377
+ case_sensitive: case_sensitive,
378
+ whole_sentence: whole_sentence,
379
+ limit: limit,
380
+ skip: skip
381
+ )
382
+
383
+ results
384
+ .map do |doc|
385
+ yield(doc) if block_given?
386
+
387
+ results = doc.search(
388
+ query,
389
+ case_sensitive: case_sensitive,
390
+ whole_sentence: whole_sentence,
391
+ sentence_limit: sentence_limit
392
+ )
393
+
394
+ # Only return result if its text has a match - compact is called below.
395
+ next nil if results.empty?
396
+
397
+ [doc.url, (top_result_only ? results.first : results)]
398
+ end
399
+ .compact
400
+ .to_h
401
+ end
402
+
351
403
  # Returns statistics about the database.
352
404
  #
353
405
  # @return [BSON::Document#[]#fetch] Similar to a Hash instance.
data/lib/wgit/document.rb CHANGED
@@ -453,7 +453,7 @@ be relative"
453
453
 
454
454
  if query.is_a?(Regexp)
455
455
  regex = query
456
- else # respond_to? #to_s == true
456
+ else # query.respond_to? :to_s == true
457
457
  query = query.to_s
458
458
  query = query.gsub(' ', '|') unless whole_sentence
459
459
  regex = Regexp.new(query, !case_sensitive)
data/lib/wgit/version.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # @author Michael Telford
7
7
  module Wgit
8
8
  # The current gem version of Wgit.
9
- VERSION = '0.10.3'
9
+ VERSION = '0.10.4'
10
10
 
11
11
  # Returns the current gem version of Wgit as a String.
12
12
  def self.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Telford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-25 00:00:00.000000000 Z
11
+ date: 2021-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable