-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 1878/1879/1880 fixing index not found for model group/model/tas…
…ks (#1889) (#1895) * adding tests for search of ML constructs * improve test coverage on MLSearchHandler * fix headers on test --------- (cherry picked from commit 41fac82) Signed-off-by: Samuel Herman <[email protected]> Signed-off-by: samuel-oci <[email protected]>
- Loading branch information
1 parent
56a9ab1
commit c278cb1
Showing
12 changed files
with
328 additions
and
31 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
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
99 changes: 99 additions & 0 deletions
99
plugin/src/test/java/org/opensearch/ml/action/handler/MLSearchHandlerTests.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,99 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.action.handler; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
import org.opensearch.index.query.QueryBuilder; | ||
import org.opensearch.index.query.QueryStringQueryBuilder; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class MLSearchHandlerTests extends OpenSearchTestCase { | ||
|
||
public void testRewriteQueryBuilder_accessControlIgnored() { | ||
final String expectedQueryString = "{\n" | ||
+ " \"bool\" : {\n" | ||
+ " \"must\" : [\n" | ||
+ " {\n" | ||
+ " \"query_string\" : {\n" | ||
+ " \"query\" : \"\",\n" | ||
+ " \"fields\" : [ ],\n" | ||
+ " \"type\" : \"best_fields\",\n" | ||
+ " \"default_operator\" : \"or\",\n" | ||
+ " \"max_determinized_states\" : 10000,\n" | ||
+ " \"enable_position_increments\" : true,\n" | ||
+ " \"fuzziness\" : \"AUTO\",\n" | ||
+ " \"fuzzy_prefix_length\" : 0,\n" | ||
+ " \"fuzzy_max_expansions\" : 50,\n" | ||
+ " \"phrase_slop\" : 0,\n" | ||
+ " \"escape\" : false,\n" | ||
+ " \"auto_generate_synonyms_phrase_query\" : true,\n" | ||
+ " \"fuzzy_transpositions\" : true,\n" | ||
+ " \"boost\" : 1.0\n" | ||
+ " }\n" | ||
+ " },\n" | ||
+ " {\n" | ||
+ " \"bool\" : {\n" | ||
+ " \"must_not\" : [\n" | ||
+ " {\n" | ||
+ " \"exists\" : {\n" | ||
+ " \"field\" : \"model_group_id\",\n" | ||
+ " \"boost\" : 1.0\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " ],\n" | ||
+ " \"adjust_pure_negative\" : true,\n" | ||
+ " \"boost\" : 1.0\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " ],\n" | ||
+ " \"adjust_pure_negative\" : true,\n" | ||
+ " \"boost\" : 1.0\n" | ||
+ " }\n" | ||
+ "}"; | ||
final QueryBuilder queryBuilder = MLSearchHandler.rewriteQueryBuilder(new QueryStringQueryBuilder(""), List.of("group1", "group2")); | ||
final String queryString = queryBuilder.toString(); | ||
Assert.assertEquals(expectedQueryString, queryString); | ||
} | ||
|
||
public void testRewriteQueryBuilder_accessControlUsed_withNullQuery() { | ||
final String expectedQueryString = "{\n" | ||
+ " \"bool\" : {\n" | ||
+ " \"should\" : [\n" | ||
+ " {\n" | ||
+ " \"terms\" : {\n" | ||
+ " \"model_group_id\" : [\n" | ||
+ " \"group1\",\n" | ||
+ " \"group2\"\n" | ||
+ " ],\n" | ||
+ " \"boost\" : 1.0\n" | ||
+ " }\n" | ||
+ " },\n" | ||
+ " {\n" | ||
+ " \"bool\" : {\n" | ||
+ " \"must_not\" : [\n" | ||
+ " {\n" | ||
+ " \"exists\" : {\n" | ||
+ " \"field\" : \"model_group_id\",\n" | ||
+ " \"boost\" : 1.0\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " ],\n" | ||
+ " \"adjust_pure_negative\" : true,\n" | ||
+ " \"boost\" : 1.0\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " ],\n" | ||
+ " \"adjust_pure_negative\" : true,\n" | ||
+ " \"boost\" : 1.0\n" | ||
+ " }\n" | ||
+ "}"; | ||
final QueryBuilder queryBuilder = MLSearchHandler.rewriteQueryBuilder(null, List.of("group1", "group2")); | ||
final String queryString = queryBuilder.toString(); | ||
Assert.assertEquals(expectedQueryString, queryString); | ||
} | ||
} |
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.