# AAF and DRb with highlighting

**URL:** <https://www.ruby-forum.com/t/aaf-and-drb-with-highlighting/113907>\
**Category:** Ferret\
**Created:** [September 6, 2007, 1:58am UTC](https://www.ruby-forum.com/t/aaf-and-drb-with-highlighting/113907 "2007-09-06T01:58:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![karlshea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/58956e/32.png) [@karlshea](https://www.ruby-forum.com/u/karlshea)\
**Post date:** [September 6, 2007, 1:58am UTC](https://www.ruby-forum.com/t/aaf-and-drb-with-highlighting/113907/1 "2007-09-06T01:58:05Z")

</div>

How would I change this method in order to get highlighting working with  
DRb? I’ve given up on searching on Google, I’m getting no results that  
are actually helpful.

def self.find\_storage\_by\_contents(query, options = {})  
# Get the index that acts\_as\_ferret created for us  
index = self.aaf\_index.ferret\_index

```
results = []

default_options = {:limit => 10, :page => 1}
options = default_options.merge options
options[:offset] = options[:limit] * (options[:page].to_i - 1)

# search_each is the core search function from Ferret, which

```

Acts\_as\_ferret hides  
total\_hits = index.search\_each(query, options) do |hit, score|  
doc = index[hit]  
result = {}

```
  article = Article.find(doc[:id])

  # Store each field in a hash which we can reference in our views
  result[:headline_highlight] = index.highlight(query, hit,
    :field => :headline,
    :pre_tag => "<strong>",
    :post_tag => "</strong>",
    :num_excerpts => 1)
  result[:body_highlight] = index.highlight(query, hit,
    :field => :body,
    :pre_tag => "<strong>",
    :post_tag => "</strong>",
    :num_excerpts => 1)
  result[:article] = article

  result[:score] = score

  results.push result
end unless query.nil?
return block_given? ? total_hits : [total_hits, results]

```

end

---

<div class="post-metadata">

**Author:** ![karlshea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/58956e/32.png) [@karlshea](https://www.ruby-forum.com/u/karlshea)\
**Post date:** [September 6, 2007, 2:36am UTC](https://www.ruby-forum.com/t/aaf-and-drb-with-highlighting/113907/2 "2007-09-06T02:36:27Z")

</div>

Ok, I think I’ve actually got it working:

def self.find\_storage\_by\_contents(query, options = {})  
results = []

```
default_options = {:limit => 10, :page => 1}
options = default_options.merge options
options[:offset] = options[:limit] * (options[:page].to_i - 1)

search = find_by_contents(query, options)
total_hits = search.total_hits

search.each do |hit|
  result = {}

  # Store each field in a hash which we can reference in our views
  result[:headline_highlight] = hit.highlight(query,
    :field => :headline,
    :pre_tag => "<strong>",
    :post_tag => "</strong>",
    :num_excerpts => 1)
  result[:body_highlight] = hit.highlight(query,
    :field => :body,
    :pre_tag => "<strong>",
    :post_tag => "</strong>",
    :num_excerpts => 1)
  result[:article] = hit

  results.push result
end unless query.nil?

return block_given? ? total_hits : [total_hits, results]

```

end

Is there anything in there that I’m not doing correctly?
