Sha256: 1b7670ad0ccb6857e96f0cf977d1657b2b8e219c61e107bdeeb9d4730b9b73fd

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

#! /opt/ruby-1.8.1/bin/ruby -w
#
# Usage:
#  search.rb [--db /path/to/index/db] --index-dir dir/to/index
#  search.rb [--db /path/to/index/db] term1 term2 term3
#
# (Not yet implemented:)
#  search.rb [--db /path/to/index/db] --index-files file file file
#
require 'getoptlong'
require 'rsi'

gopt = GetoptLong.new()
gopt.set_options(
  [ '--index-dir', '-i', GetoptLong::REQUIRED_ARGUMENT],
  [ '--db', '-d', GetoptLong::REQUIRED_ARGUMENT]
)
# lame...
OPT = { '--db' => "/var/tmp/search" }
gopt.each_option {|opt, value| OPT[opt] = value }

indexer = RSI::Indexer.new( OPT['--db'] )
#indexer.serializer = RSI::YAMLSerializer.new()
#indexer.serializer = RSI::CompressedSerializer.new()
indexer.serializer = RSI::NativeSerializer.new() # default
indexer.open()

if OPT.has_key?( '--index-dir' )
  to_index = OPT['--index-dir']
  puts "Indexing #{to_index}..."
  Dir.foreach( to_index ) do |filename|
    next if filename =~ /^\./
    next if FileTest.directory?(filename)
    next if filename =~ /~$/

    fullpath = File.expand_path( File.join( to_index, filename ) )
    puts "...#{fullpath}"
    uri = fullpath
    contents = File.read( fullpath )
    indexer.add_document( uri, contents )
  end
  puts "Synching..."
  indexer.flush()
else
  query = ARGV.join(" ")
  puts "Query: #{query}"
  puts indexer.find_all( query )
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rsi-0.4 bin/rsi_search.rb