Class: Parse::Constraint::FullTextSearchQueryConstraint

Inherits:
Parse::Constraint show all
Defined in:
lib/parse/query/constraints.rb

Overview

Equivalent to the full text search support with `$text` with a set of search crieteria.

Instance Attribute Summary

Attributes inherited from Parse::Constraint

#operand, #operation, #operator, #value

Instance Method Summary collapse

Methods inherited from Parse::Constraint

#as_json, contraint_keyword, create, #formatted_value, formatted_value, #initialize, #key, #precedence, register, #to_s

Constructor Details

This class inherits a constructor from Parse::Constraint

Instance Method Details

#buildHash

Returns the compiled constraint.

Returns:

  • (Hash)

    the compiled constraint.



734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
# File 'lib/parse/query/constraints.rb', line 734

def build
  params = formatted_value

  params = { :$term => params.to_s } if params.is_a?(String) || params.is_a?(Symbol)

  unless params.is_a?(Hash)
    raise ArgumentError, "[Parse::Query] Invalid query value parameter passed to" \
          " `text_search` constraint: Value must be a string or a hash of parameters."
  end

  params = params.inject({}) do |h, (k, v)|
    u = k.to_s
    u = u.columnize.prepend("$") unless u.start_with?("$")
    h[u] = v
    h
  end

  unless params["$term"].present?
    raise ArgumentError, "[Parse::Query] Invalid query value parameter passed to" \
          " `text_search` constraint: Missing required `$term` subkey.\n" \
          "\tExample: #{@operation.operand}.text_search => { term: 'text to search' }"
  end

  { @operation.operand => { :$text => { :$search => params } } }
end

#text_searchWithinPolygonQueryConstraint

Note:

This method will automatically add `$` to each key of the parameters

A registered method on a symbol to create the constraint. Maps to Parse operator “$text” with “$search” subconstraint. Takes a hash of parameters. Where `parameters` can be one of:

$term : Specify a field to search (Required)
$language : Determines the list of stop words and the rules for tokenizer.
$caseSensitive : Enable or disable case sensitive search.
$diacriticSensitive : Enable or disable diacritic sensitive search

hash if it doesn't already have it.

Examples:

# As many points as you want
q.where :field.text_search => {parameters}

Returns:

Version:

  • 1.8.0 (requires Server v2.5.0 or later)



730
# File 'lib/parse/query/constraints.rb', line 730

contraint_keyword :$text