Class: SwishE

Inherits:
Object
  • Object
show all
Includes:
SwishEWrapper
Defined in:
lib/swishe.rb

Overview

High Level class for using the Swish-e file indexer. This api is subject to change. Currently there is only limited searching available. If you just need to access the plain C API, you should look at the SwishEWrapper module.

Defined Under Namespace

Classes: IndexFileError, Result, SwishEError

Instance Method Summary collapse

Constructor Details

#initialize(indexfiles) ⇒ SwishE

Create a new instance of the Swish-e wrapper. Run query(string) to obtain the search results. Don’t forget to close the session, or you will lose file handles and enventually run into an error ‘too many open files’. You can use the block form that closes the session for you. indexfiles is an array of paths to index files or a string where the index files are separated by spaces.



99
100
101
102
103
104
105
106
# File 'lib/swishe.rb', line 99

def initialize(indexfiles)
  indexfiles = [indexfiles] if String===indexfiles 
  set_index(indexfiles.join(" "))
  if block_given?
    yield self
    close
  end
end

Instance Method Details

#closeObject

Does all necessary cleaning. Don’t forget to call this (or use the block form of ‘new’) when done.



110
111
112
# File 'lib/swishe.rb', line 110

def close
  swish_close(@handle)
end

#query(string) ⇒ Object

Return an Array of Result instances. Raises SwishEError if the



115
116
117
118
119
120
121
122
123
# File 'lib/swishe.rb', line 115

def query(string)
  res=swish_query(@handle,string)
  check_error
  results=[]
  while result=swish_next_result(res)
    results << Result.new(result)
  end
  return results
end