blacklight_highlight 0.0.1pre1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.swp
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,41 @@
1
+ BlacklightHighlight: Blacklight plugin that exposes Solr's highlight field component
2
+
3
+ = Description
4
+
5
+ The BlacklightHighlight Field plugin provides basic support for the Solr Highlight component, which provides search term highlighting in text fields.
6
+
7
+ This plugin will _replace_ the document field response with the highlighter field (if present). This means that if, for example, you have the field 'description_t' in your Blacklight.config[:index_fields], if 'description_t' is a 'highlighted' field, the result of SolrDocument#get('description_t') *will be* the highlighted version of this feel.
8
+
9
+ Future versions of this plugin may allow you to selectively request highlighted fields.
10
+
11
+ = Requirements
12
+
13
+ A Rails app using Blacklight >3.x.
14
+
15
+ = Installation
16
+
17
+ Add
18
+
19
+ gem "blacklight_highlight"
20
+
21
+ to your Gemfile and run "bundle install".
22
+
23
+ Then run "rails generate blacklight_highlight" to install the appropriate extensions into your CatalogController and SolrDocument classes. In you want to do customize the way this installs, instead you may:
24
+
25
+ - add this to your Solr Document model:
26
+
27
+ use_extension(BlacklightOaiProvider::SolrDocumentExtension)
28
+
29
+ - add this to your Controler:
30
+
31
+
32
+ = Configuration
33
+
34
+ You should configure your Solr request handlers to provide the appropriate highlighting results (see <http://wiki.apache.org/solr/HighlightingParameters>). If you do not add any fields, the Solr default will be used (" the fields highlighted for the LuceneQParser are the defaultSearchField (or the df param if used) and for the DisMax parser the qf fields are used.").
35
+
36
+
37
+ = Tests
38
+
39
+ There are none. This is bad I know, sorry.
40
+
41
+
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.1pre1
@@ -0,0 +1,4 @@
1
+ # Meant to be applied on top of Blacklight helpers
2
+ module BlacklightHighlightHelper
3
+ end
4
+
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), "lib/blacklight_highlight/version")
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "blacklight_highlight"
6
+ s.version = BlacklightHighlight::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 Highlight 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
+
@@ -0,0 +1,18 @@
1
+ # Meant to be applied on top of a controller that implements
2
+ # Blacklight::SolrHelper.
3
+ module BlacklightHighlight::ControllerExtension
4
+ def self.included(some_class)
5
+ some_class.helper_method :highlight_config
6
+ some_class.helper BlacklightHighlightHelper
7
+ some_class.send(:include, BlacklightHighlight::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 highlight_config
15
+ Blacklight.config[:highlight] || {}
16
+ end
17
+ end
18
+
@@ -0,0 +1,9 @@
1
+ require 'blacklight'
2
+ require 'blacklight_highlight'
3
+ require 'rails'
4
+
5
+ module BlacklightHighlight
6
+ class Engine < Rails::Engine
7
+
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module BlacklightHighlight
2
+ module SolrDocumentExtension
3
+ def self.included some_class
4
+ some_class.after_initialize do
5
+ solr_response.send(:extend, RSolr::Ext::Response::Highlight) unless solr_response.is_a? RSolr::Ext::Response::Highlight
6
+ end
7
+ end
8
+
9
+ def [] key
10
+ return highlight(key) unless highlight(key).blank?
11
+
12
+ super(key)
13
+ end
14
+
15
+ def highlight key=nil
16
+ return unless solr_response and solr_response.respond_to? :highlight
17
+ return if key == self.class.unique_key
18
+
19
+ solr_response.highlight(self, key)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ # Meant to be applied on top of Blacklight helpers
2
+ module BlacklightHighlight::SolrHelperExtension
3
+ def self.included some_class
4
+ some_class.solr_search_params_logic += [:solr_highlight_params]
5
+ end
6
+
7
+ def solr_highlight_params solr_parameters, user_parameters
8
+ solr_parameters[:hl] ||= true
9
+ end
10
+ end
11
+
@@ -0,0 +1,10 @@
1
+ module BlacklightHighlight
2
+ unless BlacklightHighlight.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,12 @@
1
+ # BlacklightHighlight
2
+ require 'rsolr-ext/response/highlight'
3
+
4
+ module BlacklightHighlight
5
+ autoload :ControllerExtension, 'blacklight_highlight/controller_extension'
6
+ autoload :SolrDocumentExtension, 'blacklight_highlight/solr_document_extension'
7
+ autoload :SolrHelperExtension, 'blacklight_highlight/solr_helper_extension'
8
+
9
+ require 'blacklight_highlight/version'
10
+ require 'blacklight_highlight/engine'
11
+
12
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails/generators'
2
+
3
+ class BlacklightHighlightGenerator < 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 BlacklightHighlight::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 BlacklightHighlight::ControllerExtension\n"
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ module RSolr
2
+ module Ext
3
+ module Response
4
+ module Highlight
5
+ def highlight document, field = nil
6
+ doc_highlights = highlights[document.id]
7
+ doc_highlights ||= {}
8
+
9
+ return doc_highlights[field] if field
10
+
11
+ doc_highlights
12
+ end
13
+
14
+ def highlights
15
+ return {} unless self[:highlighting]
16
+
17
+ @highlights ||= self[:highlighting]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blacklight_highlight
3
+ version: !ruby/object:Gem::Version
4
+ hash: 1923831971
5
+ prerelease: 5
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - pre
11
+ - 1
12
+ version: 0.0.1pre1
13
+ platform: ruby
14
+ authors:
15
+ - Chris Beer
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-07-25 00:00:00 -04:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: rails
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ hash: 7
32
+ segments:
33
+ - 3
34
+ - 0
35
+ version: "3.0"
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: blacklight
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rsolr
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: rsolr-ext
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ type: :runtime
79
+ version_requirements: *id004
80
+ description:
81
+ email:
82
+ - chris_beer@wgbh.org
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files: []
88
+
89
+ files:
90
+ - .gitignore
91
+ - MIT-LICENSE
92
+ - README.rdoc
93
+ - Rakefile
94
+ - VERSION
95
+ - app/helpers/blacklight_highlight_helper.rb
96
+ - blacklight_highlight.gemspec
97
+ - config/routes.rb
98
+ - lib/blacklight_highlight.rb
99
+ - lib/blacklight_highlight/controller_extension.rb
100
+ - lib/blacklight_highlight/engine.rb
101
+ - lib/blacklight_highlight/solr_document_extension.rb
102
+ - lib/blacklight_highlight/solr_helper_extension.rb
103
+ - lib/blacklight_highlight/version.rb
104
+ - lib/generators/blacklight_highlight/blacklight_highlight_generator.rb
105
+ - lib/rsolr-ext/response/highlight.rb
106
+ has_rdoc: true
107
+ homepage: http://projectblacklight.org/
108
+ licenses: []
109
+
110
+ post_install_message:
111
+ rdoc_options: []
112
+
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">"
128
+ - !ruby/object:Gem::Version
129
+ hash: 25
130
+ segments:
131
+ - 1
132
+ - 3
133
+ - 1
134
+ version: 1.3.1
135
+ requirements: []
136
+
137
+ rubyforge_project: blacklight
138
+ rubygems_version: 1.6.2
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Blacklight Solr Highlight plugin
142
+ test_files: []
143
+