Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
MemoryTermPositions.cs
Go to the documentation of this file.
1 /*
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20 */
21 
22 using System;
23 using System.Collections.Generic;
24 using System.Linq;
25 using System.Text;
26 
27 namespace Lucene.Net.Index.Memory
28 {
29  public partial class MemoryIndex
30  {
31  private sealed partial class MemoryIndexReader
32  {
33  private sealed class MemoryTermPositions : TermPositions
34  {
35  private readonly MemoryIndex _index;
36  private readonly MemoryIndexReader _reader;
37  private bool hasNext;
38  private int cursor = 0;
39  private ArrayIntList current;
40  private Term term;
41 
42  public MemoryTermPositions(MemoryIndex index, MemoryIndexReader reader)
43  {
44  _index = index;
45  _reader = reader;
46  }
47 
48  public void Seek(Term term)
49  {
50  this.term = term;
51 
52  if (DEBUG) System.Diagnostics.Debug.WriteLine(".seek: " + term);
53 
54  if (term == null)
55  {
56  hasNext = true; // term==null means match all docs
57  }
58  else
59  {
60  Info info = _reader.GetInfo(term.Field);
61  current = info == null ? null : info.GetPositions(term.Text);
62  hasNext = (current != null);
63  cursor = 0;
64  }
65  }
66 
67  public void Seek(TermEnum termEnum)
68  {
69  if (DEBUG) System.Diagnostics.Debug.WriteLine(".seekEnum");
70  Seek(termEnum.Term);
71  }
72 
73  public int Doc
74  {
75  get
76  {
77  if (DEBUG) System.Diagnostics.Debug.WriteLine(".doc");
78  return 0;
79  }
80  }
81 
82  public int Freq
83  {
84  get
85  {
86  int freq = current != null ? _index.NumPositions(current) : (term == null ? 1 : 0);
87  if (DEBUG) System.Diagnostics.Debug.WriteLine(".freq: " + freq);
88  return freq;
89  }
90  }
91 
92  public bool Next()
93  {
94  if (DEBUG) System.Diagnostics.Debug.WriteLine(".next: " + current + ", oldHasNext=" + hasNext);
95  bool next = hasNext;
96  hasNext = false;
97  return next;
98  }
99 
100  public int Read(int[] docs, int[] freqs)
101  {
102  if (DEBUG) System.Diagnostics.Debug.WriteLine(".read: " + docs.Length);
103  if (!hasNext) return 0;
104  hasNext = false;
105  docs[0] = 0;
106  freqs[0] = Freq;
107  return 1;
108  }
109 
110  public bool SkipTo(int target)
111  {
112  if (DEBUG) System.Diagnostics.Debug.WriteLine(".skipTo: " + target);
113  return Next();
114  }
115 
116  public void Close()
117  {
118  if (DEBUG) System.Diagnostics.Debug.WriteLine(".close");
119  }
120 
121  public void Dispose()
122  {
123  if (DEBUG) System.Diagnostics.Debug.WriteLine(".close");
124  }
125 
126  public int NextPosition()
127  {
128  int pos = current.Get(cursor);
129  cursor += _index.stride;
130  if (DEBUG) System.Diagnostics.Debug.WriteLine(".nextPosition: " + pos);
131  return pos;
132  }
133 
134  public int PayloadLength
135  {
136  get { throw new NotSupportedException(); }
137  }
138 
139  public byte[] GetPayload(byte[] data, int offset)
140  {
141  throw new NotSupportedException();
142  }
143 
144  public bool IsPayloadAvailable
145  {
146  get { return false; }
147  }
148  }
149  }
150  }
151 }