Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set the XapianDoc id after adding to the XapianDb
Support passing a string to XapianDoc.new Improve initialization of XapianDoc
- Loading branch information
Showing
3 changed files
with
47 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
module XapianFu | ||
class XapianDoc | ||
attr_reader :fields, :data, :id | ||
def initialize(fields, options = {}) | ||
if fields.is_a?(Xapian::Document) | ||
attr_reader :fields, :data, :weight, :db | ||
attr_accessor :id | ||
def initialize(doc, options = {}) | ||
if doc.is_a?(Xapian::Document) | ||
@id = doc.docid | ||
# @weight = doc.weight | ||
begin | ||
xdoc = fields | ||
@data = Marshal::load(xdoc.data) unless xdoc.data.empty? | ||
@id = xdoc.docid | ||
@data = Marshal::load(doc.data) unless doc.data.empty? | ||
rescue ArgumentError | ||
@data = nil | ||
end | ||
elsif doc.respond_to?("[]") | ||
@fields = doc | ||
@id = doc[:id] if doc.respond_to?(:has_key?) and doc.has_key?(:id) | ||
else | ||
@fields = fields | ||
@id = fields[:id] if fields.has_key?(:id) | ||
@weight = options[:weight] if options[:weight] | ||
@data = options[:data] if options[:data] | ||
@fields = { :content => doc.to_s } | ||
end | ||
@weight = options[:weight] if options[:weight] | ||
@data = options[:data] if options[:data] | ||
end | ||
|
||
def terms | ||
db.terms(id) if db and id | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters