Class: Xapit::Server::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/xapit/server/database.rb

Constant Summary collapse

COMMANDS =
%w[query add_document remove_document update_document spelling_suggestion]

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Database

Returns a new instance of Database.



6
7
8
# File 'lib/xapit/server/database.rb', line 6

def initialize(path)
  @path = path
end

Instance Method Details

#add_document(data) ⇒ Object



14
15
16
# File 'lib/xapit/server/database.rb', line 14

def add_document(data)
  xapian_database.add_document(Indexer.new(data).document)
end

#query(data) ⇒ Object



27
28
29
# File 'lib/xapit/server/database.rb', line 27

def query(data)
  Query.new(data).data
end

#remove_document(data) ⇒ Object



18
19
20
# File 'lib/xapit/server/database.rb', line 18

def remove_document(data)
  xapian_database.delete_document(Indexer.new(data).id_term)
end

#spelling_suggestion(data) ⇒ Object



31
32
33
# File 'lib/xapit/server/database.rb', line 31

def spelling_suggestion(data)
  Query.new(data).spelling_suggestion
end

#update_document(data) ⇒ Object



22
23
24
25
# File 'lib/xapit/server/database.rb', line 22

def update_document(data)
  indexer = Indexer.new(data)
  xapian_database.replace_document(indexer.id_term, indexer.document)
end

#xapian_databaseObject



10
11
12
# File 'lib/xapit/server/database.rb', line 10

def xapian_database
  @xapian_database ||= load_database
end