# Ultrasphinx/TextHelper excerpt

**URL:** <https://www.ruby-forum.com/t/ultrasphinx-texthelper-excerpt/136856>\
**Category:** Rails\
**Created:** [May 6, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/ultrasphinx-texthelper-excerpt/136856 "2008-05-06T21:45:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@Olek](https://www.ruby-forum.com/u/Olek)\
**Post date:** [May 6, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/ultrasphinx-texthelper-excerpt/136856/1 "2008-05-06T21:45:59Z")

</div>

Hi guys,

I have a problem with creating my views. I fetch results from  
Ultrasphinx::Search#excerpt ([Evan Weaver](http://blog.evanweaver.com/files/doc/)  
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

---

<div class="post-metadata">

**Author:** ![Olek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@Olek](https://www.ruby-forum.com/u/Olek)\
**Post date:** [February 9, 2009, 12:49am UTC](https://www.ruby-forum.com/t/ultrasphinx-texthelper-excerpt/136856/2 "2009-02-09T00:49:55Z")

</div>

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