blacklight_advanced_search 6.0.2 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +351 -0
- data/.solr_wrapper.yml +5 -0
- data/.travis.yml +4 -7
- data/Gemfile +18 -11
- data/Rakefile +24 -34
- data/VERSION +1 -1
- data/app/controllers/advanced_controller.rb +5 -7
- data/app/controllers/blacklight_advanced_search/advanced_controller.rb +5 -8
- data/app/helpers/advanced_helper.rb +4 -6
- data/blacklight_advanced_search.gemspec +11 -8
- data/lib/blacklight_advanced_search.rb +29 -34
- data/lib/blacklight_advanced_search/advanced_query_parser.rb +12 -13
- data/lib/blacklight_advanced_search/advanced_search_builder.rb +28 -32
- data/lib/blacklight_advanced_search/catalog_helper_override.rb +11 -34
- data/lib/blacklight_advanced_search/controller.rb +1 -1
- data/lib/blacklight_advanced_search/filter_parser.rb +7 -9
- data/lib/blacklight_advanced_search/parsing_nesting_parser.rb +5 -8
- data/lib/blacklight_advanced_search/redirect_legacy_params_filter.rb +23 -25
- data/lib/blacklight_advanced_search/render_constraints_override.rb +46 -33
- data/lib/blacklight_advanced_search/version.rb +0 -1
- data/lib/generators/blacklight_advanced_search/assets_generator.rb +4 -8
- data/lib/generators/blacklight_advanced_search/blacklight_advanced_search_generator.rb +0 -2
- data/lib/generators/blacklight_advanced_search/install_generator.rb +9 -5
- data/lib/generators/blacklight_advanced_search/templates/advanced_controller.rb +0 -2
- data/lib/parsing_nesting/grammar.rb +22 -25
- data/lib/parsing_nesting/tree.rb +156 -168
- data/solr/conf/_rest_managed.json +3 -0
- data/solr/conf/admin-extra.html +31 -0
- data/solr/conf/elevate.xml +36 -0
- data/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
- data/solr/conf/protwords.txt +21 -0
- data/solr/conf/schema.xml +635 -0
- data/solr/conf/scripts.conf +24 -0
- data/solr/conf/solrconfig.xml +411 -0
- data/solr/conf/spellings.txt +2 -0
- data/solr/conf/stopwords.txt +58 -0
- data/solr/conf/stopwords_en.txt +58 -0
- data/solr/conf/synonyms.txt +31 -0
- data/solr/conf/xslt/example.xsl +132 -0
- data/solr/conf/xslt/example_atom.xsl +67 -0
- data/solr/conf/xslt/example_rss.xsl +66 -0
- data/solr/conf/xslt/luke.xsl +337 -0
- data/solr/sample_solr_documents.yml +2692 -0
- data/spec/features/blacklight_advanced_search_form_spec.rb +0 -2
- data/spec/helpers/advanced_helper_spec.rb +0 -2
- data/spec/integration/blacklight_stub_spec.rb +0 -2
- data/spec/lib/advanced_search_builder_spec.rb +7 -14
- data/spec/lib/blacklight_advanced_search/render_constraints_override_spec.rb +39 -0
- data/spec/lib/deep_merge_spec.rb +109 -34
- data/spec/lib/filter_parser_spec.rb +8 -14
- data/spec/parsing_nesting/build_tree_spec.rb +73 -81
- data/spec/parsing_nesting/consuming_spec.rb +2 -12
- data/spec/parsing_nesting/to_solr_spec.rb +93 -130
- data/spec/spec_helper.rb +0 -3
- data/spec/test_app_templates/app/controllers/catalog_controller.rb +3 -3
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +3 -3
- metadata +63 -13
- data/spec/spec.opts +0 -4
data/Rakefile
CHANGED
@@ -1,51 +1,41 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rdoc/task'
|
4
|
-
|
5
1
|
require 'bundler/setup'
|
6
2
|
Bundler::GemHelper.install_tasks
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
require 'rdoc/task'
|
5
|
+
require 'rubocop/rake_task'
|
11
6
|
require 'rspec/core/rake_task'
|
12
7
|
require 'engine_cart/rake_task'
|
13
8
|
|
14
9
|
EngineCart.fingerprint_proc = EngineCart.rails_fingerprint_proc
|
15
10
|
|
16
|
-
require 'jettywrapper'
|
17
|
-
|
18
11
|
task :default => :ci
|
19
12
|
|
20
13
|
desc "Run specs"
|
21
|
-
RSpec::Core::RakeTask.new
|
22
|
-
|
14
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
|
+
|
16
|
+
desc "Load fixtures"
|
17
|
+
task :fixtures => ['engine_cart:generate'] do
|
18
|
+
within_test_app do
|
19
|
+
ENV['RAILS_ENV'] ||= 'test'
|
20
|
+
system "rake blacklight:index:seed"
|
21
|
+
abort "Error running fixtures" unless $?.success?
|
22
|
+
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
desc "Execute Continuous Integration build"
|
26
|
+
task :ci => ['rubocop', 'engine_cart:generate'] do
|
27
|
+
require 'solr_wrapper'
|
28
|
+
|
29
|
+
SolrWrapper.wrap(port: '8983') do |solr|
|
30
|
+
solr.with_collection(name: 'blacklight-core', dir: File.join(File.expand_path(File.dirname(__FILE__)), "solr", "conf")) do
|
31
|
+
Rake::Task['fixtures'].invoke
|
32
|
+
Rake::Task['spec'].invoke
|
31
33
|
end
|
32
34
|
end
|
35
|
+
end
|
33
36
|
|
34
|
-
desc
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
jetty_params = {
|
39
|
-
:jetty_home => File.expand_path(File.dirname(__FILE__) + '/jetty'),
|
40
|
-
:quiet => false,
|
41
|
-
:jetty_port => 8888,
|
42
|
-
:solr_home => File.expand_path(File.dirname(__FILE__) + '/jetty/solr'),
|
43
|
-
:startup_wait => 30
|
44
|
-
}
|
45
|
-
|
46
|
-
error = Jettywrapper.wrap(jetty_params) do
|
47
|
-
Rake::Task['fixtures'].invoke
|
48
|
-
Rake::Task['spec'].invoke
|
49
|
-
end
|
50
|
-
raise "test failures: #{error}" if error
|
37
|
+
desc 'Run style checker'
|
38
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
39
|
+
task.requires << 'rubocop-rspec'
|
40
|
+
task.fail_on_error = true
|
51
41
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
6.0
|
1
|
+
6.1.0
|
@@ -5,23 +5,21 @@
|
|
5
5
|
# Note that this NEEDS to sub-class CatalogController, so it gets any
|
6
6
|
# custom searching behavior you've added, and uses when fetching facets
|
7
7
|
# etc. It does that right now because BlacklightAdvancedSearch::AdvancedController
|
8
|
-
# is hard-coded to subclass CatalogController.
|
8
|
+
# is hard-coded to subclass CatalogController.
|
9
9
|
#
|
10
|
-
# TODO:
|
10
|
+
# TODO:
|
11
11
|
# This seperate controller may not need to exist at all -- it just exists
|
12
12
|
# to provide the advanced search form (and fetching of facets to display
|
13
13
|
# on that form). Instead, mix-in a new "advanced" action to CatalogController?
|
14
|
-
# (Make a backwards compat route though).
|
14
|
+
# (Make a backwards compat route though).
|
15
15
|
#
|
16
|
-
# Alternately, if this does exist as a seperate controller, it should
|
16
|
+
# Alternately, if this does exist as a seperate controller, it should
|
17
17
|
# _directly_ < CatalogController, and BlacklightAdvancedSearch::AdvancedController
|
18
18
|
# should be a mix-in that does not assume parent controller. Then, if you have
|
19
19
|
# multi-controllers, you just need to create new `AdvancedControllerForX < XController`
|
20
20
|
# which still mixes in BlacklightAdvancedSearch::AdvancedController. There
|
21
21
|
# are probably some other edges that need to be smoothed for that approach, but
|
22
|
-
# that'd be the direction.
|
22
|
+
# that'd be the direction.
|
23
23
|
class AdvancedController < BlacklightAdvancedSearch::AdvancedController
|
24
|
-
|
25
24
|
copy_blacklight_config_from(CatalogController)
|
26
|
-
|
27
25
|
end
|
@@ -1,17 +1,14 @@
|
|
1
1
|
# Need to sub-class CatalogController so we get all other plugins behavior
|
2
|
-
# for our own "inside a search context" lookup of facets.
|
2
|
+
# for our own "inside a search context" lookup of facets.
|
3
3
|
class BlacklightAdvancedSearch::AdvancedController < CatalogController
|
4
|
-
|
5
4
|
def index
|
6
|
-
unless request.method
|
7
|
-
@response = get_advanced_search_facets
|
8
|
-
end
|
5
|
+
@response = get_advanced_search_facets unless request.method == :post
|
9
6
|
end
|
10
7
|
|
11
8
|
protected
|
12
9
|
|
13
10
|
# Override to use the engine routes
|
14
|
-
def search_action_url
|
11
|
+
def search_action_url(options = {})
|
15
12
|
blacklight_advanced_search_engine.url_for(options.merge(action: 'index'))
|
16
13
|
end
|
17
14
|
|
@@ -20,9 +17,9 @@ class BlacklightAdvancedSearch::AdvancedController < CatalogController
|
|
20
17
|
# * IGNORING current query (add in facets_for_advanced_search_form filter)
|
21
18
|
# * IGNORING current advanced search facets (remove add_advanced_search_to_solr filter)
|
22
19
|
response, _ = search_results(params) do |search_builder|
|
23
|
-
search_builder.except(:add_advanced_search_to_solr).append(:facets_for_advanced_search_form)
|
20
|
+
search_builder.except(:add_advanced_search_to_solr).append(:facets_for_advanced_search_form)
|
24
21
|
end
|
25
22
|
|
26
|
-
|
23
|
+
response
|
27
24
|
end
|
28
25
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# Helper methods for the advanced search form
|
2
2
|
module AdvancedHelper
|
3
|
-
|
4
3
|
# Fill in default from existing search, if present
|
5
4
|
# -- if you are using same search fields for basic
|
6
5
|
# search and advanced, will even fill in properly if existing
|
7
6
|
# search used basic search on same field present in advanced.
|
8
7
|
def label_tag_default_for(key)
|
9
|
-
if
|
8
|
+
if !params[key].blank?
|
10
9
|
return params[key]
|
11
10
|
elsif params["search_field"] == key
|
12
11
|
return params["q"]
|
@@ -26,7 +25,7 @@ module AdvancedHelper
|
|
26
25
|
t('blacklight_advanced_search.any') => 'OR'
|
27
26
|
}.sort
|
28
27
|
|
29
|
-
|
28
|
+
select_tag(:op, options_for_select(options, params[:op]), :class => 'input-small')
|
30
29
|
end
|
31
30
|
|
32
31
|
# Current params without fields that will be over-written by adv. search,
|
@@ -34,12 +33,12 @@ module AdvancedHelper
|
|
34
33
|
def advanced_search_context
|
35
34
|
my_params = params.except :page, :commit, :f_inclusive, :q, :search_field, :op, :action, :index, :sort, :controller, :utf8
|
36
35
|
|
37
|
-
my_params.except! *search_fields_for_advanced_search.map { |
|
36
|
+
my_params.except! *search_fields_for_advanced_search.map { |_key, field_def| field_def[:key] }
|
38
37
|
end
|
39
38
|
|
40
39
|
def search_fields_for_advanced_search
|
41
40
|
@search_fields_for_advanced_search ||= begin
|
42
|
-
blacklight_config.search_fields.select { |
|
41
|
+
blacklight_config.search_fields.select { |_k, v| v.include_in_advanced_search || v.include_in_advanced_search.nil? }
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
@@ -47,5 +46,4 @@ module AdvancedHelper
|
|
47
46
|
def advanced_search_facet_partial_name(display_facet)
|
48
47
|
facet_configuration_for_field(display_facet.name).try(:partial) || "catalog/facet_limit"
|
49
48
|
end
|
50
|
-
|
51
49
|
end
|
@@ -2,13 +2,14 @@
|
|
2
2
|
require File.join(File.dirname(__FILE__), "lib/blacklight_advanced_search/version")
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
5
|
+
s.name = "blacklight_advanced_search"
|
6
|
+
s.version = BlacklightAdvancedSearch::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors
|
9
|
-
s.email
|
10
|
-
s.homepage
|
11
|
-
s.summary
|
8
|
+
s.authors = ["Jonathan Rochkind", "Chris Beer"]
|
9
|
+
s.email = ["blacklight-development@googlegroups.com"]
|
10
|
+
s.homepage = "http://projectblacklight.org/"
|
11
|
+
s.summary = "Blacklight Advanced Search plugin"
|
12
|
+
s.license = "Apache 2.0"
|
12
13
|
|
13
14
|
s.rubyforge_project = "blacklight"
|
14
15
|
|
@@ -23,6 +24,8 @@ Gem::Specification.new do |s|
|
|
23
24
|
s.add_development_dependency "rails"
|
24
25
|
s.add_development_dependency "rspec-rails", "~> 3.0"
|
25
26
|
s.add_development_dependency "capybara"
|
26
|
-
s.add_development_dependency '
|
27
|
-
s.add_development_dependency 'engine_cart', "~> 0.
|
27
|
+
s.add_development_dependency 'solr_wrapper', "~> 0.14"
|
28
|
+
s.add_development_dependency 'engine_cart', "~> 0.10"
|
29
|
+
s.add_development_dependency 'rubocop'
|
30
|
+
s.add_development_dependency 'rubocop-rspec'
|
28
31
|
end
|
@@ -10,40 +10,35 @@ module BlacklightAdvancedSearch
|
|
10
10
|
|
11
11
|
require 'blacklight_advanced_search/version'
|
12
12
|
require 'blacklight_advanced_search/engine'
|
13
|
-
|
14
|
-
# Utility method used in our solr search logic.
|
15
|
-
# Merges new_hash into source_hash, but will recursively
|
16
|
-
# merge nested arrays and hashes too; also will NOT merge nil
|
17
|
-
# or blank values from new_hash into source_hash, nil or blank values
|
18
|
-
# in new_hash will not overwrite values in source_hash.
|
19
|
-
def self.deep_merge!(source_hash, new_hash)
|
20
|
-
# We used to use built-in source_hash.merge() with a block arg
|
21
|
-
# to customize merge behavior, but that was breaking in some
|
22
|
-
# versions of BL/Rails where source_hash was a kind of HashWithIndifferentAccess,
|
23
|
-
# and hwia is unreliable in some versions of Rails. Oh well.
|
24
|
-
# https://github.com/projectblacklight/blacklight/issues/827
|
25
13
|
|
26
|
-
|
27
|
-
|
14
|
+
# Utility method used in our solr search logic.
|
15
|
+
# Like Rails Hash#deep_merge, merges 2 hashes recursively, including nested Arrays and Hashes.
|
16
|
+
# Unlike Rails Hash#deep_merge:
|
17
|
+
# - will NOT merge nil values over existing ones
|
18
|
+
# - will NOT merge (non-FalseClass) blank values
|
19
|
+
# - WILL deduplicate values from arrays after merging them
|
20
|
+
#
|
21
|
+
# @param [Hash|HashWithIndifferentAccess] source_hash
|
22
|
+
# @param [Hash|HashWithIndifferentAccess] new_hash
|
23
|
+
# @return [Hash] the deeply merged hash
|
24
|
+
# @see Rails #deep_merge http://apidock.com/rails/v4.2.1/Hash/deep_merge
|
25
|
+
# @example new_hash = BlacklightAdvancedSearch.deep_merge(h1, h2)
|
26
|
+
def self.deep_merge(source_hash, new_hash)
|
27
|
+
source_hash.deep_merge(new_hash, &method(:merge_conflict_resolution))
|
28
|
+
end
|
29
|
+
|
30
|
+
# this one side-effects the first param
|
31
|
+
# @see #deep_merge
|
32
|
+
# @deprecated use `new_hash = BlacklightAdvancedSearch.deep_merge(h1, h2)` instead
|
33
|
+
def self.deep_merge!(source_hash, new_hash)
|
34
|
+
source_hash.deep_merge!(new_hash, &method(:merge_conflict_resolution))
|
35
|
+
end
|
28
36
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
old.concat(new_value).uniq
|
37
|
-
elsif new_value.nil?
|
38
|
-
# Allowing nil values to over-write on merge messes things up.
|
39
|
-
# don't set a nil value if you really want to force blank, set
|
40
|
-
# empty string.
|
41
|
-
old
|
42
|
-
else
|
43
|
-
new_value
|
44
|
-
end
|
45
|
-
end
|
46
|
-
source_hash
|
47
|
-
end
|
48
|
-
|
37
|
+
# the arguments are set by what the Rails Hash.deep_merge supplies the block
|
38
|
+
def self.merge_conflict_resolution(_key, old, new_value)
|
39
|
+
return old if new_value.nil?
|
40
|
+
return old if new_value.respond_to?(:blank?) && new_value.blank? && !new_value.is_a?(FalseClass)
|
41
|
+
return old | new_value if old.is_a?(Array) && new_value.is_a?(Array)
|
42
|
+
new_value
|
43
|
+
end
|
49
44
|
end
|
@@ -9,16 +9,16 @@ module BlacklightAdvancedSearch
|
|
9
9
|
include FilterParser
|
10
10
|
attr_reader :config, :params
|
11
11
|
|
12
|
-
def initialize(params,config)
|
13
|
-
@params =
|
12
|
+
def initialize(params, config)
|
13
|
+
@params = Blacklight::SearchState.new(params, config).to_h
|
14
14
|
@config = config
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_solr
|
18
18
|
@to_solr ||= begin
|
19
19
|
{
|
20
|
-
:q => process_query(params,config),
|
21
|
-
:fq => generate_solr_fq
|
20
|
+
:q => process_query(params, config),
|
21
|
+
:fq => generate_solr_fq
|
22
22
|
}
|
23
23
|
end
|
24
24
|
end
|
@@ -32,40 +32,39 @@ module BlacklightAdvancedSearch
|
|
32
32
|
# returns as a kash of field => query.
|
33
33
|
# see also keyword_op
|
34
34
|
def keyword_queries
|
35
|
-
unless
|
35
|
+
unless @keyword_queries
|
36
36
|
@keyword_queries = {}
|
37
37
|
|
38
38
|
return @keyword_queries unless @params[:search_field] == ::AdvancedController.blacklight_config.advanced_search[:url_key]
|
39
39
|
|
40
|
-
config.search_fields.each do |
|
41
|
-
|
42
|
-
@keyword_queries[
|
40
|
+
config.search_fields.each do |key, _field_def|
|
41
|
+
unless @params[key.to_sym].blank?
|
42
|
+
@keyword_queries[key] = @params[key.to_sym]
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
@keyword_queries
|
47
47
|
end
|
48
48
|
|
49
49
|
# extracts advanced-type filters from query params,
|
50
50
|
# returned as a hash of field => [array of values]
|
51
51
|
def filters
|
52
|
-
unless
|
52
|
+
unless @filters
|
53
53
|
@filters = {}
|
54
54
|
return @filters unless @params[:f_inclusive] && @params[:f_inclusive].respond_to?(:each_pair)
|
55
55
|
@params[:f_inclusive].each_pair do |field, value_array|
|
56
56
|
@filters[field] ||= value_array.dup
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
@filters
|
60
60
|
end
|
61
61
|
|
62
62
|
def filters_include_value?(field, value)
|
63
|
-
filters[field.to_s].try {|array| array.include? value}
|
63
|
+
filters[field.to_s].try { |array| array.include? value }
|
64
64
|
end
|
65
65
|
|
66
66
|
def empty?
|
67
67
|
filters.empty? && keyword_queries.empty?
|
68
68
|
end
|
69
|
-
|
70
69
|
end
|
71
70
|
end
|
@@ -2,7 +2,6 @@ require 'parslet'
|
|
2
2
|
require 'parsing_nesting/tree'
|
3
3
|
module BlacklightAdvancedSearch
|
4
4
|
module AdvancedSearchBuilder
|
5
|
-
|
6
5
|
include Blacklight::SearchFields
|
7
6
|
|
8
7
|
def is_advanced_search?
|
@@ -12,66 +11,64 @@ module BlacklightAdvancedSearch
|
|
12
11
|
# this method should get added into the processor chain
|
13
12
|
# in a position AFTER normal query handling (:add_query_to_solr),
|
14
13
|
# so it'll overwrite that if and only if it's an advanced search.
|
15
|
-
# adds a 'q' and 'fq's based on advanced search form input.
|
14
|
+
# adds a 'q' and 'fq's based on advanced search form input.
|
16
15
|
def add_advanced_search_to_solr(solr_parameters)
|
17
16
|
# If we've got the hint that we're doing an 'advanced' search, then
|
18
17
|
# map that to solr #q, over-riding whatever some other logic may have set, yeah.
|
19
18
|
# the hint right now is :search_field request param is set to a magic
|
20
|
-
# key. OR of :f_inclusive is set for advanced params, we need processing too.
|
19
|
+
# key. OR of :f_inclusive is set for advanced params, we need processing too.
|
21
20
|
if is_advanced_search?
|
22
21
|
# Set this as a controller instance variable, not sure if some views/helpers depend on it. Better to leave it as a local variable
|
23
|
-
# if not, more investigation later.
|
24
|
-
advanced_query = BlacklightAdvancedSearch::QueryParser.new(blacklight_params, self.blacklight_config
|
25
|
-
BlacklightAdvancedSearch.deep_merge!(solr_parameters, advanced_query.to_solr
|
26
|
-
|
22
|
+
# if not, more investigation later.
|
23
|
+
advanced_query = BlacklightAdvancedSearch::QueryParser.new(blacklight_params, self.blacklight_config)
|
24
|
+
BlacklightAdvancedSearch.deep_merge!(solr_parameters, advanced_query.to_solr)
|
25
|
+
unless advanced_query.keyword_queries.empty?
|
27
26
|
# force :qt if set, fine if it's nil, we'll use whatever CatalogController
|
28
|
-
# ordinarily uses.
|
27
|
+
# ordinarily uses.
|
29
28
|
solr_parameters[:qt] = self.blacklight_config.advanced_search[:qt]
|
30
|
-
solr_parameters[:defType] = "lucene"
|
29
|
+
solr_parameters[:defType] = "lucene"
|
31
30
|
end
|
32
|
-
|
31
|
+
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
36
35
|
# Different versions of Parslet raise different exception classes,
|
37
36
|
# need to figure out which one exists to rescue
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
PARSLET_FAILED_EXCEPTIONS = if defined? Parslet::UnconsumedInput
|
38
|
+
[Parslet::UnconsumedInput].freeze
|
39
|
+
else
|
40
|
+
[Parslet::ParseFailed].freeze
|
42
41
|
end
|
43
|
-
|
44
|
-
|
42
|
+
|
45
43
|
# This method can be included in the SearchBuilder to have us
|
46
44
|
# parse an ordinary entered :q for AND/OR/NOT and produce appropriate
|
47
45
|
# Solr query.
|
48
46
|
#
|
49
47
|
# Note: For syntactically invalid input, we'll just skip the adv
|
50
48
|
# parse and send it straight to solr same as if advanced_parse_q
|
51
|
-
# were not being used.
|
49
|
+
# were not being used.
|
52
50
|
def add_advanced_parse_q_to_solr(solr_parameters)
|
53
51
|
unless scope.params[:q].blank?
|
54
|
-
field_def = search_field_def_for_key(
|
52
|
+
field_def = search_field_def_for_key(scope.params[:search_field]) ||
|
55
53
|
default_search_field
|
56
|
-
|
57
|
-
|
54
|
+
|
58
55
|
# If the individual field has advanced_parse_q suppressed, punt
|
59
|
-
return if field_def[:advanced_parse] == false
|
60
|
-
|
56
|
+
return if field_def[:advanced_parse] == false
|
57
|
+
|
61
58
|
solr_direct_params = field_def[:solr_parameters] || {}
|
62
59
|
solr_local_params = field_def[:solr_local_parameters] || {}
|
63
|
-
|
60
|
+
|
64
61
|
# See if we can parse it, if we can't, we're going to give up
|
65
62
|
# and just allow basic search, perhaps with a warning.
|
66
63
|
begin
|
67
|
-
adv_search_params = ParsingNesting::Tree.parse(scope.params[:q], blacklight_config.advanced_search[:query_parser]).to_single_query_params(
|
64
|
+
adv_search_params = ParsingNesting::Tree.parse(scope.params[:q], blacklight_config.advanced_search[:query_parser]).to_single_query_params(solr_local_params)
|
68
65
|
|
69
66
|
BlacklightAdvancedSearch.deep_merge!(solr_parameters, solr_direct_params)
|
70
|
-
BlacklightAdvancedSearch.deep_merge!(solr_parameters, adv_search_params)
|
71
|
-
rescue
|
67
|
+
BlacklightAdvancedSearch.deep_merge!(solr_parameters, adv_search_params)
|
68
|
+
rescue PARSLET_FAILED_EXCEPTIONS => e
|
72
69
|
# do nothing, don't merge our input in, keep basic search
|
73
|
-
# optional TODO, display error message in flash here, but hard to
|
74
|
-
# display a good one.
|
70
|
+
# optional TODO, display error message in flash here, but hard to
|
71
|
+
# display a good one.
|
75
72
|
return
|
76
73
|
end
|
77
74
|
end
|
@@ -80,21 +77,20 @@ module BlacklightAdvancedSearch
|
|
80
77
|
# A Solr param filter that is NOT included by default in the chain,
|
81
78
|
# but is appended by AdvancedController#index, to do a search
|
82
79
|
# for facets _ignoring_ the current query, we want the facets
|
83
|
-
# as if the current query weren't there.
|
80
|
+
# as if the current query weren't there.
|
84
81
|
#
|
85
82
|
# Also adds any solr params set in blacklight_config.advanced_search[:form_solr_parameters]
|
86
83
|
def facets_for_advanced_search_form(solr_p)
|
87
84
|
# ensure empty query is all records, to fetch available facets on entire corpus
|
88
85
|
solr_p["q"] = '{!lucene}*:*'
|
89
86
|
|
90
|
-
# We only care about facets, we don't need any rows.
|
87
|
+
# We only care about facets, we don't need any rows.
|
91
88
|
solr_p["rows"] = "0"
|
92
89
|
|
93
90
|
# Anything set in config as a literal
|
94
91
|
if blacklight_config.advanced_search[:form_solr_parameters]
|
95
|
-
solr_p.merge!(
|
92
|
+
solr_p.merge!(blacklight_config.advanced_search[:form_solr_parameters])
|
96
93
|
end
|
97
|
-
|
98
94
|
end
|
99
95
|
end
|
100
96
|
end
|