Skip to content

Commit 5c79291

Browse files
bhabeggerclaude
andcommitted
refactor: reorder methods to match legacy Lucene structure
Reorder method declarations in LuceneNg classes to match the order used in legacy oak-lucene classes for easier side-by-side comparison: - LuceneNgIndex: getIndexName() and getPlan() moved up - OakDirectory: methods follow legacy order (listAll, deleteFile, etc.) - OakIndexInput: readBytes, readByte, seek, length, getFilePointer order - OakIndexOutput: getFilePointer, writeBytes, writeByte order - OakBufferedIndexFile: clone/length/position/close/isClosed/seek order No functional changes - pure refactoring for code organization. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b15e771 commit 5c79291

5 files changed

Lines changed: 142 additions & 142 deletions

File tree

oak-search-luceneNg/src/main/java/org/apache/jackrabbit/oak/plugins/index/luceneNg/LuceneNgIndex.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public double getMinimumCost() {
6262
return 2.0; // Better than traversal (1000+) but not as good as unique lookup (1.0)
6363
}
6464

65+
@Override
66+
public String getIndexName() {
67+
return "luceneNg";
68+
}
69+
6570
@Override
6671
public double getCost(Filter filter, NodeState rootState) {
6772
// Check if we can handle this query
@@ -85,6 +90,11 @@ public double getCost(Filter filter, NodeState rootState) {
8590
return Double.POSITIVE_INFINITY;
8691
}
8792

93+
@Override
94+
public String getPlan(Filter filter, NodeState rootState) {
95+
return "lucene9:" + indexPath + " ft=" + filter.getFullTextConstraint();
96+
}
97+
8898
@Override
8999
public Cursor query(Filter filter, NodeState rootState) {
90100
try {
@@ -244,16 +254,6 @@ private static List<String> tokenize(String text, Analyzer analyzer) {
244254
return tokens;
245255
}
246256

247-
@Override
248-
public String getPlan(Filter filter, NodeState rootState) {
249-
return "lucene9:" + indexPath + " ft=" + filter.getFullTextConstraint();
250-
}
251-
252-
@Override
253-
public String getIndexName() {
254-
return "luceneNg";
255-
}
256-
257257
/**
258258
* Navigates to the index definition node from the root state.
259259
* Example: indexPath="/oak:index/myIndex" returns builder for that node.

oak-search-luceneNg/src/main/java/org/apache/jackrabbit/oak/plugins/index/luceneNg/directory/OakBufferedIndexFile.java

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,46 @@ private OakBufferedIndexFile(OakBufferedIndexFile that) {
129129
this.dataModified = that.dataModified;
130130
}
131131

132+
private void loadBlob(int i) throws IOException {
133+
if (i < 0 || i >= data.size()) {
134+
throw new IndexOutOfBoundsException("Invalid chunk index: " + i);
135+
}
136+
137+
if (index != i) {
138+
flushBlob();
139+
140+
int bytesToRead = (int) Math.min(blobSize, length - (long) i * blobSize);
141+
try (InputStream stream = data.get(i).getNewStream()) {
142+
IOUtils.readFully(stream, blob, 0, bytesToRead);
143+
}
144+
145+
index = i;
146+
}
147+
}
148+
149+
private void flushBlob() throws IOException {
150+
if (blobModified) {
151+
int bytesToWrite = (int) Math.min(blobSize, length - (long) index * blobSize);
152+
InputStream in = new ByteArrayInputStream(blob, 0, bytesToWrite);
153+
154+
Blob b = blobFactory.createBlob(in);
155+
if (index < data.size()) {
156+
data.set(index, b);
157+
} else {
158+
if (index != data.size()) {
159+
throw new IllegalStateException("Gap in chunks: index=" + index + ", data.size=" + data.size());
160+
}
161+
data.add(b);
162+
}
163+
164+
dataModified = true;
165+
blobModified = false;
166+
}
167+
}
168+
132169
@Override
133-
public String getName() {
134-
return name;
170+
public OakIndexFile clone() {
171+
return new OakBufferedIndexFile(this);
135172
}
136173

137174
@Override
@@ -140,8 +177,8 @@ public long length() {
140177
}
141178

142179
@Override
143-
public boolean isClosed() {
144-
return blob == null && data == null;
180+
public long position() {
181+
return position;
145182
}
146183

147184
@Override
@@ -151,8 +188,8 @@ public void close() {
151188
}
152189

153190
@Override
154-
public long position() {
155-
return position;
191+
public boolean isClosed() {
192+
return blob == null && data == null;
156193
}
157194

158195
@Override
@@ -166,11 +203,6 @@ public void seek(long pos) throws IOException {
166203
position = pos;
167204
}
168205

169-
@Override
170-
public OakIndexFile clone() {
171-
return new OakBufferedIndexFile(this);
172-
}
173-
174206
@Override
175207
public void readBytes(byte[] b, int offset, int len) throws IOException {
176208
if (b == null) {
@@ -234,6 +266,13 @@ public void writeBytes(byte[] b, int offset, int len) throws IOException {
234266
}
235267
}
236268

269+
private static int determineBlobSize(NodeBuilder file) {
270+
if (file.hasProperty(OakDirectory.PROP_BLOB_SIZE)) {
271+
return Math.toIntExact(file.getProperty(OakDirectory.PROP_BLOB_SIZE).getValue(Type.LONG));
272+
}
273+
return DEFAULT_BLOB_SIZE;
274+
}
275+
237276
@Override
238277
public void flush() throws IOException {
239278
flushBlob();
@@ -244,52 +283,13 @@ public void flush() throws IOException {
244283
}
245284
}
246285

247-
private void loadBlob(int i) throws IOException {
248-
if (i < 0 || i >= data.size()) {
249-
throw new IndexOutOfBoundsException("Invalid chunk index: " + i);
250-
}
251-
252-
if (index != i) {
253-
flushBlob();
254-
255-
int bytesToRead = (int) Math.min(blobSize, length - (long) i * blobSize);
256-
try (InputStream stream = data.get(i).getNewStream()) {
257-
IOUtils.readFully(stream, blob, 0, bytesToRead);
258-
}
259-
260-
index = i;
261-
}
262-
}
263-
264-
private void flushBlob() throws IOException {
265-
if (blobModified) {
266-
int bytesToWrite = (int) Math.min(blobSize, length - (long) index * blobSize);
267-
InputStream in = new ByteArrayInputStream(blob, 0, bytesToWrite);
268-
269-
Blob b = blobFactory.createBlob(in);
270-
if (index < data.size()) {
271-
data.set(index, b);
272-
} else {
273-
if (index != data.size()) {
274-
throw new IllegalStateException("Gap in chunks: index=" + index + ", data.size=" + data.size());
275-
}
276-
data.add(b);
277-
}
278-
279-
dataModified = true;
280-
blobModified = false;
281-
}
282-
}
283-
284-
private static int determineBlobSize(NodeBuilder file) {
285-
if (file.hasProperty(OakDirectory.PROP_BLOB_SIZE)) {
286-
return Math.toIntExact(file.getProperty(OakDirectory.PROP_BLOB_SIZE).getValue(Type.LONG));
287-
}
288-
return DEFAULT_BLOB_SIZE;
286+
@Override
287+
public String toString() {
288+
return name;
289289
}
290290

291291
@Override
292-
public String toString() {
292+
public String getName() {
293293
return name;
294294
}
295295
}

oak-search-luceneNg/src/main/java/org/apache/jackrabbit/oak/plugins/index/luceneNg/directory/OakDirectory.java

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,6 @@ public OakDirectory(NodeBuilder definitionBuilder, String indexName, boolean rea
8080
this.fileNames.addAll(getListing());
8181
}
8282

83-
/**
84-
* Gets the directory builder dynamically to avoid staleness issues.
85-
*/
86-
private NodeBuilder getDirectoryBuilder() {
87-
if (readOnly) {
88-
return definitionBuilder.getChildNode(INDEX_DATA_CHILD_NAME);
89-
} else {
90-
return definitionBuilder.child(INDEX_DATA_CHILD_NAME);
91-
}
92-
}
93-
9483
@Override
9584
public String[] listAll() throws IOException {
9685
return fileNames.toArray(new String[0]);
@@ -139,16 +128,49 @@ public IndexOutput createOutput(String name, IOContext context) throws IOExcepti
139128
}
140129

141130
@Override
142-
public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
143-
String name = getTempFileName(prefix, suffix, 0);
144-
return createOutput(name, context);
131+
public IndexInput openInput(String name, IOContext context) throws IOException {
132+
NodeBuilder file = getDirectoryBuilder().getChildNode(name);
133+
if (!file.exists()) {
134+
throw new FileNotFoundException(String.format("[%s] %s", indexName, name));
135+
}
136+
return new OakIndexInput(name, file, indexName, blobFactory);
137+
}
138+
139+
@Override
140+
public Lock obtainLock(String name) throws IOException {
141+
// Oak storage doesn't require locking - return a dummy lock
142+
return new Lock() {
143+
@Override
144+
public void close() throws IOException {
145+
// No-op
146+
}
147+
148+
@Override
149+
public void ensureValid() throws IOException {
150+
// No-op
151+
}
152+
};
145153
}
146154

147155
@Override
148156
public void sync(Collection<String> names) throws IOException {
149157
// No-op for Oak storage
150158
}
151159

160+
@Override
161+
public void close() throws IOException {
162+
if (!readOnly) {
163+
// Save directory listing
164+
getDirectoryBuilder().setProperty(createProperty(PROP_DIR_LISTING, fileNames, Type.STRINGS));
165+
}
166+
}
167+
168+
@Override
169+
public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
170+
String name = getTempFileName(prefix, suffix, 0);
171+
return createOutput(name, context);
172+
}
173+
152174
@Override
153175
public void syncMetaData() throws IOException {
154176
// No-op for Oak storage
@@ -176,42 +198,20 @@ public void rename(String source, String dest) throws IOException {
176198
sourceFile.remove();
177199
}
178200

179-
@Override
180-
public IndexInput openInput(String name, IOContext context) throws IOException {
181-
NodeBuilder file = getDirectoryBuilder().getChildNode(name);
182-
if (!file.exists()) {
183-
throw new FileNotFoundException(String.format("[%s] %s", indexName, name));
184-
}
185-
return new OakIndexInput(name, file, indexName, blobFactory);
186-
}
187-
188-
@Override
189-
public void close() throws IOException {
190-
if (!readOnly) {
191-
// Save directory listing
192-
getDirectoryBuilder().setProperty(createProperty(PROP_DIR_LISTING, fileNames, Type.STRINGS));
193-
}
194-
}
195-
196201
@Override
197202
public Set<String> getPendingDeletions() throws IOException {
198203
return Set.of();
199204
}
200205

201-
@Override
202-
public Lock obtainLock(String name) throws IOException {
203-
// Oak storage doesn't require locking - return a dummy lock
204-
return new Lock() {
205-
@Override
206-
public void close() throws IOException {
207-
// No-op
208-
}
209-
210-
@Override
211-
public void ensureValid() throws IOException {
212-
// No-op
213-
}
214-
};
206+
/**
207+
* Gets the directory builder dynamically to avoid staleness issues.
208+
*/
209+
private NodeBuilder getDirectoryBuilder() {
210+
if (readOnly) {
211+
return definitionBuilder.getChildNode(INDEX_DATA_CHILD_NAME);
212+
} else {
213+
return definitionBuilder.child(INDEX_DATA_CHILD_NAME);
214+
}
215215
}
216216

217217
private Set<String> getListing() {

oak-search-luceneNg/src/main/java/org/apache/jackrabbit/oak/plugins/index/luceneNg/directory/OakIndexInput.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,28 @@ private OakIndexInput(OakIndexInput other, String sliceDescription, long offset,
4848
}
4949

5050
@Override
51-
public void close() throws IOException {
52-
file.close();
51+
public void readBytes(byte[] b, int offset, int len) throws IOException {
52+
if (file.isClosed()) {
53+
throw new IOException("IndexInput is closed");
54+
}
55+
long pos = getFilePointer();
56+
if (pos + len > sliceLength) {
57+
throw new IOException("read past EOF: " + (pos + len) + " > " + sliceLength);
58+
}
59+
file.readBytes(b, offset, len);
5360
}
5461

5562
@Override
56-
public long getFilePointer() {
57-
// Return position relative to slice start
58-
return file.position() - sliceOffset;
63+
public byte readByte() throws IOException {
64+
if (file.isClosed()) {
65+
throw new IOException("IndexInput is closed");
66+
}
67+
if (getFilePointer() >= sliceLength) {
68+
throw new IOException("read past EOF: " + getFilePointer());
69+
}
70+
byte[] b = new byte[1];
71+
file.readBytes(b, 0, 1);
72+
return b[0];
5973
}
6074

6175
@Override
@@ -79,6 +93,12 @@ public long length() {
7993
return sliceLength;
8094
}
8195

96+
@Override
97+
public long getFilePointer() {
98+
// Return position relative to slice start
99+
return file.position() - sliceOffset;
100+
}
101+
82102
@Override
83103
public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
84104
if (file.isClosed()) {
@@ -94,27 +114,7 @@ public IndexInput slice(String sliceDescription, long offset, long length) throw
94114
}
95115

96116
@Override
97-
public byte readByte() throws IOException {
98-
if (file.isClosed()) {
99-
throw new IOException("IndexInput is closed");
100-
}
101-
if (getFilePointer() >= sliceLength) {
102-
throw new IOException("read past EOF: " + getFilePointer());
103-
}
104-
byte[] b = new byte[1];
105-
file.readBytes(b, 0, 1);
106-
return b[0];
107-
}
108-
109-
@Override
110-
public void readBytes(byte[] b, int offset, int len) throws IOException {
111-
if (file.isClosed()) {
112-
throw new IOException("IndexInput is closed");
113-
}
114-
long pos = getFilePointer();
115-
if (pos + len > sliceLength) {
116-
throw new IOException("read past EOF: " + (pos + len) + " > " + sliceLength);
117-
}
118-
file.readBytes(b, offset, len);
117+
public void close() throws IOException {
118+
file.close();
119119
}
120120
}

0 commit comments

Comments
 (0)