Permalink
Browse files

Store ID in schema, refactor Highlight#format

  • Loading branch information...
1 parent 3dba502 commit fcbba020d1bba88d714d26b9c2fcc303cdc7f577 Mat Brown committed Jul 30, 2009
Showing with 11 additions and 8 deletions.
  1. +8 −5 lib/sunspot/search/highlight.rb
  2. +2 −2 solr/solr/conf/schema.xml
  3. +1 −1 templates/schema.xml.haml
@@ -29,13 +29,16 @@ def initialize(field_name, highlight)
# Returns the highlighted text with formatting according to the template given in &block.
# When no block is given, <em> and </em> are used to surround the highlight.
#
- def format
- highlighted = highlight.match(HIGHLIGHT_MATCHER).captures.first
- result = block_given? ? yield(highlighted) : "<em>#{highlighted}</em>"
- highlight.gsub(HIGHLIGHT_MATCHER, result)
+ def format(&block)
+ block ||= proc { |word| "<em>#{word}</em>" }
+ highlight.gsub(HIGHLIGHT_MATCHER) do
+ # I HATE having to use this magic global, but it seems like the only
+ # way.
+ block.call($1)
+ end
end
alias_method :formatted, :format
end
end
-end
+end
@@ -16,10 +16,10 @@
<fieldtype class='solr.StrField' name='string' omitNorms='true' />
</types>
<fields>
- <field indexed='true' multiValued='false' name='id' stored='false' type='string' />
+ <field indexed='true' multiValued='false' name='id' stored='true' type='string' />
<field indexed='true' multiValued='true' name='type' stored='false' type='string' />
<field indexed='true' multiValued='false' name='class_name' stored='false' type='string' />
- <field indexed='true' multiValued='true' name='text' stored='true' type='text' />
+ <field indexed='true' multiValued='true' name='text' stored='false' type='text' />
<dynamicField indexed='true' multiValued='true' name='*_text' stored='true' type='text' />
<dynamicField indexed='true' name='random_*' stored='false' type='rand' />
<dynamicField indexed='true' multiValued='false' name='*_b' stored='false' type='boolean' />
@@ -14,7 +14,7 @@
%field{ :name => 'type', :type => 'string', :indexed => 'true', :stored => 'false', :multiValued => 'true' }/
%field{ :name => 'class_name', :type => 'string', :indexed => 'true', :stored => 'false', :multiValued => 'false' }/
%field{ :name => 'text', :type => 'text', :indexed => 'true', :stored => 'false', :multiValued => 'true' }/
- %dynamicField{ :name => '*_text', :type => 'text', :indexed => 'true', :stored => 'false', :multiValued => 'true' }/
+ %dynamicField{ :name => '*_text', :type => 'text', :indexed => 'true', :stored => 'true', :multiValued => 'true' }/
%dynamicField{ :name => 'random_*', :type => 'rand', :indexed => 'true', :stored => 'false' }/
- for dynamic_field in schema.dynamic_fields
%dynamicField{ :name => dynamic_field.name, :type => dynamic_field.type, :indexed => 'true', :stored => dynamic_field.stored?, :multiValued => dynamic_field.multiValued? }/

0 comments on commit fcbba02

Please sign in to comment.