shookach 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/shookach.rb +16 -4
- data/lib/shookach/indexer.rb +16 -8
- data/lib/shookach/railtie.rb +7 -0
- data/lib/tasks/shookach.rake +8 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10c53341d7bdb6158be1e5e5d86a4ad63593b76e2c2649a13f6e691edc919992
|
|
4
|
+
data.tar.gz: 90bf5ad2a2fa6b364b5f4ef4b83b7ed61eb4a7e33953173f3403ad17feb7ff92
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: efa4d6324507afafa2709502b166e83966036b2df56e220647d6c9fb0602e425a3ec75ec4bf36939f1d0e073c5e548813ce6e66152392ebe36456f79d71bdfe1
|
|
7
|
+
data.tar.gz: dc5eb5012eeb4a440954fb856ccc6a6b84f1aab4b25030d19c77d8cad7b7eac2052101ee2915acc96d764d4d9b1c9c41fdefc42d8f9a925134ac335637028f12
|
data/lib/shookach.rb
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require '
|
|
1
|
+
require 'shookach/indexer'
|
|
2
|
+
require 'shookach/searcher'
|
|
3
|
+
require 'shookach/railtie' if defined?(Rails)
|
|
3
4
|
|
|
4
5
|
class Shookach
|
|
5
|
-
def self.index(
|
|
6
|
-
|
|
6
|
+
def self.index(options = {})
|
|
7
|
+
@options = default_configs.merge(options)
|
|
8
|
+
|
|
9
|
+
Indexer.new(@options[:library_path], @options[:output_path]).call
|
|
7
10
|
end
|
|
8
11
|
|
|
9
12
|
def self.search
|
|
10
13
|
# @searcher.call
|
|
11
14
|
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def self.default_configs
|
|
19
|
+
{
|
|
20
|
+
library_path: './public/input/',
|
|
21
|
+
output_path: './public/output/'
|
|
22
|
+
}
|
|
23
|
+
end
|
|
12
24
|
end
|
data/lib/shookach/indexer.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class Indexer
|
|
2
|
-
def initialize(library_path)
|
|
3
|
-
@
|
|
4
|
-
|
|
2
|
+
def initialize(library_path, output_path)
|
|
3
|
+
@library_path = library_path
|
|
4
|
+
create_index_file(output_path)
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def call
|
|
@@ -12,20 +12,28 @@ class Indexer
|
|
|
12
12
|
|
|
13
13
|
private
|
|
14
14
|
|
|
15
|
+
def create_index_file(path)
|
|
16
|
+
Dir.mkdir(path) unless File.exists?(path)
|
|
17
|
+
|
|
18
|
+
@output_file = File.open("#{path}indexes#{Time.now.strftime('%Y%m%d%H%M%S')}.yml", 'w')
|
|
19
|
+
end
|
|
20
|
+
|
|
15
21
|
def write_dir_indexes
|
|
16
|
-
puts "
|
|
22
|
+
puts "Indexing directory: #{@library_path}"
|
|
17
23
|
|
|
18
|
-
Dir.foreach(@
|
|
24
|
+
Dir.foreach(@library_path) do |filename|
|
|
19
25
|
next if filename == '.' || filename == '..'
|
|
20
26
|
|
|
21
27
|
write_file_indexes(filename)
|
|
22
28
|
end
|
|
29
|
+
|
|
30
|
+
puts "Output file: #{@output_file.path}"
|
|
23
31
|
end
|
|
24
32
|
|
|
25
33
|
def write_file_indexes(filename)
|
|
26
|
-
puts "
|
|
34
|
+
puts "Indexing file: #{filename}"
|
|
27
35
|
|
|
28
|
-
@file = File.open("#{@
|
|
36
|
+
@file = File.open("#{@library_path}/#{filename}", 'r')
|
|
29
37
|
|
|
30
38
|
sentences_arr.each_with_index do |sentence, s_index|
|
|
31
39
|
words = sentence.split(' ')
|
|
@@ -39,6 +47,6 @@ class Indexer
|
|
|
39
47
|
end
|
|
40
48
|
|
|
41
49
|
def sentences_arr
|
|
42
|
-
@file.read().gsub(/\n|\r/, ' ').split(/\.\s*/)
|
|
50
|
+
@file.read().gsub(',', ' ').gsub(/\n|\r/, ' ').split(/\.\s*/)
|
|
43
51
|
end
|
|
44
52
|
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
namespace :shookach do
|
|
2
|
+
desc 'Index files'
|
|
3
|
+
task :index, [:input, :output] => :environment do |_t, args|
|
|
4
|
+
args.with_defaults(input: './public/input/', output: './public/output/')
|
|
5
|
+
|
|
6
|
+
Shookach.index({ library_path: args.input, output_path: args.output })
|
|
7
|
+
end
|
|
8
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shookach
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bohdan Chaban
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A simple gem for full-text search
|
|
14
14
|
email: b.chaban.91@gmail.com
|
|
@@ -18,7 +18,9 @@ extra_rdoc_files: []
|
|
|
18
18
|
files:
|
|
19
19
|
- lib/shookach.rb
|
|
20
20
|
- lib/shookach/indexer.rb
|
|
21
|
+
- lib/shookach/railtie.rb
|
|
21
22
|
- lib/shookach/searcher.rb
|
|
23
|
+
- lib/tasks/shookach.rake
|
|
22
24
|
homepage: http://rubygems.org/gems/shookach
|
|
23
25
|
licenses:
|
|
24
26
|
- MIT
|