Permalink
Browse files

Reorganise in an attempt to get the plugin working with Rails3

  • Loading branch information...
1 parent 8a6f89f commit d53c3a01283ad01191e1b9cf306bf97c51aee6fd @springbok springbok committed Mar 7, 2011
View
15 init.rb
@@ -1,14 +1 @@
-# Following line causes error 134 in RubyMine during debug
-#$:.unshift "#{File.dirname(__FILE__)}/lib"
-# Replace with:
-libdir = "#{File.dirname(__FILE__)}/lib"
-$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
-require 'sunspot'
-require 'composite_setup'
-require 'sunspot/dsl/fields'
-require 'sunspot/dsl/standard_query'
-require 'sunspot/type'
-require 'sunspot/field'
-require 'sunspot/setup'
-require 'sunspot/field_factory'
-require 'sunspot/indexer'
+require 'sunspot_cell'
View
@@ -1,34 +0,0 @@
-module Sunspot
- class CompositeSetup
-
- # Collection of all attachment fields configured for any of the enclosed types.
- #
- # === Returns
- #
- # Array:: Text fields configured for the enclosed types
- #
- def all_attachment_fields
- @attachment_fields ||= attachment_fields_hash.values.map { |set| set.to_a }.flatten
- end
-
- private
-
- # Return a hash of field names to atachment field objects, containing all fields
- # that are configured for any of the types enclosed.
- #
- # ==== Returns
- #
- # Hash:: Hash of field names to text field objects.
- #
- def attachment_fields_hash
- @attachment_fields_hash ||=
- setups.inject({}) do |hash, setup|
- setup.all_attachment_fields.each do |text_field|
- (hash[text_field.name] ||= Set.new) << text_field
- end
- hash
- end
- end
-
- end
-end
View
@@ -1,3 +0,0 @@
-%w(rich_document).each do |filename|
- require File.join(File.dirname(__FILE__), 'sunspot', filename)
-end
View
@@ -1,16 +0,0 @@
-module Sunspot
- module DSL
- class Fields
-
- # Added an attachment field, the attachment filename is passed to Solr for
- # indexing by tiqa
-
- def attachment(*names)
- names.each do |name|
- @setup.add_attachment_field_factory(name)
- end
- end
-
- end
- end
-end
@@ -1,130 +0,0 @@
-module Sunspot
- module DSL #:nodoc:
- #
- # This class presents a DSL for constructing queries using the
- # Sunspot.search method. Methods of this class are available inside the
- # search block. Much of the DSL's functionality is implemented by this
- # class's superclasses, Sunspot::DSL::FieldQuery and Sunspot::DSL::Scope
- #
- # See Sunspot.search for usage examples
- #
- class StandardQuery < FieldQuery
- include Paginatable, Adjustable
-
- # Specify a phrase that should be searched as fulltext. Only +text+
- # fields are searched - see DSL::Fields.text
- #
- # Keyword search is executed using Solr's dismax handler, which strikes
- # a good balance between powerful and foolproof. In particular,
- # well-matched quotation marks can be used to group phrases, and the
- # + and - modifiers work as expected. All other special Solr boolean
- # syntax is escaped, and mismatched quotes are ignored entirely.
- #
- # This method can optionally take a block, which is evaluated by the
- # Fulltext DSL class, and exposes several powerful dismax features.
- #
- # ==== Parameters
- #
- # keywords<String>:: phrase to perform fulltext search on
- #
- # ==== Options
- #
- # :fields<Array>::
- # List of fields that should be searched for keywords. Defaults to all
- # fields configured for the types under search.
- # :highlight<Boolean,Array>::
- # If true, perform keyword highlighting on all searched fields. If an
- # array of field names, perform highlighting on the specified fields.
- # This can also be called from within the fulltext block.
- # :minimum_match<Integer>::
- # The minimum number of search terms that a result must match. By
- # default, all search terms must match; if the number of search terms
- # is less than this number, the default behavior applies.
- # :tie<Float>::
- # A tiebreaker coefficient for scores derived from subqueries that are
- # lower-scoring than the maximum score subquery. Typically a near-zero
- # value is useful. See
- # http://wiki.apache.org/solr/DisMaxRequestHandler#tie_.28Tie_breaker.29
- # for more information.
- # :query_phrase_slop<Integer>::
- # The number of words that can appear between the words in a
- # user-entered phrase (i.e., keywords in quotes) and still match. For
- # instance, in a search for "\"great pizza\"" with a phrase slop of 1,
- # "great pizza" and "great big pizza" will match, but "great monster of
- # a pizza" will not. Default behavior is a query phrase slop of zero.
- #
- def fulltext(keywords, options = {}, &block)
- if keywords && !(keywords.to_s =~ /^\s*$/)
- fulltext_query = @query.add_fulltext(keywords)
- if field_names = options.delete(:fields)
- Util.Array(field_names).each do |field_name|
- @setup.text_fields(field_name).each do |field|
- fulltext_query.add_fulltext_field(field, field.default_boost)
- end
- end
- end
- if minimum_match = options.delete(:minimum_match)
- fulltext_query.minimum_match = minimum_match.to_i
- end
- if tie = options.delete(:tie)
- fulltext_query.tie = tie.to_f
- end
- if query_phrase_slop = options.delete(:query_phrase_slop)
- fulltext_query.query_phrase_slop = query_phrase_slop.to_i
- end
- if highlight_field_names = options.delete(:highlight)
- if highlight_field_names == true
- fulltext_query.add_highlight
- else
- highlight_fields = []
- Util.Array(highlight_field_names).each do |field_name|
- highlight_fields.concat(@setup.text_fields(field_name))
- end
- fulltext_query.add_highlight(highlight_fields)
- end
- end
- if block && fulltext_query
- fulltext_dsl = Fulltext.new(fulltext_query, @setup)
- Util.instance_eval_or_call(
- fulltext_dsl,
- &block
- )
- end
- if !field_names && (!fulltext_dsl || !fulltext_dsl.fields_added?)
- @setup.all_text_fields.each do |field|
- unless fulltext_query.has_fulltext_field?(field)
- unless fulltext_dsl && fulltext_dsl.exclude_fields.include?(field.name)
- fulltext_query.add_fulltext_field(field, field.default_boost)
- end
- end
- end
- end
- if !field_names && (!fulltext_dsl || !fulltext_dsl.fields_added?)
- unless @setup.all_attachment_fields.empty?
- @setup.all_attachment_fields.each do |attachment_text_field|
- unless fulltext_dsl && fulltext_dsl.exclude_fields.include?(attachment_text_field.name)
- fulltext_query.add_fulltext_field(attachment_text_field, attachment_text_field.default_boost)
- end
- end
- end
- end
- end
- end
- alias_method :keywords, :fulltext
-
- def with(*args)
- case args.first
- when String, Symbol
- field_name = args[0]
- value = args.length > 1 ? args[1] : Scope::NONE
- if value == Scope::NONE
- return DSL::RestrictionWithNear.new(@setup.field(field_name.to_sym), @scope, @query, false)
- end
- end
-
- # else
- super
- end
- end
- end
-end
View
@@ -1,5 +0,0 @@
-module Sunspot
- class Field
- attr_reader :default_boost
- end
-end
@@ -1,4 +1,5 @@
module Sunspot
+
class RichDocument < RSolr::Message::Document
include Enumerable
@@ -11,8 +12,6 @@ def contains_attachment?
return false
end
-
-
def add(connection)
params = {
:wt => :ruby
View
@@ -1,23 +0,0 @@
-module Sunspot
- module Type
-
- # class <<self
-
- class AttachmentType < AbstractType
- def indexed_name(name)
- "#{name}_attachment"
- end
-
- def to_indexed(value)
- value if value
- end
-
- def cast(text)
- text
- end
- end
-
- # end
-
- end
-end
View
@@ -0,0 +1,17 @@
+require 'sunspot/rich_document'
+require 'sunspot_cell/composite_setup'
+Sunspot::CompositeSetup.send(:include, SunspotCell::CompositeSetup)
+require 'sunspot_cell/dsl/fields'
+Sunspot::DSL::Fields.send(:include, SunspotCell::DSL::Fields)
+require 'sunspot_cell/dsl/standard_query'
+Sunspot::DSL::StandardQuery.send(:include, SunspotCell::DSL::StandardQuery)
+require 'sunspot_cell/type'
+Sunspot::Type.send(:include, SunspotCell::Type)
+require 'sunspot_cell/field'
+Sunspot::AttributeField.send(:include, SunspotCell::Field)
+require 'sunspot_cell/setup'
+Sunspot::Setup.send(:include, SunspotCell::Setup)
+require 'sunspot_cell/field_factory'
+Sunspot::FieldFactory.send(:include, SunspotCell::FieldFactory)
+require 'sunspot_cell/indexer'
+Sunspot::Indexer.send(:include, SunspotCell::Indexer)
@@ -0,0 +1,39 @@
+module SunspotCell
+ module CompositeSetup
+
+ extend ActiveSupport::Concern
+
+ module InstanceMethods
+
+ # Collection of all attachment fields configured for any of the enclosed types.
+ #
+ # === Returns
+ #
+ # Array:: Text fields configured for the enclosed types
+ #
+ def all_attachment_fields
+ @attachment_fields ||= attachment_fields_hash.values.map { |set| set.to_a }.flatten
+ end
+
+ private
+
+ # Return a hash of field names to atachment field objects, containing all fields
+ # that are configured for any of the types enclosed.
+ #
+ # ==== Returns
+ #
+ # Hash:: Hash of field names to text field objects.
+ #
+ def attachment_fields_hash
+ @attachment_fields_hash ||=
+ setups.inject({}) do |hash, setup|
+ setup.all_attachment_fields.each do |text_field|
+ (hash[text_field.name] ||= Set.new) << text_field
+ end
+ hash
+ end
+ end
+
+ end
+ end
+end
@@ -0,0 +1,21 @@
+module SunspotCell
+ module DSL
+ module Fields
+
+ extend ActiveSupport::Concern
+
+ module InstanceMethods
+
+ # Added an attachment field, the attachment filename is passed to Solr for
+ # indexing by tiqa
+
+ def attachment(*names)
+ names.each do |name|
+ @setup.add_attachment_field_factory(name)
+ end
+ end
+
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit d53c3a0

Please sign in to comment.