-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable _terms_enum API for version fields (#93839)
The _terms_enum API currently only supports the keyword, constant_keyword and flattened field type. This change adds support for the `version` field type that sorts according to the semantic versioning definition. Closes #83403
- Loading branch information
Showing
12 changed files
with
349 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 93839 | ||
summary: Enable _terms_enum on version fields | ||
area: Search | ||
type: enhancement | ||
issues: | ||
- 83403 |
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
35 changes: 35 additions & 0 deletions
35
server/src/main/java/org/elasticsearch/index/mapper/SearchAfterTermsEnum.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,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.index.mapper; | ||
|
||
import org.apache.lucene.index.FilteredTermsEnum; | ||
import org.apache.lucene.index.TermsEnum; | ||
import org.apache.lucene.util.BytesRef; | ||
|
||
/** | ||
* This terms enumeration initializes with a seek to a given term but excludes that term | ||
* from any results. The problem it addresses is that termsEnum.seekCeil() | ||
* would work but either leaves us positioned on the seek term (if it exists) or the | ||
* term after (if the seek term doesn't exist). That complicates any subsequent | ||
* iteration logic so this class simplifies the pagination use case. | ||
*/ | ||
public final class SearchAfterTermsEnum extends FilteredTermsEnum { | ||
private final BytesRef afterRef; | ||
|
||
public SearchAfterTermsEnum(TermsEnum tenum, BytesRef termText) { | ||
super(tenum); | ||
afterRef = termText; | ||
setInitialSeekTerm(termText); | ||
} | ||
|
||
@Override | ||
protected AcceptStatus accept(BytesRef term) { | ||
return term.equals(afterRef) ? AcceptStatus.NO : AcceptStatus.YES; | ||
} | ||
} |
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.