blacklight_more_like_this 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,60 @@
1
+ BlacklightMoreLikeThis: Blacklight plugin that exposes more-like-this information
2
+
3
+ = Description
4
+
5
+ The BlacklightMoreLikeThis plugin provides basic support for the Solr MoreLikeThis feature, which provides similar documents for a results set. The primary use case for this plugin is as an element in the document show view, but should be possible to work with it on the index view as well.
6
+
7
+ = Requirements
8
+
9
+ A Rails app using the Blacklight plugin (tested against post-version 2.5).
10
+
11
+ = Installation
12
+
13
+ This is a plugin, not a gem (because the structure was copied from existing plugins; in theory, it should be possible to make this a gem in the future).
14
+
15
+ A couple different ways to get the source into your vendor/plugins directory.
16
+
17
+ Go into your application directory, and run:
18
+
19
+ ./script/plugin install git://github.com/cbeer/blacklight_more_like_this.git
20
+
21
+ Later you can run ./script/plugin update blacklight_more_like_this if you like.
22
+
23
+ Requires git installed on your system. There are other ways to get the plugin in there too.
24
+
25
+ OR
26
+ cd $your_app/vendor/plugins
27
+ git clone git://github.com/cbeer/blacklight_more_like_this.git
28
+
29
+ = Configuration
30
+
31
+ You should configure solr to provide MoreLikeThis results directly (by editing the response handler <http://wiki.apache.org/solr/MoreLikeThis>), however some basic support is built into the plugin to provide the proper behaviors anyway, using config[:more_like_this] in your config/initializers/blacklight_config.rb.
32
+
33
+ config[:more_like_this][:fields] = ["title", "description", "author"]
34
+ config[:more_like_this][:count] = 3
35
+
36
+
37
+ == Injection
38
+
39
+ This plugin assumes it is in a Blacklight Rails app, uses Blacklight methods, Rails methods, and standard ruby module includes to inject it's behaviors into the app.
40
+
41
+ You can turn off this injection if you like, although it will make the plugin less (or non-) functional unless you manually do similar injection. See lib/blacklight_more_like_this.rb#inject! to see exactly what's going on.
42
+
43
+ In any initializer, you can set:
44
+
45
+ BlacklightMoreLikeThis.omit_inject = true
46
+
47
+ to turn off all injection. The plugin will be completely non-functional if you do this, of course. But perhaps you could try to re-use some of it's classes in a non-Blacklight, highly hacked Blacklight, or even non-Rails application this way.
48
+
49
+ You can also turn off injection of individual components, which could be more useful:
50
+
51
+ BlacklightMoreLikeThis.omit_inject = {
52
+ :solrdocument_mixin => false,
53
+ :view_helpers => false
54
+ }
55
+
56
+ = Tests
57
+
58
+ There are none. This is bad I know, sorry.
59
+
60
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rake'
2
+ require 'bundler'
3
+
4
+ Bundler::GemHelper.install_tasks
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,6 @@
1
+ # Meant to be applied on top of Blacklight helpers
2
+ module BlacklightMoreLikeThisHelper
3
+ def render_more_like_this document = @document
4
+ render :partial => 'blacklight_more_like_this/more_like_this', :collection => document.more_like_this
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ <div class="more_like_this">
2
+ <%= link_to_document object %>
3
+ </div>
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), "lib/blacklight_more_like_this/version")
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "blacklight_more_like_this"
6
+ s.version = BlacklightMoreLikeThis::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Chris Beer"]
9
+ s.email = ["chris_beer@wgbh.org"]
10
+ s.homepage = "http://projectblacklight.org/"
11
+ s.summary = "Blacklight Solr More-Like-This plugin"
12
+
13
+ s.rubyforge_project = "blacklight"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+
21
+ s.add_dependency "rails", "~> 3.0"
22
+ s.add_dependency "blacklight"
23
+ s.add_dependency "rsolr"
24
+ s.add_dependency "rsolr-ext"
25
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+
2
+ # We want to add a new collection action to Catalog, without over-writing
3
+ # what's already there. This SEEMS to do it.
4
+ ActionController::Routing::Routes.draw do |map|
5
+ end
6
+
File without changes
@@ -0,0 +1,17 @@
1
+ # Meant to be applied on top of a controller that implements
2
+ # Blacklight::SolrHelper.
3
+ module BlacklightMoreLikeThis::ControllerExtension
4
+ def self.included(some_class)
5
+ some_class.helper_method :more_like_this_config
6
+ some_class.helper BlacklightMoreLikeThisHelper
7
+ some_class.send(:include, BlacklightMoreLikeThis::SolrHelperExtension)
8
+ end
9
+
10
+ # Uses Blacklight.config, needs to be modified when
11
+ # that changes to be controller-based. This is the only method
12
+ # in this plugin that accesses Blacklight.config, single point
13
+ # of contact.
14
+ def more_like_this_config
15
+ Blacklight.config[:more_like_this] || {}
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'blacklight'
2
+ require 'blacklight_more_like_this'
3
+ require 'rails'
4
+
5
+ module BlacklightMoreLikeThis
6
+ class Engine < Rails::Engine
7
+
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module BlacklightMoreLikeThis
2
+ module SolrDocumentExtension
3
+ def self.included some_class
4
+ some_class.after_initialize do
5
+ solr_response.send(:extend, RSolr::Ext::Response::MoreLikeThis) unless solr_response.is_a? RSolr::Ext::Response::MoreLikeThis
6
+ end
7
+ end
8
+
9
+ def more_like_this
10
+ return unless solr_response and solr_response.respond_to? :more_like
11
+
12
+ solr_response.more_like(self).map { |x| self.class.new(x, solr_response) }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ # Meant to be applied on top of Blacklight helpers
2
+ module BlacklightMoreLikeThis::SolrHelperExtension
3
+
4
+ def self.included some_class
5
+ some_class.solr_search_params_logic += [:add_solr_mlt_parameters]
6
+ end
7
+
8
+ def add_solr_mlt_parameters solr_parameters, user_parameters
9
+ config = more_like_this_config
10
+ config ||= {}
11
+
12
+ return unless config['enable_mlt_in_search_results'] or solr_parameters[:id]
13
+
14
+ solr_parameters[:mlt] = true
15
+ solr_parameters['mlt.count'] = 3
16
+ solr_parameters['mlt.mintf'] = 1
17
+
18
+ config.keys.select { |x| x.to_s =~ /mlt/ }.each do |k|
19
+ solr_parameters[k] = config[k]
20
+ end
21
+ end
22
+
23
+ def solr_doc_params(*args)
24
+ config = more_like_this_config
25
+ config ||= {}
26
+
27
+ solr_parameters = super(*args)
28
+
29
+ add_solr_mlt_parameters(solr_parameters, {})
30
+
31
+ solr_parameters
32
+ end
33
+
34
+ end
@@ -0,0 +1,10 @@
1
+ module BlacklightMoreLikeThis
2
+ unless BlacklightMoreLikeThis.const_defined? :VERSION
3
+ def self.version
4
+ @version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
5
+ end
6
+
7
+ VERSION = self.version
8
+ end
9
+ end
10
+
@@ -0,0 +1,11 @@
1
+ # BlacklightMoreLikeThis
2
+
3
+ require 'rsolr-ext/response/more_like_this'
4
+
5
+ module BlacklightMoreLikeThis
6
+ require 'blacklight_more_like_this/version'
7
+ require 'blacklight_more_like_this/engine'
8
+ autoload :ControllerExtension, 'blacklight_more_like_this/controller_extension'
9
+ autoload :SolrHelperExtension, 'blacklight_more_like_this/solr_helper_extension'
10
+ autoload :SolrDocumentExtension, 'blacklight_more_like_this/solr_document_extension'
11
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails/generators'
2
+
3
+ class BlacklightMoreLikeThisGenerator < Rails::Generators::Base
4
+
5
+ argument :model_name, :type => :string, :default => "SolrDocument"
6
+ argument :controller_name, :type => :string, :default => "CatalogController"
7
+
8
+ def inject_solr_document_extension
9
+ file_path = "app/models/#{model_name.underscore}.rb"
10
+
11
+ if File.exists? file_path
12
+ inject_into_file file_path, :after => "include Blacklight::Solr::Document" do
13
+ "\n include BlacklightMoreLikeThis::SolrDocumentExtension\n"
14
+ end
15
+ end
16
+ end
17
+
18
+ def inject_catalog_controller_extension
19
+ file_path = "app/controllers/#{controller_name.underscore}.rb"
20
+ if File.exists? file_path
21
+ inject_into_file file_path, :after => "include Blacklight::Catalog" do
22
+ "\n include BlacklightMoreLikeThis::ControllerExtension\n"
23
+ end
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,20 @@
1
+ module RSolr
2
+ module Ext
3
+ module Response
4
+ module MoreLikeThis
5
+ def more_like document
6
+ mlt = more_like_this[document.id]
7
+ return [] unless mlt and mlt['docs']
8
+
9
+ mlt['docs'].map { |x| x.extend RSolr::Ext::Doc }
10
+ end
11
+
12
+ def more_like_this
13
+ return {} unless self[:moreLikeThis]
14
+
15
+ self[:moreLikeThis]
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blacklight_more_like_this
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Chris Beer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-26 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ version: "3.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: blacklight
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rsolr
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :runtime
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rsolr-ext
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :runtime
77
+ version_requirements: *id004
78
+ description:
79
+ email:
80
+ - chris_beer@wgbh.org
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files: []
86
+
87
+ files:
88
+ - MIT-LICENSE
89
+ - README.rdoc
90
+ - Rakefile
91
+ - VERSION
92
+ - app/helpers/blacklight_more_like_this_helper.rb
93
+ - app/views/blacklight_more_like_this/_more_like_this.html.erb
94
+ - blacklight_more_like_this.gemspec
95
+ - config/routes.rb
96
+ - lib/blacklight_more_like_this.rb
97
+ - lib/blacklight_more_like_this/README.rdoc
98
+ - lib/blacklight_more_like_this/controller_extension.rb
99
+ - lib/blacklight_more_like_this/engine.rb
100
+ - lib/blacklight_more_like_this/solr_document_extension.rb
101
+ - lib/blacklight_more_like_this/solr_helper_extension.rb
102
+ - lib/blacklight_more_like_this/version.rb
103
+ - lib/generators/blacklight_more_like_this/blacklight_more_like_this_generator.rb
104
+ - lib/rsolr-ext/response/more_like_this.rb
105
+ has_rdoc: true
106
+ homepage: http://projectblacklight.org/
107
+ licenses: []
108
+
109
+ post_install_message:
110
+ rdoc_options: []
111
+
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ requirements: []
133
+
134
+ rubyforge_project: blacklight
135
+ rubygems_version: 1.6.2
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: Blacklight Solr More-Like-This plugin
139
+ test_files: []
140
+