fastri 0.2.0.1 → 0.2.1.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.
- data/CHANGES +11 -0
- data/bin/fri +107 -43
- data/bin/ri-emacs +1 -1
- data/lib/fastri/full_text_indexer.rb +1 -1
- data/lib/fastri/ri_service.rb +10 -0
- data/lib/fastri/util.rb +22 -5
- data/lib/fastri/version.rb +4 -4
- data/test/test_full_text_indexer.rb +1 -1
- data/test/test_integration_full_text_index.rb +2 -2
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
|
2
2
|
User-visible changes in FastRI
|
3
3
|
|
4
|
+
Since version 0.2.0 (2006-11-15)
|
5
|
+
================================
|
6
|
+
Features
|
7
|
+
--------
|
8
|
+
* fri will use a pager in full-text search mode, and also when asked to
|
9
|
+
(-P, -T, --[no-]pager, --pager-cmd)
|
10
|
+
* multiple queries supported: fri upcase downcase
|
11
|
+
* fri -S is 100ms faster since it avoids requiring rubygems.rb
|
12
|
+
* list all classes/modules and methods with --classes and --methods, and both
|
13
|
+
with --list-names (-l)
|
14
|
+
|
4
15
|
Since version 0.1.1 (2006-11-10)
|
5
16
|
================================
|
6
17
|
Features
|
data/bin/fri
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
# Copyright (C) 2006 Mauricio Fernandez <mfp@acm.org>
|
4
4
|
#
|
5
5
|
|
6
|
-
require 'rinda/ring'
|
7
6
|
require 'optparse'
|
8
7
|
require 'fastri/util'
|
9
8
|
require 'fastri/full_text_index'
|
@@ -31,6 +30,10 @@ options = {
|
|
31
30
|
:show_matches => false,
|
32
31
|
:do_full_text => false,
|
33
32
|
:full_text_dir => File.join(FastRI::Util.find_home, ".fastri-fulltext"),
|
33
|
+
:use_pager => nil,
|
34
|
+
:pager => nil,
|
35
|
+
:list_classes => nil,
|
36
|
+
:list_methods => nil,
|
34
37
|
}
|
35
38
|
override_addr_env = false
|
36
39
|
optparser = OptionParser.new do |opts|
|
@@ -57,14 +60,32 @@ optparser = OptionParser.new do |opts|
|
|
57
60
|
|
58
61
|
opts.on("--show-matches", "Only show matching entries."){ options[:show_matches] = true }
|
59
62
|
|
63
|
+
opts.on("--classes", "List all known classes/modules.") do
|
64
|
+
options[:use_pager] = true
|
65
|
+
options[:list_classes] = true
|
66
|
+
end
|
67
|
+
opts.on("--methods", "List all known methods.") do
|
68
|
+
options[:use_pager] = true
|
69
|
+
options[:list_methods] = true
|
70
|
+
end
|
71
|
+
opts.on("-l", "--list-names", "List all known namespaces/methods.") do
|
72
|
+
options[:use_pager] = true
|
73
|
+
options[:list_classes] = true
|
74
|
+
options[:list_methods] = true
|
75
|
+
end
|
76
|
+
|
60
77
|
opts.on("-S", "--full-text", "Perform full-text search.") do
|
61
78
|
options[:do_full_text] = true
|
79
|
+
options[:use_pager] = true if options[:use_pager].nil?
|
80
|
+
options[:format] = "plain"
|
62
81
|
end
|
63
82
|
|
64
83
|
opts.on("-F", "--full-text-dir DIR", "Use full-text index in DIR",
|
65
84
|
"(default: #{options[:full_text_dir]})") do |dir|
|
66
85
|
options[:full_text_dir] = dir if dir
|
67
86
|
options[:do_full_text] = true
|
87
|
+
options[:use_pager] = true
|
88
|
+
options[:format] = "plain"
|
68
89
|
end
|
69
90
|
|
70
91
|
opts.on("-f", "--format FMT", "Format to use when displaying output:",
|
@@ -72,6 +93,19 @@ optparser = OptionParser.new do |opts|
|
|
72
93
|
options[:format] = format
|
73
94
|
end
|
74
95
|
|
96
|
+
opts.on("-P", "--[no-]pager", "Use pager.", "(default: don't)") do |usepager|
|
97
|
+
options[:use_pager] = usepager
|
98
|
+
options[:format] = "plain" if usepager
|
99
|
+
end
|
100
|
+
|
101
|
+
opts.on("-T", "Don't use a pager."){ options[:use_pager] = false }
|
102
|
+
|
103
|
+
opts.on("--pager-cmd PAGER", "Use pager PAGER.", "(default: don't)") do |pager|
|
104
|
+
options[:pager] = pager
|
105
|
+
options[:use_pager] = true
|
106
|
+
options[:format] = "plain"
|
107
|
+
end
|
108
|
+
|
75
109
|
opts.on("-w", "--width WIDTH", "Set the width of the output.") do |width|
|
76
110
|
w = width.to_i
|
77
111
|
options[:width] = w > 0 ? w : options[:width]
|
@@ -84,7 +118,7 @@ optparser = OptionParser.new do |opts|
|
|
84
118
|
end
|
85
119
|
optparser.parse!
|
86
120
|
|
87
|
-
if ARGV.empty?
|
121
|
+
if !options[:list_classes] && !options[:list_methods] && ARGV.empty?
|
88
122
|
puts optparser
|
89
123
|
exit
|
90
124
|
end
|
@@ -122,43 +156,7 @@ def magic_help(query)
|
|
122
156
|
query
|
123
157
|
end
|
124
158
|
end
|
125
|
-
help_query = magic_help(ARGV[0])
|
126
|
-
|
127
|
-
#{{{ determine the address to bind to
|
128
|
-
if override_addr_env
|
129
|
-
addr_spec = options[:addr]
|
130
|
-
else
|
131
|
-
addr_spec = ENV["FASTRI_ADDR"] || options[:addr]
|
132
|
-
end
|
133
|
-
|
134
|
-
ip = addr_spec[/^[^:]+/] || "127.0.0.1"
|
135
|
-
port = addr_spec[/:(\d+)/, 1] || 0
|
136
|
-
addr = "druby://#{ip}:#{port}"
|
137
|
-
|
138
|
-
#{{{ start DRb and perform request
|
139
|
-
begin
|
140
|
-
DRb.start_service(addr)
|
141
|
-
ring_server = Rinda::RingFinger.primary
|
142
|
-
rescue Exception
|
143
|
-
puts <<EOF
|
144
|
-
Couldn't initialize DRb and locate the Ring server.
|
145
159
|
|
146
|
-
Please make sure that:
|
147
|
-
* the fastri-server is running, the server is bound to the correct interface,
|
148
|
-
and the ACL setup allows connections from this host
|
149
|
-
* fri is using the correct interface for incoming DRb requests:
|
150
|
-
either set the FASTRI_ADDR environment variable, or use --bind ADDR, e.g
|
151
|
-
export FASTRI_ADDR="192.168.1.12"
|
152
|
-
fri Array
|
153
|
-
EOF
|
154
|
-
exit(-1)
|
155
|
-
end
|
156
|
-
service = ring_server.read([:name, :FastRI, nil, nil])[2]
|
157
|
-
info_options = {
|
158
|
-
:formatter => options[:format],
|
159
|
-
:width => options[:width],
|
160
|
-
:lookup_order => options[:lookup_order],
|
161
|
-
}
|
162
160
|
|
163
161
|
MAX_CONTEXT_LINES = 20
|
164
162
|
def context_wrap(text, width)
|
@@ -197,7 +195,7 @@ def display_fulltext_search_results(results, gem_dir_info = FastRI::Util.gem_dir
|
|
197
195
|
puts
|
198
196
|
end
|
199
197
|
|
200
|
-
|
198
|
+
def perform_fulltext_search(options)
|
201
199
|
fulltext = File.join(options[:full_text_dir], "full_text.dat")
|
202
200
|
suffixes = File.join(options[:full_text_dir], "suffixes.dat")
|
203
201
|
begin
|
@@ -231,8 +229,9 @@ EOF
|
|
231
229
|
puts "nil"
|
232
230
|
else
|
233
231
|
puts "#{paths.size} hits"
|
234
|
-
paths.sort_by{|path| -path_map[path].size}.map do |path|
|
232
|
+
paths.sort_by{|path| 1.0 * -path_map[path].size / path_map[path].first.metadata[:size] ** 0.5}.map do |path|
|
235
233
|
puts "=" * options[:width]
|
234
|
+
puts 1.0 * path_map[path].size / path_map[path].first.metadata[:size] ** 0.5
|
236
235
|
display_fulltext_search_results(path_map[path], gem_dir_info, options[:width])
|
237
236
|
end
|
238
237
|
end
|
@@ -240,9 +239,74 @@ EOF
|
|
240
239
|
exit 0
|
241
240
|
end
|
242
241
|
|
243
|
-
|
244
|
-
|
242
|
+
#{{{ set up pager
|
243
|
+
if options[:use_pager]
|
244
|
+
[options[:pager], ENV["PAGER"], "less", "more", "pager"].compact.uniq.each do |pager|
|
245
|
+
begin
|
246
|
+
$stdout = IO.popen(pager, "w")
|
247
|
+
at_exit{ $stdout.close }
|
248
|
+
break
|
249
|
+
rescue Exception
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
#{{{ perform full text search if asked to
|
255
|
+
perform_fulltext_search(options) if options[:do_full_text]
|
256
|
+
|
257
|
+
#{{{ normal query
|
258
|
+
require 'rinda/ring'
|
259
|
+
|
260
|
+
|
261
|
+
#{{{ determine the address to bind to
|
262
|
+
if override_addr_env
|
263
|
+
addr_spec = options[:addr]
|
245
264
|
else
|
246
|
-
|
265
|
+
addr_spec = ENV["FASTRI_ADDR"] || options[:addr]
|
266
|
+
end
|
267
|
+
|
268
|
+
ip = addr_spec[/^[^:]+/] || "127.0.0.1"
|
269
|
+
port = addr_spec[/:(\d+)/, 1] || 0
|
270
|
+
addr = "druby://#{ip}:#{port}"
|
271
|
+
|
272
|
+
#{{{ start DRb and perform request
|
273
|
+
begin
|
274
|
+
DRb.start_service(addr)
|
275
|
+
ring_server = Rinda::RingFinger.primary
|
276
|
+
rescue Exception
|
277
|
+
$stderr.puts <<EOF
|
278
|
+
Couldn't initialize DRb and locate the Ring server.
|
279
|
+
|
280
|
+
Please make sure that:
|
281
|
+
* the fastri-server is running, the server is bound to the correct interface,
|
282
|
+
and the ACL setup allows connections from this host
|
283
|
+
* fri is using the correct interface for incoming DRb requests:
|
284
|
+
either set the FASTRI_ADDR environment variable, or use --bind ADDR, e.g
|
285
|
+
export FASTRI_ADDR="192.168.1.12"
|
286
|
+
fri Array
|
287
|
+
EOF
|
288
|
+
exit(-1)
|
289
|
+
end
|
290
|
+
service = ring_server.read([:name, :FastRI, nil, nil])[2]
|
291
|
+
info_options = {
|
292
|
+
:formatter => options[:format],
|
293
|
+
:width => options[:width],
|
294
|
+
:lookup_order => options[:lookup_order],
|
295
|
+
}
|
296
|
+
|
297
|
+
# {{{ list classes or methods
|
298
|
+
puts service.all_classes if options[:list_classes]
|
299
|
+
puts service.all_methods if options[:list_methods]
|
300
|
+
exit if options[:list_classes] || options[:list_methods]
|
301
|
+
|
302
|
+
# {{{ normal query
|
303
|
+
|
304
|
+
ARGV.each do |term|
|
305
|
+
help_query = magic_help(term)
|
306
|
+
if options[:show_matches]
|
307
|
+
puts service.matches(help_query, info_options).sort
|
308
|
+
else
|
309
|
+
puts service.info(help_query, info_options)
|
310
|
+
end
|
247
311
|
end
|
248
312
|
# vi: set sw=2 expandtab:
|
data/bin/ri-emacs
CHANGED
data/lib/fastri/ri_service.rb
CHANGED
@@ -256,6 +256,16 @@ class RiService
|
|
256
256
|
r ? r.map{|x| x.gsub(/\./, "::")} : nil
|
257
257
|
end
|
258
258
|
|
259
|
+
# Return array of strings with the names of all known methods.
|
260
|
+
def all_methods
|
261
|
+
@ri_reader.full_method_names
|
262
|
+
end
|
263
|
+
|
264
|
+
# Return array of strings with the names of all known classes.
|
265
|
+
def all_classes
|
266
|
+
@ri_reader.full_class_names
|
267
|
+
end
|
268
|
+
|
259
269
|
private
|
260
270
|
|
261
271
|
def obtain_unqualified_method_entries(name, separators, order)
|
data/lib/fastri/util.rb
CHANGED
@@ -1,11 +1,28 @@
|
|
1
1
|
# Copyright (C) 2006 Mauricio Fernandez <mfp@acm.org>
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
# emulate rubygems.rb and define Gem.path if not loaded
|
4
|
+
# This is much faster than requiring rubygems.rb, which loads way too much
|
5
|
+
# stuff.
|
6
|
+
unless defined? ::Gem
|
7
|
+
require 'rbconfig'
|
8
|
+
module Gem
|
9
|
+
def self.path
|
10
|
+
ENV['GEM_HOME'] || default_dir
|
11
|
+
end
|
12
|
+
def self.default_dir
|
13
|
+
if defined? RUBY_FRAMEWORK_VERSION
|
14
|
+
return File.join(File.dirname(Config::CONFIG["sitedir"]), "Gems")
|
15
|
+
else
|
16
|
+
File.join(Config::CONFIG['libdir'], 'ruby', 'gems', Config::CONFIG['ruby_version'])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
7
20
|
end
|
8
|
-
|
21
|
+
# don't let rdoc/ri/ri_paths load rubygems.rb, that takes ~100ms !
|
22
|
+
emulation = $".all?{|x| /rubygems\.rb$/ !~ x} # 1.9 compatibility
|
23
|
+
$".unshift "rubygems.rb" if emulation
|
24
|
+
require 'rdoc/ri/ri_paths'
|
25
|
+
$".delete "rubygems.rb" if emulation
|
9
26
|
require 'rdoc/ri/ri_writer'
|
10
27
|
|
11
28
|
module FastRI
|
data/lib/fastri/version.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
#
|
3
3
|
|
4
4
|
module FastRI
|
5
|
-
FASTRI_VERSION = "0.2.
|
6
|
-
FASTRI_RELEASE_DATE = "2006-11-
|
5
|
+
FASTRI_VERSION = "0.2.1"
|
6
|
+
FASTRI_RELEASE_DATE = "2006-11-23"
|
7
7
|
FASTRI_INDEX_FORMAT = "0.1.0"
|
8
|
-
FASTRI_FT_INDEX_FORMAT = "
|
9
|
-
FASTRI_FT_INDEX_FORMAT_MAJOR = "
|
8
|
+
FASTRI_FT_INDEX_FORMAT = "1.0.0"
|
9
|
+
FASTRI_FT_INDEX_FORMAT_MAJOR = "1"
|
10
10
|
FASTRI_FT_INDEX_FORMAT_MINOR = "0"
|
11
11
|
FASTRI_FT_INDEX_FORMAT_TEENY = "0"
|
12
12
|
end
|
@@ -53,7 +53,7 @@ EOF
|
|
53
53
|
fulltext = StringIO.new("")
|
54
54
|
suffixarray = StringIO.new("")
|
55
55
|
@indexer.build_index(fulltext, suffixarray)
|
56
|
-
assert_equal(["\000\
|
56
|
+
assert_equal(["\000\027\000\000\000foo.txt\000\004\b{\006:\tsizei\002\230:\000"],
|
57
57
|
fulltext.string[-200..-1].scan(/\0.*$/))
|
58
58
|
assert_equal(4000 * 4, suffixarray.string.size)
|
59
59
|
end
|
@@ -37,7 +37,7 @@ class TestIntegrationFullTextIndex < Test::Unit::TestCase
|
|
37
37
|
index = get_index
|
38
38
|
assert_equal("first.txt", index.lookup("foo").path)
|
39
39
|
assert_equal("second.doc", index.lookup("bar").path)
|
40
|
-
assert_equal({:foo=>"baz", :type=>"text/plain"}, index.lookup("foo").metadata)
|
41
|
-
assert_equal({:bar=>"foo", :type=>"application/msword"}, index.lookup("bar").metadata)
|
40
|
+
assert_equal({:foo=>"baz", :type=>"text/plain", :size => 31}, index.lookup("foo").metadata)
|
41
|
+
assert_equal({:bar=>"foo", :type=>"application/msword", :size => 32}, index.lookup("bar").metadata)
|
42
42
|
end
|
43
43
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: fastri
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2006-11-
|
6
|
+
version: 0.2.1.1
|
7
|
+
date: 2006-11-23 00:00:00 +01:00
|
8
8
|
summary: RI docs across machines, faster and smarter than ri.
|
9
9
|
require_paths:
|
10
10
|
- lib
|