class Searcher

Searcher finds matches in a tree

It needs the tree root, and the data source used to make the tree This assumes the tree was made with a single data source.

“find” really should be finding matches from a different data source (not a string)

Public Class Methods

new(treeDataSource, treeRoot) click to toggle source
# File lib/search/searcher.rb, line 14
def initialize(treeDataSource, treeRoot)
  @dataSource = treeDataSource
  @root = treeRoot
end

Public Instance Methods

findAtLocation(location, s) click to toggle source

match a string starting at a specific location, returning the character depth of the resulting match

# File lib/search/searcher.rb, line 64
def findAtLocation(location, s)
  location.matchString(@dataSource, s)
  return location.depth
end
findNode(dataSource) click to toggle source
# File lib/search/searcher.rb, line 28
def findNode(dataSource)
  location = Location.new(@root)
  if (location.matchDataSource(@dataSource, dataSource).depth == dataSource.numberValues) then
    return location.node
  else
    return nil
  end
end
findResults(node) click to toggle source
# File lib/search/searcher.rb, line 51
def findResults(node)
  if (node != nil) then
    soCollector = SuffixOffsetVisitor.new
    so = BFS.new(soCollector)
    so.traverse(node)
    return soCollector.result.sort
  else
    return []
  end
end
findString(searchString) click to toggle source

returns the list of suffix offset values where the searchString has been found

# File lib/search/searcher.rb, line 40
def findString(searchString)
  node = self.findNode(StringDataSource.new(searchString))
  return self.findResults(node)
end
findWord(searchString) click to toggle source
# File lib/search/searcher.rb, line 46
def findWord(searchString)
  node = self.findNode(SingleWordDataSource.new(searchString))
  return self.findResults(node)
end
matchDataSource(dataSource) click to toggle source

match dataSource values, return location in the suffix tree where the match stopped

# File lib/search/searcher.rb, line 22
def matchDataSource(dataSource)
  location = Location.new(@root)
  location.matchDataSource(@dataSource, dataSource)
  location
end