class Riak::Search::Query
A {Riak::Search::Query} wraps a Solr query for Riak
Search
2.
Attributes
@!attribute [r] client @return [Riak::Client] the client to query against
@!attribute df @return [Array<String>] default fields for Solr to search
@!attribute filter @return [String] have Solr filter the results prior to returning them
@!attribute fl @return [Array<String>] fields for Solr to return
@!attribute [r] index @return [Riak::Search::Index] the index to query against
@!attribute op @return [String] Solr search operator
@!attribute rows @return [Numeric] the number of rows to return from the query
@!attribute sort @return [String] how Solr should sort the result set
@!attribute start @return [Numeric] the offset into the total result set to get results for
@!attribute [r] term @return [String] the term to query
Public Class Methods
Initializes a query object.
@param [Riak::Client] client the client connected to the Riak
cluster @param [String,Riak::Search::Index] index the index to query, either a
{Riak::Search::Index} instance or a {String}
@param [String] term the query term @param [Hash] options a hash of options to quickly set attributes
# File lib/riak/search/query.rb, line 54 def initialize(client, index, term, options = { }) @client = client validate_index index @term = term @options = options.symbolize_keys set_defaults consume_options end
Public Instance Methods
Get results from the query. Performs the query when called the first time.
@return [Riak::Search::ResultCollection] collection of results
# File lib/riak/search/query.rb, line 67 def results return @results if defined? @results @results = ResultCollection.new @client, raw_results end
Private Instance Methods
# File lib/riak/search/query.rb, line 110 def consume_options @rows = @options[:rows] if @options[:rows] @start = @options[:start] if @options[:start] @sort = @options[:sort] if @options[:sort] @filter = @options[:filter] if @options[:filter] @df = @options[:df] if @options[:df] @op = @options[:op] if @options[:op] @fl = @options[:fl] if @options[:fl] end
# File lib/riak/search/query.rb, line 75 def index_name return @index if @index.is_a? String return @index.name end
# File lib/riak/search/query.rb, line 122 def prepare_options configured_options = { rows: @rows, start: @start, sort: @sort, filter: @filter, df: @df.join(' '), op: @op, fl: @fl } @options.merge configured_options end
# File lib/riak/search/query.rb, line 135 def raw_results @client.backend do |be| be.search index_name, @term, prepare_options end end
# File lib/riak/search/query.rb, line 96 def set_defaults @rows = nil @start = nil @sort = nil @filter = nil @df = %w{text} @op = nil @fl = %w{_yz_rb _yz_rk _yz_rt score} @presort = nil end
# File lib/riak/search/query.rb, line 80 def validate_index(index) if index.is_a? String index = Riak::Search::Index.new @client, index end unless index.is_a? Riak::Search::Index raise Riak::SearchError::IndexArgumentError.new index end unless index.exists? raise Riak::SearchError::IndexNonExistError.new index.name end @index = index end