Carl Youngblood
2005-Dec-14 04:25 UTC
[Ferret-talk] Is it possible to highlight search keywords in results?
I''m wondering if ferret has any built-in search/replace mechanism that I might be able to use to highlight the query data in each search result. The reason I think this would be a good idea is that I could end up having to practically duplicate the ferret query parser just to interpret the query so that I can figure out how to highlight the keywords in the search results. Just in case I''m not making sense, here is an example of what I want: query = ''contents:"testing|trucks"'' prepend = ''<strong>'' append = ''</strong>'' count = index.search_each(query) do |doc, score| highlighted_contents index.highlight_for_query(doc, query, prepend, append) puts highlighted_contents end This would make all instances of "testing" and "trucks" appear in bold for html formatted text. Thoughts? Thanks, Carl
David Balmain
2005-Dec-14 04:51 UTC
[Ferret-talk] Is it possible to highlight search keywords in results?
There is a highlighter for Lucene in the Lucene sandbox. You can have a look at it and try porting it to Ruby if you like. If you can wait a month or two I''ll do it myself. http://svn.apache.org/repos/asf/lucene/java/trunk/contrib/highlighter/ On 12/14/05, Carl Youngblood <carl at youngbloods.org> wrote:> I''m wondering if ferret has any built-in search/replace mechanism that > I might be able to use to highlight the query data in each search > result. The reason I think this would be a good idea is that I could > end up having to practically duplicate the ferret query parser just to > interpret the query so that I can figure out how to highlight the > keywords in the search results. Just in case I''m not making sense, > here is an example of what I want: > > query = ''contents:"testing|trucks"'' > prepend = ''<strong>'' > append = ''</strong>'' > count = index.search_each(query) do |doc, score| > highlighted_contents > index.highlight_for_query(doc, query, prepend, append) > puts highlighted_contents > end > > This would make all instances of "testing" and "trucks" appear in bold > for html formatted text. Thoughts? > > Thanks, > Carl > > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk >
Carl Youngblood
2005-Dec-14 05:35 UTC
[Ferret-talk] Is it possible to highlight search keywords in results?
Sounds like a good idea. I have bigger fish to fry right now but I may get around to it if my search queries get hairier. Right now a quick and dirty solution is working okay for me. Thanks, Carl On 12/13/05, David Balmain <dbalmain.ml at gmail.com> wrote:> There is a highlighter for Lucene in the Lucene sandbox. You can have > a look at it and try porting it to Ruby if you like. If you can wait a > month or two I''ll do it myself.
Erik Hatcher
2005-Dec-14 11:56 UTC
[Ferret-talk] Is it possible to highlight search keywords in results?
The Highlighter is cool, but does have some drawbacks. First, it''s advantages.... you can easily get the terms for a Query and then do some substitutions in the original document, but Highlighter actually picks out the bet fragments to show. It''s disadvantage is that it only highlights the terms of the query. For example, if you search for "some phrase", any occurrence of the word "some" is highlighted, even if it is not followed by "phrase". More visually, here''s how it comes out: http://www.lucenebook.com/search?query=%22term+positions%22 It would be sweet to have a Ruby highlighter. I''ve done work in Java for a consulting client to convert a Query into a SpanQuery and have created a non-generalizable highlighter (does not fragment, currently) that highlights very precisely, so it is possible, just not trivial. Erik On Dec 13, 2005, at 11:51 PM, David Balmain wrote:> There is a highlighter for Lucene in the Lucene sandbox. You can have > a look at it and try porting it to Ruby if you like. If you can wait a > month or two I''ll do it myself. > > http://svn.apache.org/repos/asf/lucene/java/trunk/contrib/highlighter/ > > On 12/14/05, Carl Youngblood <carl at youngbloods.org> wrote: >> I''m wondering if ferret has any built-in search/replace mechanism >> that >> I might be able to use to highlight the query data in each search >> result. The reason I think this would be a good idea is that I could >> end up having to practically duplicate the ferret query parser >> just to >> interpret the query so that I can figure out how to highlight the >> keywords in the search results. Just in case I''m not making sense, >> here is an example of what I want: >> >> query = ''contents:"testing|trucks"'' >> prepend = ''<strong>'' >> append = ''</strong>'' >> count = index.search_each(query) do |doc, score| >> highlighted_contents >> index.highlight_for_query(doc, query, prepend, append) >> puts highlighted_contents >> end >> >> This would make all instances of "testing" and "trucks" appear in >> bold >> for html formatted text. Thoughts? >> >> Thanks, >> Carl >> >> _______________________________________________ >> Ferret-talk mailing list >> Ferret-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ferret-talk >> > > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk
David Balmain
2005-Dec-14 12:26 UTC
[Ferret-talk] Is it possible to highlight search keywords in results?
On 12/14/05, Erik Hatcher <erik at ehatchersolutions.com> wrote:> The Highlighter is cool, but does have some drawbacks. First, it''s > advantages.... you can easily get the terms for a Query and then do > some substitutions in the original document, but Highlighter actually > picks out the bet fragments to show. It''s disadvantage is that it > only highlights the terms of the query. For example, if you search > for "some phrase", any occurrence of the word "some" is highlighted, > even if it is not followed by "phrase". More visually, here''s how > it comes out: > > http://www.lucenebook.com/search?query=%22term+positions%22 > > It would be sweet to have a Ruby highlighter. I''ve done work in Java > for a consulting client to convert a Query into a SpanQuery and have > created a non-generalizable highlighter (does not fragment, > currently) that highlights very precisely, so it is possible, just > not trivial.Not trivial. Sounds like a challenge. I like the sound of that. :P> > Erik