forked from opensearch-project/neural-search
-
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.
Removed map of subquery to subquery index in favor of storing index a…
…s part of DISI wrapper to improve hybrid query latencies by 20% (opensearch-project#711) * Removed map of subquery to subquery index in favor of storing index as part of disi wrapper to improve hybrid query latencies by 20% Signed-off-by: Martin Gaievski <[email protected]>
- Loading branch information
1 parent
b277b07
commit a3bdde5
Showing
4 changed files
with
72 additions
and
54 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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/org/opensearch/neuralsearch/search/HybridDisiWrapper.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,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.neuralsearch.search; | ||
|
||
import lombok.Getter; | ||
import org.apache.lucene.search.DisiWrapper; | ||
import org.apache.lucene.search.Scorer; | ||
|
||
/** | ||
* Wrapper for DisiWrapper, saves state of sub-queries for performance reasons | ||
*/ | ||
@Getter | ||
public class HybridDisiWrapper extends DisiWrapper { | ||
// index of disi wrapper sub-query object when its part of the hybrid query | ||
private final int subQueryIndex; | ||
|
||
public HybridDisiWrapper(Scorer scorer, int subQueryIndex) { | ||
super(scorer); | ||
this.subQueryIndex = subQueryIndex; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/org/opensearch/neuralsearch/search/HybridDisiWrapperTests.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,24 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.neuralsearch.search; | ||
|
||
import org.apache.lucene.search.DocIdSetIterator; | ||
import org.apache.lucene.search.Scorer; | ||
import org.opensearch.neuralsearch.query.OpenSearchQueryTestCase; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class HybridDisiWrapperTests extends OpenSearchQueryTestCase { | ||
|
||
public void testSubQueryIndex_whenCreateNewInstanceAndSetIndex_thenSuccessful() { | ||
Scorer scorer = mock(Scorer.class); | ||
DocIdSetIterator docIdSetIterator = mock(DocIdSetIterator.class); | ||
when(scorer.iterator()).thenReturn(docIdSetIterator); | ||
int subQueryIndex = 2; | ||
HybridDisiWrapper hybridDisiWrapper = new HybridDisiWrapper(scorer, subQueryIndex); | ||
assertEquals(2, hybridDisiWrapper.getSubQueryIndex()); | ||
} | ||
} |