Skip to content

Commit

Permalink
adding index blueprint method to fetch document given member
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Mar 10, 2009
1 parent 2c60321 commit 498fb9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/xapit/index_blueprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ def facet(*attributes)
field(*attributes)
end

def document_for(member)
document = Xapian::Document.new
document.data = "#{member.class}-#{member.id}"
terms(member).each do |term|
document.add_term(term)
end
values(member).each_with_index do |value, index|
document.add_value(index, value)
end
document
end

def stripped_words(content)
content.to_s.downcase.scan(/[a-z0-9]+/)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/xapit/index_blueprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@
@index.facet(:foo)
@index.field_terms(member).should == %w[Xfoo-abc]
end

it "should add terms and values to xapian document" do
member = Object.new
stub(member).id { 123 }
stub(@index).values { %w[value list] }
stub(@index).terms { %w[term list] }
doc = @index.document_for(member)
doc.should be_kind_of(Xapian::Document)
doc.data.should == "Object-123"
doc.values.map(&:value).sort.should == %w[value list].sort
doc.terms.map(&:term).sort.should == %w[term list].sort
end
end

0 comments on commit 498fb9c

Please sign in to comment.