Skip to content

Commit

Permalink
Adding tests and updating changelog.md
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun committed Jan 17, 2024
1 parent debafba commit a3ef808
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Bug Fixes
- Fixing multiple issues reported in #497 ([#524](https://github.com/opensearch-project/neural-search/pull/524))
- Fix Flaky test reported in #433 ([#533](https://github.com/opensearch-project/neural-search/pull/533))
- Enable support for default model id on HybridQueryBuilder ([#541](https://github.com/opensearch-project/neural-search/pull/541))
### Infrastructure
- BWC tests for Neural Search ([#515](https://github.com/opensearch-project/neural-search/pull/515))
- Github action to run integ tests in secure opensearch cluster ([#535](https://github.com/opensearch-project/neural-search/pull/535))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ private Collection<Query> toQueries(Collection<QueryBuilder> queryBuilders, Quer

/**
* visit method to parse the HybridQueryBuilder by a visitor
* @return
*/
@Override
public void visit(QueryBuilderVisitor visitor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.function.Supplier;

import org.apache.lucene.search.MatchNoDocsQuery;
Expand Down Expand Up @@ -52,6 +53,7 @@
import org.opensearch.knn.index.query.KNNQueryBuilder;
import org.opensearch.neuralsearch.util.NeuralSearchClusterTestUtils;
import org.opensearch.neuralsearch.util.NeuralSearchClusterUtil;
import static org.opensearch.neuralsearch.TestUtils.createTestVisitor;

import com.carrotsearch.randomizedtesting.RandomizedTest;

Expand Down Expand Up @@ -708,6 +710,13 @@ public void testBoost_whenDefaultBoostSet_thenBuildSuccessfully() {
assertNotNull(hybridQueryBuilder);
}

public void testVisit() {
HybridQueryBuilder hybridQueryBuilder = new HybridQueryBuilder().add(new NeuralQueryBuilder()).add(new NeuralSparseQueryBuilder());
List<QueryBuilder> visitedQueries = new ArrayList<>();
hybridQueryBuilder.visit(createTestVisitor(visitedQueries));
assertEquals(3, visitedQueries.size());
}

private Map<String, Object> getInnerMap(Object innerObject, String queryName, String fieldName) {
if (!(innerObject instanceof Map)) {
fail("field name does not map to nested object");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.index.query.QueryBuilderVisitor;
import static org.opensearch.test.OpenSearchTestCase.randomFloat;

import java.util.ArrayList;
Expand Down Expand Up @@ -310,4 +312,8 @@ public static String getModelId(Map<String, Object> pipeline, String processor)

return (String) textEmbeddingProcessor.get("model_id");
}

public static QueryBuilderVisitor createTestVisitor(List<QueryBuilder> visitedQueries) {
return QueryBuilderVisitor.NO_OP_VISITOR;
}
}

0 comments on commit a3ef808

Please sign in to comment.