Skip to content

Instantly share code, notes, and snippets.

@cbeer
Created March 8, 2010 20:24
Show Gist options
  • Save cbeer/325623 to your computer and use it in GitHub Desktop.
Save cbeer/325623 to your computer and use it in GitHub Desktop.
monkey patch in MoreLikeThis for Blacklight
Blacklight.configure(:shared) do |config|
[...]
config[:mlt_fields] = ['people', 'place', 'date', 'topic']
[...]
end
require 'dispatcher'
module Mlt_SolrHelperPatch
def self.included(base)
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
end
module ClassMethods
end
module InstanceMethods
def more_like_this(id = nil, extra_controller_params={})
input = ({:mlt => true, 'mlt.fl' => Blacklight.config[:mlt_fields], 'mlt.mindf' => 1, 'mlt.mintf' => 1, 'mlt.count' => 3 }).deep_merge(extra_controller_params)
response, document = get_solr_response_for_doc_id(id, input)
response['moreLikeThis'].first.last['docs'].collect {|doc| SolrDocument.new(doc)}
end
end
end
Dispatcher.to_prepare do
Blacklight::SolrHelper.send(:include, Mlt_SolrHelperPatch)
end
class VizController < ApplicationController
include Blacklight::SolrHelper
[...]
def show
@response, @document = get_solr_response_for_doc_id
@similar = more_like_this nil, {'mlt.count' => 30}
respond_to do |format|
format.html { render :layout => false }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment