Class: ActiveRubinstein::LuceneSearcher

Inherits:
Base
  • Object
show all
Defined in:
lib/active_rubinstein/lucene_searcher.rb

Overview

A DRb object to jRubinstein#JenaLuc::Lucene or JenaLuc::GeoLucene

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#hello, #roll, set_language, #shuffle

Constructor Details

#initialize(lucene_branch = :standard) ⇒ LuceneSearcher

adds a Lucene engine to the server pool; the Lucene branch can be selected by the option

lucene_branch => :standard || :geolucene

currently GeoLucene is not used, as it fails to parse fuzzy searches.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_rubinstein/lucene_searcher.rb', line 50

def initialize( lucene_branch = :standard )
  case lucene_branch

  when :standard
    server = $serverPool[ :jena ].first
    unless server.ping
      @@log.error $!.message
    else
      @@lucene = server
      @@log.rubinstein "@@lucene = #{server.inspect}"
    end

  when :geolucene
    server = $serverPool[ :geolucene ].first
    unless server.ping
      @@log.error $!.message
    else
      @@geolucene = server
      @@log.rubinstein "@@geolucene = #{server.inspect}"
    end
  end
end

Instance Attribute Details

#languageObject

Returns the value of attribute language.



43
44
45
# File 'lib/active_rubinstein/lucene_searcher.rb', line 43

def language
  @language
end

Class Method Details

.do_log(*args) ⇒ Object

:nodoc:



165
166
167
# File 'lib/active_rubinstein/lucene_searcher.rb', line 165

def do_log(*args) # :nodoc:
  super
end

.execute(query, options) ⇒ Object

analyzes the query to find the correct method to execute. accepts queries of type Symbol, RDFS::Resource and String.

Parameters:

  • 1 query (Symbol, RDFS::Resource or String)

  • 2 options (Hash; …)



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/active_rubinstein/lucene_searcher.rb', line 82

def execute( query, options )

  @lucene = options[ :lucene_branch ] || :standard

  if query.is_a? Symbol or query.is_a? RDFS::Resource
    case query

    # look for geographically nearby resources
    when :nearby
      lat = options[ :lat ]
      long = options[ :long ]
      radius = options[ :radius ] || 1000
      resource = options[ :resource ]

      if resource # quick hack
        resource = RdfAbout.new( resource ) unless resource.is_a? RdfAbout
        lat = resource.lat
        long = resource.long
      end

      lat = lat.to_f unless lat.is_a? Float
      long = long.to_f unless long.is_a? Float
      radius = radius.to_i unless radius.is_a? Fixnum

      if lat and long
        return self.getNearbyTargets( lat, long, radius, options )
      end
    end

  elsif query.is_a? String
    options.update :indices => :full unless options.has_key? :indices
    return self.search( query, options )

  elsif query.is_a? Query
    @@log.info "Lucene cannot handle SPARQL queries yet."
    return nil

  else
    @@log.warn "Unfamiliar query (#{query}) to Lucene"
    return nil
  end
end

.method_missing(method, *args, &block) ⇒ Object

pretty much the most important method of all :) this method sends the request to Rubinstein’s DRb server.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/active_rubinstein/lucene_searcher.rb', line 150

def method_missing(method, *args, &block)
  @@log.rubinstein "sending the request to #{@@lucene}, method #{method}"

  @lucene ||= :standard
  case @lucene
  when :standard
    return @@lucene.send( method, *args, &block )
  when :geolucene
    return @@geolucene.send( method, *args, &block )
  else
    @@log.error "Unknown Lucene branch #{@lucene}"
    return Array.new
  end
end

.serverObject

returns the server object



140
141
142
143
144
145
146
# File 'lib/active_rubinstein/lucene_searcher.rb', line 140

def server
  if @@lucene
    return @@lucene
  elsif @@geolucene
    return @@geolucene
  end
end