AAF and DRb with highlighting

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

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs