StrIdx 0.1.4 → 0.1.5
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/Makefile +1 -0
- data/README.md +17 -3
- data/demo.cpp +36 -5
- data/exe/stridx.rb +6 -1
- data/flist.txt +0 -5550
- data/rubyext/ruby_interf.cpp +58 -2
- data/runserver.rb +20 -0
- data/server.rb +7 -2
- data/stridx.gemspec +1 -5
- data/stridx.hpp +411 -226
- data/thread_pool.hpp +20 -5
- data/unittest.cpp +58 -16
- metadata +3 -3
data/rubyext/ruby_interf.cpp
CHANGED
@@ -59,8 +59,8 @@ VALUE StringIndexFind(VALUE self, VALUE str) {
|
|
59
59
|
StrIdx::StringIndex *idx = (StrIdx::StringIndex *)data;
|
60
60
|
|
61
61
|
ret = rb_ary_new();
|
62
|
-
const std::vector<std::pair<float, int>> &results = idx->findSimilar(s1
|
63
|
-
int limit =
|
62
|
+
const std::vector<std::pair<float, int>> &results = idx->findSimilar(s1);
|
63
|
+
int limit = 40;
|
64
64
|
int i = 0;
|
65
65
|
for (const auto &res : results) {
|
66
66
|
VALUE arr = rb_ary_new();
|
@@ -75,6 +75,60 @@ VALUE StringIndexFind(VALUE self, VALUE str) {
|
|
75
75
|
return ret;
|
76
76
|
}
|
77
77
|
|
78
|
+
VALUE StringIndexFindFilesAndDirs(VALUE self, VALUE str) {
|
79
|
+
VALUE ret;
|
80
|
+
std::string s1 = StringValueCStr(str);
|
81
|
+
|
82
|
+
void *data;
|
83
|
+
TypedData_Get_Struct(self, int, &str_idx_type, data);
|
84
|
+
StrIdx::StringIndex *idx = (StrIdx::StringIndex *)data;
|
85
|
+
|
86
|
+
ret = rb_ary_new();
|
87
|
+
const std::vector<std::pair<float, std::string>> &results = idx->findFilesAndDirectories(s1);
|
88
|
+
int limit = 40;
|
89
|
+
int i = 0;
|
90
|
+
for (const auto &res : results) {
|
91
|
+
VALUE arr = rb_ary_new();
|
92
|
+
rb_ary_push(arr, rb_str_new_cstr(res.second.c_str()));
|
93
|
+
rb_ary_push(arr, DBL2NUM(res.first));
|
94
|
+
rb_ary_push(ret, arr);
|
95
|
+
i++;
|
96
|
+
if (i >= limit) {
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
return ret;
|
101
|
+
}
|
102
|
+
|
103
|
+
VALUE StringIndexFindDirs(VALUE self, VALUE str) {
|
104
|
+
VALUE ret;
|
105
|
+
std::string s1 = StringValueCStr(str);
|
106
|
+
|
107
|
+
void *data;
|
108
|
+
TypedData_Get_Struct(self, int, &str_idx_type, data);
|
109
|
+
StrIdx::StringIndex *idx = (StrIdx::StringIndex *)data;
|
110
|
+
|
111
|
+
ret = rb_ary_new();
|
112
|
+
const std::vector<std::pair<float, std::string>> &results = idx->findFilesAndDirectories(s1,false,true);
|
113
|
+
int limit = 40;
|
114
|
+
int i = 0;
|
115
|
+
for (const auto &res : results) {
|
116
|
+
VALUE arr = rb_ary_new();
|
117
|
+
rb_ary_push(arr, rb_str_new_cstr(res.second.c_str()));
|
118
|
+
rb_ary_push(arr, DBL2NUM(res.first));
|
119
|
+
rb_ary_push(ret, arr);
|
120
|
+
i++;
|
121
|
+
if (i >= limit) {
|
122
|
+
break;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return ret;
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
78
132
|
VALUE StringIndexSetDirSeparator(VALUE self, VALUE str) {
|
79
133
|
char c = '/';
|
80
134
|
if (TYPE(str) == T_STRING) {
|
@@ -104,6 +158,8 @@ void Init_stridx(void) {
|
|
104
158
|
rb_define_method(classStringIndex, "add", StringIndexAddSegments, 2);
|
105
159
|
rb_define_method(classStringIndex, "waitUntilDone", StringIndexWaitUntilDone, 0);
|
106
160
|
rb_define_method(classStringIndex, "find", StringIndexFind, 1);
|
161
|
+
rb_define_method(classStringIndex, "findFilesAndDirs", StringIndexFindFilesAndDirs, 1);
|
162
|
+
rb_define_method(classStringIndex, "findDirs", StringIndexFindDirs, 1);
|
107
163
|
|
108
164
|
rb_define_method(classStringIndex, "setDirSeparator", StringIndexSetDirSeparator, 1);
|
109
165
|
|
data/runserver.rb
CHANGED
@@ -1,7 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$:.unshift File.dirname(__FILE__)
|
3
3
|
|
4
|
+
def kill_signal
|
5
|
+
puts "\nShutting down..."
|
6
|
+
File.delete(File.expand_path("~/.stridx/sock"))
|
7
|
+
end
|
8
|
+
|
9
|
+
# https://gist.github.com/sauloperez/6592971
|
10
|
+
# Trap ^C
|
11
|
+
Signal.trap("INT") {
|
12
|
+
kill_signal
|
13
|
+
exit
|
14
|
+
}
|
15
|
+
|
16
|
+
# Trap `Kill `
|
17
|
+
Signal.trap("TERM") {
|
18
|
+
kill_signal
|
19
|
+
exit
|
20
|
+
}
|
21
|
+
|
4
22
|
require "server.rb"
|
5
23
|
# StrIdx::Server.start ARGV, daemonize: true
|
6
24
|
StrIdx::Server.start ARGV
|
7
25
|
|
26
|
+
|
27
|
+
|
data/server.rb
CHANGED
@@ -86,8 +86,12 @@ module StrIdx
|
|
86
86
|
# puts "Received from client: #{data}"
|
87
87
|
if data.match(/^find:(.*)/)
|
88
88
|
query = Regexp.last_match(1)
|
89
|
-
|
90
|
-
|
89
|
+
# TODO: not sure which is best as default:
|
90
|
+
# res = idx.find(query)
|
91
|
+
# res = idx.findDirs(query)
|
92
|
+
res = idx.findFilesAndDirs(query)
|
93
|
+
# response = res.collect { |x| flist[x[0]] }.join("\n")
|
94
|
+
response = res.collect { |x| "/"+x[0] }.join("\n")
|
91
95
|
|
92
96
|
# Send a response back to the client
|
93
97
|
client.puts response
|
@@ -98,6 +102,7 @@ module StrIdx
|
|
98
102
|
}
|
99
103
|
|
100
104
|
t.join
|
105
|
+
File.delete(sockfn)
|
101
106
|
end
|
102
107
|
end
|
103
108
|
end
|
data/stridx.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "StrIdx"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.5"
|
4
4
|
spec.authors = ["Sami Sieranoja"]
|
5
5
|
spec.email = ["sami.sieranoja@gmail.com"]
|
6
6
|
|
@@ -13,10 +13,6 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
14
14
|
f.match(%r{^(refcode|spec|features)/})
|
15
15
|
end
|
16
|
-
# spec.files << "thread_pool.hpp"
|
17
|
-
# spec.files << "exe/stridx.rb"
|
18
|
-
# spec.files << "server.rb"
|
19
|
-
# spec.files << "stridx-tty.rb"
|
20
16
|
|
21
17
|
spec.bindir = "exe"
|
22
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|