Tracking Solr Replication Delay via Scout or Sheriff

We now keep track of our solr replication delay, maybe you should too ;)

Works with scout-app or sheriff(free/self-hosted)

class SolrReplication < Scout::Plugin
  needs 'open-uri'

  OPTIONS=<<-EOS
    master:
      default: http://192.168.2.114:8983
    slave:
      default: http://localhost:8765
  EOS

  def build_report
    replication_path = '/solr/admin/replication/index.jsp'
    rex = /Generation: (\d+)/
    master = open(option(:master)+replication_path).read.match(rex)[1]
    slave = open(option(:slave)+replication_path).read.match(rex)[1]
    if master and slave
      report 'delay' => master.to_i - slave.to_i
    else
      error "Incorrect values found master:#{master} slave:#{slave}"
    end
  end
end

Negative queries with solr in multiple fields

We recently did some negative queries and had a lot of ‘fun’ with solr.
After reading/testing a bit we found a simple rule: negative queries for single words do not work (dont ask me why…), but it can be fixed with an additional *:*

Does not work: title: -xxx / (-title:xxx)

When you are only interested in certain fields, query building gets rather conplex:

  • contains foo and bar -> title:(foo bar) OR description:(foo bar)
  • contains foo or bar -> title:(foo OR bar) OR description:(foo OR bar)
  • does not contain foo or bar-> -title:(foo bar *:*) AND -description(foo bar *:*)

The *:* is killed by acts_as_solr, so the parser needs a little fix too:

# lib/parser_methods.rb:80
# *:xxx -> *:xxx a : b -> a_t:b
query = "(#{query.gsub(/([^\*]) *: */, "\\1_t:")}) #{models}"

(see our branch on github)

Hope this helps someone!