Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more mucking

  • Loading branch information...
commit 6de3d8516b709b208a499ae5e8df8033d24e6130 1 parent f406ffd
@adamhjk authored
View
4 .gitignore
@@ -5,3 +5,7 @@ db/iclassify_*
db/schema.rb
icagent.uuid
index/*
+vendor/plugins/acts_as_solr/solr/solr/data/*
+vendor/plugins/acts_as_solr/solr/logs/*
+vendor/plugins/acts_as_solr/solr/tmp/*
+
View
82 app/models/node.rb
@@ -30,7 +30,7 @@ class Node < ActiveRecord::Base
# acts_as_ferret(:fields => [ :uuid, :notes, :description, :tag ], :remote => true )
- acts_as_solr(:fields => [ :uuid, :notes, :description, :tag ],
+ acts_as_solr(:fields => [ {:uuid => :string}, {:notes => :string}, {:description => :string}, {:tag => :string} ],
:auto_commit => true)
# FIXME: Acts as tree needs to be added.
@@ -78,7 +78,7 @@ def solr_save
if evaluate_condition(configuration[:if], self)
logger.debug "solr_save: #{self.class.name} : #{record_id(self)}"
this_doc = to_solr_doc
- field_type = configuration[:facets] && configuration[:facets].include?(field) ? :facet : :text
+ field_type = configuration[:facets] && configuration[:facets].include?(field) ? :facet : :string
field_boost= solr_configuration[:default_boost]
suffix = get_solr_field_type(field_type)
attribs.each do |attrib|
@@ -100,6 +100,37 @@ def solr_save
end
end
+ def check_solr_string(v)
+ if v =~ /(\.|\_|\:|\*|\(|\)|\-|\=)/
+ get_solr_field_type(:string)
+ else
+ get_solr_field_type(:text)
+ end
+ end
+
+ # Replaces the field types based on the types (if any) specified
+ # on the acts_as_solr call
+ def replace_types(strings, include_colon=true)
+ suffix = include_colon ? ":" : ""
+ if configuration[:solr_fields] && configuration[:solr_fields].is_a?(Array)
+ configuration[:solr_fields].each do |solr_field|
+ field_type = get_solr_field_type(:string)
+ if solr_field.is_a?(Hash)
+ solr_field.each do |name,value|
+ if value.respond_to?(:each_pair)
+ field_type = get_solr_field_type(value[:type]) if value[:type]
+ else
+ field_type = get_solr_field_type(value)
+ end
+ field = "#{name.to_s}_#{field_type}#{suffix}"
+ strings.each_with_index { |s,i| strings[i] = s.gsub(/#{name.to_s}_s#{suffix}/,field) }
+ end
+ end
+ end
+ end
+ strings
+ end
+
def tag
tags.collect { |t| t.name }
end
@@ -181,6 +212,53 @@ def update_with_tags_and_attribs(params, tag_array=nil, attrib_array=nil)
self.save
end
+ def parse_query(query=nil, options={}, models=nil)
+ valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator]
+ query_options = {}
+ return if query.nil?
+ raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty?
+ begin
+ Deprecation.validate_query(options)
+ query_options[:start] = options[:offset]
+ query_options[:rows] = options[:limit]
+ query_options[:operator] = options[:operator]
+
+ # first steps on the facet parameter processing
+ if options[:facets]
+ query_options[:facets] = {}
+ query_options[:facets][:limit] = -1 # TODO: make this configurable
+ query_options[:facets][:sort] = :count if options[:facets][:sort]
+ query_options[:facets][:mincount] = 0
+ query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false
+ query_options[:facets][:fields] = options[:facets][:fields].collect{|k| "#{k}_facet"} if options[:facets][:fields]
+ query_options[:filter_queries] = replace_types(options[:facets][:browse].collect{|k| "#{k.sub!(/ *: */,"_facet:")}"}) if options[:facets][:browse]
+ query_options[:facets][:queries] = replace_types(options[:facets][:query].collect{|k| "#{k.sub!(/ *: */,"_t:")}"}) if options[:facets][:query]
+ end
+
+ if models.nil?
+ # TODO: use a filter query for type, allowing Solr to cache it individually
+ models = "AND #{solr_configuration[:type_field]}:#{self.name}"
+ field_list = solr_configuration[:primary_key_field]
+ else
+ field_list = "id"
+ end
+
+ query_options[:field_list] = [field_list, 'score']
+ query = "(#{query.gsub(/ *: */,"_s:")}) #{models}"
+ order = options[:order].split(/\s*,\s*/).collect{|e| e.gsub(/\s+/,'_t ').gsub(/\bscore_t\b/, 'score') }.join(',') if options[:order]
+ query_options[:query] = replace_types([query])[0] # TODO adjust replace_types to work with String or Array
+
+ if options[:order]
+ # TODO: set the sort parameter instead of the old ;order. style.
+ query_options[:query] << ';' << replace_types([order], false)[0]
+ end
+
+ ActsAsSolr::Post.execute(Solr::Request::Standard.new(query_options))
+ rescue
+ raise "There was a problem executing your search: #{$!}"
+ end
+ end
+
# Serializes all the nodes in the database
def self.rest_serialize_all
rest_array = Array.new
View
10 vendor/plugins/acts_as_solr/solr/solr/conf/schema.xml
@@ -48,11 +48,11 @@
</analyzer>
</fieldType>
- <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
- <analyzer type="index">
+ <fieldType name="text" class="solr.StrField" sortMissingLast="true" omitNorms="false">
+ <!-- <analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
- <!-- <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0"/> -->
+ <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EnglishPorterFilterFactory" protected="protwords.txt"/>
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
@@ -61,11 +61,11 @@
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
- <!-- <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0"/> -->
+ <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EnglishPorterFilterFactory" protected="protwords.txt"/>
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
- </analyzer>
+ </analyzer> -->
</fieldType>
<fieldType name="textTight" class="solr.TextField" positionIncrementGap="100" >
Please sign in to comment.
Something went wrong with that request. Please try again.