-
Notifications
You must be signed in to change notification settings - Fork 242
/
TextMultiValues.java
121 lines (100 loc) · 3.14 KB
/
TextMultiValues.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
69
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.backend.lucene.lowlevel.docvalues.impl;
import java.io.IOException;
import org.apache.lucene.index.SortedSetDocValues;
/**
* A per-document, unordered sequence of text ordinals.
* <p>
* Essentially, this is a wrapper around {@link SortedSetDocValues} that may support joins,
* but does not guarantee that ordinals for a given documents are returned in ascending order.
* <p>
* Some of this code was copied and adapted from
* {@code org.apache.lucene.index.SortedSetDocValues}
* of <a href="https://lucene.apache.org/">Apache Lucene project</a>.
*/
public abstract class TextMultiValues {
/**
* Sole constructor. (For invocation by subclass
* constructors, typically implicit.)
*/
protected TextMultiValues() {
}
/**
* Advance this instance to the given document id
*
* @return true if there is a value for this document
*/
public abstract boolean advanceExact(int doc) throws IOException;
/**
* @return true if there is a next value for this document,
* i.e. if nextValue() can be called.
*/
public abstract boolean hasNextValue() throws IOException;
/**
* @return The next value for the current document.
* Can only be called after {@link #hasNextValue()} returned {@code true}.
*/
public abstract long nextOrd() throws IOException;
/**
* Returns the number of unique values.
* @return number of unique values in this SortedDocValues. This is
* also equivalent to one plus the maximum ordinal.
*/
public abstract long getValueCount();
public static TextMultiValues fromDocValues(SortedSetDocValues docValues) {
return new DocValuesTextMultiValues( docValues );
}
/**
* An empty DoubleMultiValues instance that always returns {@code false} from {@link #advanceExact(int)}
*/
public static final TextMultiValues EMPTY = new TextMultiValues() {
@Override
public boolean advanceExact(int doc) {
return false;
}
@Override
public boolean hasNextValue() {
throw new UnsupportedOperationException();
}
@Override
public long nextOrd() {
throw new UnsupportedOperationException();
}
@Override
public long getValueCount() {
return 0;
}
};
protected static class DocValuesTextMultiValues extends TextMultiValues {
protected final SortedSetDocValues values;
protected long nextOrd;
DocValuesTextMultiValues(SortedSetDocValues values) {
this.values = values;
}
@Override
public boolean advanceExact(int doc) throws IOException {
boolean found = values.advanceExact( doc );
nextOrd = found ? values.nextOrd() : SortedSetDocValues.NO_MORE_ORDS;
return found;
}
@Override
public boolean hasNextValue() throws IOException {
return nextOrd != SortedSetDocValues.NO_MORE_ORDS;
}
@Override
public long nextOrd() throws IOException {
long result = nextOrd;
nextOrd = values.nextOrd();
return result;
}
@Override
public long getValueCount() {
return values.getValueCount();
}
}
}