forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
- Loading branch information
1 parent
ff8a2fd
commit 0f9b49b
Showing
6 changed files
with
113 additions
and
117 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
74 changes: 74 additions & 0 deletions
74
server/src/main/java/org/opensearch/search/approximate/ApproximateIndexOrDocValuesQuery.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,74 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.search.approximate; | ||
|
||
import org.apache.lucene.search.IndexOrDocValuesQuery; | ||
import org.apache.lucene.search.IndexSearcher; | ||
import org.apache.lucene.search.Query; | ||
import org.apache.lucene.search.QueryVisitor; | ||
import org.apache.lucene.search.ScoreMode; | ||
import org.apache.lucene.search.Weight; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A wrapper around {@link IndexOrDocValuesQuery} that can be used to run approximate queries. | ||
* It delegates to either {@link ApproximateableQuery} or {@link IndexOrDocValuesQuery} based on whether the query can be approximated or not. | ||
* @see ApproximateableQuery | ||
*/ | ||
public final class ApproximateIndexOrDocValuesQuery extends ApproximateScoreQuery { | ||
|
||
private final ApproximateableQuery approximateIndexQuery; | ||
private final IndexOrDocValuesQuery indexOrDocValuesQuery; | ||
|
||
public ApproximateIndexOrDocValuesQuery(Query indexQuery, ApproximateableQuery approximateIndexQuery, Query dvQuery) { | ||
super(new IndexOrDocValuesQuery(indexQuery, dvQuery), approximateIndexQuery); | ||
this.approximateIndexQuery = approximateIndexQuery; | ||
this.indexOrDocValuesQuery = new IndexOrDocValuesQuery(indexQuery, dvQuery); | ||
} | ||
|
||
@Override | ||
public String toString(String field) { | ||
return "ApproximateIndexOrDocValuesQuery(indexQuery=" | ||
+ indexOrDocValuesQuery.getIndexQuery().toString(field) | ||
+ ", approximateIndexQuery=" | ||
+ approximateIndexQuery.toString(field) | ||
+ ", dvQuery=" | ||
+ indexOrDocValuesQuery.getRandomAccessQuery().toString(field) | ||
+ ")"; | ||
} | ||
|
||
@Override | ||
public void visit(QueryVisitor visitor) { | ||
indexOrDocValuesQuery.visit(visitor); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (sameClassAs(obj) == false) { | ||
return false; | ||
} | ||
ApproximateIndexOrDocValuesQuery that = (ApproximateIndexOrDocValuesQuery) obj; | ||
return indexOrDocValuesQuery.getIndexQuery().equals(that.indexOrDocValuesQuery.getIndexQuery()) | ||
&& indexOrDocValuesQuery.getRandomAccessQuery().equals(that.indexOrDocValuesQuery.getRandomAccessQuery()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return indexOrDocValuesQuery.hashCode(); | ||
} | ||
|
||
@Override | ||
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { | ||
if (approximateIndexQuery.canApproximate(this.getContext())) { | ||
return approximateIndexQuery.createWeight(searcher, scoreMode, boost); | ||
} | ||
return indexOrDocValuesQuery.createWeight(searcher, scoreMode, boost); | ||
} | ||
} |
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
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