Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #1682: Support auto-complete via querying main Lucene direct…
…ory (#1683) * Current State is rough * Resolves #1682: Support auto-complete via querying main Lucene directory This modifies the auto-complete cursor so that it reads from the main Lucene index and then reconstitutes the original text by reading from the base record data. Co-authored-by: john_leach <jleach4@gmail.com>
- Loading branch information
1 parent
d0e98a7
commit 606bfb8
Showing
13 changed files
with
835 additions
and
1,112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
501 changes: 438 additions & 63 deletions
501
...ne/src/main/java/com/apple/foundationdb/record/lucene/LuceneAutoCompleteResultCursor.java
Large diffs are not rendered by default.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
...r-lucene/src/main/java/com/apple/foundationdb/record/lucene/LuceneCursorContinuation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* LuceneCursorContinuation.java | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2015-2022 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.apple.foundationdb.record.lucene; | ||
|
||
import com.apple.foundationdb.record.RecordCursorContinuation; | ||
import com.google.protobuf.ByteString; | ||
import org.apache.lucene.search.ScoreDoc; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Continuation from scanning a Lucene index. This wraps the LuceneIndexContinuation protobuf message, | ||
* which contains enough information to use the Lucene | ||
* {@link org.apache.lucene.search.IndexSearcher#searchAfter(ScoreDoc, org.apache.lucene.search.Query, int) searchAfter} | ||
* feature to resume a query. | ||
*/ | ||
class LuceneCursorContinuation implements RecordCursorContinuation { | ||
@Nonnull | ||
private final LuceneContinuationProto.LuceneIndexContinuation protoContinuation; | ||
|
||
@SuppressWarnings("squid:S3077") // Byte array is immutable once created, so does not need to use atomic array | ||
private volatile byte[] byteContinuation; | ||
|
||
private LuceneCursorContinuation(@Nonnull LuceneContinuationProto.LuceneIndexContinuation protoContinuation) { | ||
this.protoContinuation = protoContinuation; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public byte[] toBytes() { | ||
if (byteContinuation == null) { | ||
synchronized (this) { | ||
if (byteContinuation == null) { | ||
byteContinuation = toByteString().toByteArray(); | ||
} | ||
} | ||
} | ||
return byteContinuation; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public ByteString toByteString() { | ||
return protoContinuation.toByteString(); | ||
} | ||
|
||
@Override | ||
public boolean isEnd() { | ||
return false; | ||
} | ||
|
||
public static LuceneCursorContinuation fromScoreDoc(ScoreDoc scoreDoc) { | ||
return new LuceneCursorContinuation(LuceneContinuationProto.LuceneIndexContinuation.newBuilder() | ||
.setDoc(scoreDoc.doc) | ||
.setShard(scoreDoc.shardIndex) | ||
.setScore(scoreDoc.score) | ||
.build() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.