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
On Fri, Dec 01, 2006 at 02:52:31PM +0100, Henrik Zagerholm wrote:> 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.interesting question, but I''m afraid I can''t give a definite answer. I''d guess that all you can do is try out what is faster - the query filter or an added boolean clause in your query. In general I wouldn''t expect any speed difference in a query matching a single document issued with or without an additional clause matching the id field of that document. There will be some speed improvement if your query matches more documents, but mainly because you narrow the result set that Ferret has to return to down to one element, not because search is faster. Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66