Class: Ferret::Search::Spans::SpanNotQuery::SpanNotEnum

Inherits:
Ferret::Search::Spans::SpansEnum show all
Defined in:
lib/ferret/search/spans/span_not_query.rb

Instance Method Summary collapse

Constructor Details

#initialize(query, reader) ⇒ SpanNotEnum

Returns a new instance of SpanNotEnum.



35
36
37
38
39
40
41
# File 'lib/ferret/search/spans/span_not_query.rb', line 35

def initialize(query, reader)
  @query = query
  @incl_spans = @query.incl.spans(reader)
  @more_incl = true
  @excl_spans = @query.excl.spans(reader)
  @more_excl = @excl_spans.next? # excl_spans needs to be preset
end

Instance Method Details

#docObject



98
# File 'lib/ferret/search/spans/span_not_query.rb', line 98

def doc() @incl_spans.doc end

#finishObject



100
# File 'lib/ferret/search/spans/span_not_query.rb', line 100

def finish() @incl_spans.finish end

#next?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ferret/search/spans/span_not_query.rb', line 43

def next?()
  if (@more_incl)                          # move to next incl
    @more_incl = @incl_spans.next?()
  end

  while (@more_incl and @more_excl) 
    if (@incl_spans.doc > @excl_spans.doc) # skip excl
      @more_excl = @excl_spans.skip_to(@incl_spans.doc)
    end

    while (@more_excl and                  # while excl is before
           @incl_spans.doc == @excl_spans.doc and
           @excl_spans.finish <= @incl_spans.start) 
      @more_excl = @excl_spans.next?       # increment excl
    end

    if (not @more_excl or                  # if no intersection
        @incl_spans.doc != @excl_spans.doc or
        @incl_spans.finish <= @excl_spans.start)
      break                                # we found a match
    end

    @more_incl = @incl_spans.next?         # intersected: keep scanning
  end
  return @more_incl
end

#skip_to(target) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ferret/search/spans/span_not_query.rb', line 70

def skip_to(target)
  if @more_incl                            # skip incl
    @more_incl = @incl_spans.skip_to(target)
  end

  if not @more_incl
    return false
  end

  if (@more_excl and @incl_spans.doc > @excl_spans.doc) # skip excl
    @more_excl = @excl_spans.skip_to(@incl_spans.doc)
  end

  while (@more_excl and                    # while excl is before
         @incl_spans.doc == @excl_spans.doc and
         @excl_spans.finish <= @incl_spans.start) 
    @more_excl = @excl_spans.next?         # increment excl
  end

  if (not @more_excl or                    # if no intersection
        @incl_spans.doc != @excl_spans.doc or
        @incl_spans.finish <= @excl_spans.start)
    return true                            # we found a match
  end

  return next?()                           # scan to next match
end

#startObject



99
# File 'lib/ferret/search/spans/span_not_query.rb', line 99

def start() @incl_spans.start end

#to_sObject



102
103
104
# File 'lib/ferret/search/spans/span_not_query.rb', line 102

def to_s() 
  return "spans(#{@query})"
end