Created
March 8, 2010 20:24
-
-
Save cbeer/325623 to your computer and use it in GitHub Desktop.
monkey patch in MoreLikeThis for Blacklight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blacklight.configure(:shared) do |config| | |
[...] | |
config[:mlt_fields] = ['people', 'place', 'date', 'topic'] | |
[...] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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