Class: Mincer::PgSearch::SearchEngines::Fulltext

Inherits:
Base
  • Object
show all
Defined in:
lib/mincer/processors/pg_search/search_engines/fulltext.rb

Constant Summary collapse

DISALLOWED_TSQUERY_CHARACTERS =
/[!(:&|)'?\\]/

Instance Attribute Summary

Attributes inherited from Base

#args, #search_statements

Instance Method Summary collapse

Methods inherited from Base

#arel_group, #engine_sym, #initialize, #quote, #sanitize_column, #sanitize_string, #sanitize_string_quoted, #search_engine_statements

Methods included from Mincer::Processors::Helpers

#join_expressions

Constructor Details

This class inherits a constructor from Mincer::PgSearch::SearchEngines::Base

Instance Method Details

#conditionsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mincer/processors/pg_search/search_engines/fulltext.rb', line 7

def conditions
  return nil unless prepared_search_statements.any?
  arel_group do
    documents = prepared_search_statements.map do |search_statement|
      ts_query = ts_query_for(search_statement)
      ts_vectors_for(search_statement).map do |ts_vector|
        arel_group(Arel::Nodes::InfixOperation.new('@@', ts_vector, ts_query))
      end
    end.flatten

    join_expressions(documents, :or)
  end
end

#rankObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mincer/processors/pg_search/search_engines/fulltext.rb', line 21

def rank
  return nil unless prepared_search_statements.any?
  arel_group do
    ranks = prepared_search_statements.map do |search_statement|
      ts_query = ts_query_for(search_statement)
      ts_vectors_for(search_statement).map do |ts_vector|
        Arel::Nodes::NamedFunction.new('ts_rank', [ts_vector, ts_query])
      end
    end.flatten

    join_expressions(ranks, '+')
  end
end