Hi list,
I’m new to ferret and I wonder what is the best way to search if I
know one fields id and want to search on its content.
I have experimented with FilteredQuery but I don’t know if this is
the best way.
Eg.
index = Index::Index.new(:path => ‘/tmp/all’)
@dbh = Database.instance.connect
result = @dbh.exec(“SELECT pk_fulltext_id, fulltext_text FROM
tbl_fulltext”)
result.each do |row|
#Inserting the PK id and text from DB
index << {:pk_fulltext_id => row[‘pk_fulltext_id’], :content => row
[‘fulltext_text’]}
end
content_query = Search::WildcardQuery.new(:content, “Text*”)
I know the ID of the text to search in so I want to do it efficient
id_filter = Search::QueryFilter.new(Search::TermQuery.new
(‘pk_fulltext_id’, ‘1257667’))
query = Search::FilteredQuery.new(content_query, id_filter)
index.search_each(query) do |id, score|
puts “Document #{id} found with a score of #{score}”
highlights = index.highlight(content_query, id,
:field => :content,
:pre_tag => “\033[36m”,
:post_tag => “\033[m”,
:excerpt_length => 100)
puts highlights
end
Please comment of this!
Can I make my database PK id to be the ferret document ID??
Would that speed it up?
Cheers,
Henrik