Ultrasphinx/TextHelper excerpt

Hi guys,

I have a problem with creating my views. I fetch results from
Ultrasphinx::Search#excerpt (Evan Weaver
fauna/ultrasphinx/classes/Ultrasphinx/Search.html#M000026).

The problem is that this method only highlights the results, without
actually cropping the unnecessary stuff left and right from the
searched words. A fragment from my config/environment.rb:

Ultrasphinx::Search.excerpting_options =
HashWithIndifferentAccess.new({
:before_match => ‘’,
:after_match => ‘
’,
:chunk_separator => “…”,
:limit => 256,
:around => 2, # This doesn’t seem to work
:content_methods => [‘search_content’]
})

The search_content method is in all searchable models, it returns all
the indexed fields concatenated together.

For example, if I looked for “foo” in a model, for which
search_content returns “this is a long foo sentence with some more of
this foo stuff”, running excerpt gives me:

  • actual: “this is a long foo sentence with some more
    of this foo stuff”
  • expected: “…a long foo sentence with … of this
    foo stuff”

Could someone help me on this?

Then, I fought of skipping Ultrasphinx’s excerpt, and manually replace
the unnecessary parts with ‘…’. Unfortunately TextHelper#excerpt
accepts only one string to excerpt, and I have an array of strings.

Is there some way to achieve what I need without struggling manually
with the strings/regexp/etc.?

I would really appreciate your help.


Bye,
Olek

I have the same problem. Will post more if I find something, others
please do the same.