Skip to content

Instantly share code, notes, and snippets.

require_dependency 'vendor/plugins/blacklight/app/controllers/catalog_controller.rb'
class CatalogController < ApplicationController
# prepend_before_filter :transform_syntax
def solr_search_params(extra_controller_params={})
solr_parameters = super extra_controller_params
my_parameters = solr_parameters.clone
if my_parameters.key? :q
@jrochkind
jrochkind / gist:871530
Created March 15, 2011 21:27
correclty parsing...
["foo",
"foo bar",
" foo bar ",
" foo bar baz ",
"+foo",
"-foo",
"+foo -bar",
"one +two three -four five",
"foo AND bar",
"one AND two AND three AND four",
@jrochkind
jrochkind / gist:904497
Created April 5, 2011 20:40
yet another talking point strawman
# 1. Get rid of ambiguity in parameters, you pass in user_parameters, from the BL rails app. No
# need to pass in direct solr parameters, the caller can add them on themselves, eg:
# i_want_to_force = {:rows => "10000"}
# solr_search_params(params).merge(i_want_to_force)
#
# 2. Try to make it as easy as possible to add units of logic and remove/replace units of logic
# -- we do that a lot. This may may be 'too clever', but the analogy is before_filter on
# controller, remember "before_filter :method_name", this is a similar thing for mapping logic.
def self.solr_search_params_logic
module Foo
def print_something
"foo"
end
end
module Bar
include Foo
def call_print_something
print_something
module Namespace
module Original
def print_something
"foo"
end
end
end
module OtherNameSpace
module Dependent
DEPRECATION WARNING: Future versions of RSolr::Ext will require initialization via RSolr::Ext.connect.
/home/rochkind/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-3.0.6/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `to_sym' for nil:NilClass (NoMethodError)
from /home/rochkind/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.6/lib/action_dispatch/routing/mapper.rb:1309:in `action_path'
from /home/rochkind/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.6/lib/action_dispatch/routing/mapper.rb:1304:in `path_for_action'
from /home/rochkind/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.6/lib/action_dispatch/routing/mapper.rb:1159:in `match'
from /home/rochkind/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.6/lib/action_dispatch/routing/mapper.rb:1358:in `match'
from /home/rochkind/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.6/lib/action_dispatch/routing/mapper.rb:394:in `map_method'
from /home/rochkind/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-
<%= form_tag ... do %>
<span>something</span>
<%= not_html_safe %>
<% end %>
That ends up making the entire block inside the form_tag do html escaped, which ordinarily isn't what happens in a view, but since it's inside a 'do' block, it does.
...which is why it's important for helper methods that return html to .html_safe it BEFORE they return it, like Rails own helpers do.
@jrochkind
jrochkind / gist:1029828
Created June 16, 2011 18:00
definition of Solr 'text' field, with stemming, we use in our Blacklight app
<!-- This is for a Solr 1.4 installation; when we upgrade to 3.1 this will change substantially, using the built-in ICU filters instead of the custom unicode filters here currently, and probably using new improved tokenization and stemming filters. -->
<!-- I don't recall why we've split the filters for indexing vs. query or if we really needed to do that. -->
<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<!-- bob's umich unicode normalization filter -->
<filter class="schema.UnicodeNormalizationFilterFactory" version="icu4j" composed="false" remove_diacritics="true" remove_modifiers="true" fold="true" />
@jrochkind
jrochkind / gist:1029844
Created June 16, 2011 18:08
a Solr text field without stemming
<!-- for Solr 1.4, would be different for Solr 3.1+, including using
built-in ICU analyzers instead of current custom unicode filters. -->
<!-- I don't recall why I used seperate definitions of index and query stage,
or if that's needed for anything. -->
<!-- NO stopwords in use, to avoid dismax stopwords gotcha. -->
<!-- Analyzed Text, no Stemming or Synonyms -->
<fieldtype name="textNoStem" class="solr.TextField" positionIncrementGap="100">
@jrochkind
jrochkind / gist:1030209
Created June 16, 2011 20:36
UnstemSolrParams
# lib/unstem_solr_params.rb
# Add on to CatalogController or another SolrHelper
#, to support :unstem_search param to search only un-stemmed fields.
module UnstemSolrParams
def self.included(klass)
# Replace :add_query_to_solr in solr_search_params_logic with
# our new method.
i = klass.solr_search_params_logic << :add_unstemmed_overrides_to_solr