Class: Csquery::Structured

Inherits:
Object
  • Object
show all
Defined in:
lib/csquery/structured.rb

Class Method Summary collapse

Class Method Details

.and_(*args, **kwargs) ⇒ Object



8
9
10
# File 'lib/csquery/structured.rb', line 8

def and_(*args, **kwargs)
  Expression.new('and', *args, options: _get_option([:boost], kwargs), **kwargs)
end

.field(value, name = nil) ⇒ Object



4
5
6
# File 'lib/csquery/structured.rb', line 4

def field(value, name = nil)
  FieldValue.new(value: value, name: name)
end

.format_options(options = {}) ⇒ Object



60
61
62
63
64
# File 'lib/csquery/structured.rb', line 60

def format_options(options={})
  return '' unless options

  ' ' + options.map{|k,v| "#{k}=#{v}"}.join(' ')
end

.format_value(value) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/csquery/structured.rb', line 40

def format_value(value)
  return format_range_values(*value) if value.is_a?(Array)

  return "#{value}" if value.is_a?(Numeric)

  return value.query if value.is_a?(Expression)

  value = value.to_s

  if(value.start_with?('(') and value.end_with?(')'))\
    or(value.start_with?('{') and value.end_with?(']'))\
    or(value.start_with?('[') and value.end_with?('}'))\
    or(value.start_with?('[') and value.end_with?(']'))

    return value
  end

  "'#{escape(value)}'"
end

.near_(*args, **kwargs) ⇒ Object



24
25
26
# File 'lib/csquery/structured.rb', line 24

def near_(*args, **kwargs)
  Expression.new('near', *args, options: _get_option([:field, :distance, :boost], kwargs), **kwargs)
end

.not_(*args, **kwargs) ⇒ Object



12
13
14
# File 'lib/csquery/structured.rb', line 12

def not_(*args, **kwargs)
  Expression.new('not', *args, options: _get_option([:field, :boost], kwargs), **kwargs)
end

.or_(*args, **kwargs) ⇒ Object



16
17
18
# File 'lib/csquery/structured.rb', line 16

def or_(*args, **kwargs)
  Expression.new('or', *args, options: _get_option([:boost], kwargs), **kwargs)
end

.phrase_(*args, **kwargs) ⇒ Object



28
29
30
# File 'lib/csquery/structured.rb', line 28

def phrase_(*args, **kwargs)
  Expression.new('phrase', *args, options: _get_option([:field, :boost], kwargs), **kwargs)
end

.prefix_(*args, **kwargs) ⇒ Object



32
33
34
# File 'lib/csquery/structured.rb', line 32

def prefix_(*args, **kwargs)
  Expression.new('prefix', *args, options: _get_option([:field, :boost], kwargs), **kwargs)
end

.range_(*args, **kwargs) ⇒ Object



36
37
38
# File 'lib/csquery/structured.rb', line 36

def range_(*args, **kwargs)
  Expression.new('range', *args, options: _get_option([:field, :boost], kwargs), **kwargs)
end

.term_(*args, **kwargs) ⇒ Object



20
21
22
# File 'lib/csquery/structured.rb', line 20

def term_(*args, **kwargs)
  Expression.new('term', *args, options: _get_option([:field, :boost], kwargs), **kwargs)
end