-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'opensearch-project:main' into rescore-context
- Loading branch information
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()); | ||
} | ||
} |