src/test/java/com/o19s/es/ltr/query/LtrQueryBuilderTests.java
@Override
    public void testMustRewrite() throws IOException {
        Script script = new Script(ScriptType.INLINE, "ranklib", simpleModel, Collections.emptyMap());
        List<QueryBuilder> features = new ArrayList<>();
        QueryBuilder testedFtrRewritten = null;
        boolean mustRewrite = false;
        int idx = 0;
        // WARNING - this test assumes MatchQueryBuilder does not rewrite,
        // but that WrappedQueryBuilder does.
        if (randomBoolean()) {
            idx++;
            features.add(new MatchQueryBuilder("test", "foo"));
        }
        if (randomBoolean()) {
            mustRewrite = true;
            features.add(new WrapperQueryBuilder(new MatchQueryBuilder("test", "foo3").toString()));
        }
        if (randomBoolean()) {
            features.add(new MatchQueryBuilder("test", "foo2"));
        }

        LtrQueryBuilder builder = new LtrQueryBuilder(script, features);
        QueryBuilder rewritten = builder.rewrite(createSearchExecutionContext());
        if (!mustRewrite && features.isEmpty()) {
            // if it's empty we rewrite to match all
            assertEquals(rewritten, new MatchAllQueryBuilder());
        } else {
            LtrQueryBuilder rewrite = (LtrQueryBuilder) rewritten;
            if (mustRewrite) {
                assertNotSame(rewrite, builder);
                if (!builder.features().isEmpty()) {
                    assertEquals(builder.features().size(), rewrite.features().size());
                    assertSame(builder.rankerScript(), rewrite.rankerScript());
                    assertEquals(new MatchQueryBuilder("test", "foo3"), rewrite.features().get(idx));
                }
            } else {
                assertSame(rewrite, builder);
            }
        }
    }
/**
     * This test ensures that queries that need to be rewritten have dedicated tests.
     * These queries must override this method accordingly.
     */
This test ensures that queries that need to be rewritten have dedicated tests.
These queries must override this method accordingly.
This test ensures that queries that need to be rewritten have dedicated tests . These queries must override this method accordingly .
@Override
    public void testMustRewrite() throws IOException {
        Script script = new Script(ScriptType.INLINE, "ranklib", simpleModel, Collections.emptyMap());
        List<QueryBuilder> features = new ArrayList<>();
        QueryBuilder testedFtrRewritten = null;
        boolean mustRewrite = false;
        int idx = 0;
        if (randomBoolean()) {
            idx++;
            features.add(new MatchQueryBuilder("test", "foo"));
        }
        if (randomBoolean()) {
            mustRewrite = true;
            features.add(new WrapperQueryBuilder(new MatchQueryBuilder("test", "foo3").toString()));
        }
        if (randomBoolean()) {
            features.add(new MatchQueryBuilder("test", "foo2"));
        }
        LtrQueryBuilder builder = new LtrQueryBuilder(script, features);
        QueryBuilder rewritten = builder.rewrite(createSearchExecutionContext());
        if (!mustRewrite && features.isEmpty()) {
            assertEquals(rewritten, new MatchAllQueryBuilder());
        } else {
            LtrQueryBuilder rewrite = (LtrQueryBuilder) rewritten;
            if (mustRewrite) {
                assertNotSame(rewrite, builder);
                if (!builder.features().isEmpty()) {
                    assertEquals(builder.features().size(), rewrite.features().size());
                    assertSame(builder.rankerScript(), rewrite.rankerScript());
                    assertEquals(new MatchQueryBuilder("test", "foo3"), rewrite.features().get(idx));
                }
            } else {
                assertSame(rewrite, builder);
            }
        }
    }
@ Override public void testMustRewrite ( ) throws IOException { Script script = new Script ( ScriptType . INLINE , "ranklib" , simpleModel , Collections . emptyMap ( ) ) ; List < QueryBuilder > features = new ArrayList < > ( ) ; QueryBuilder testedFtrRewritten = null ; boolean mustRewrite = false ; int idx = 0 ; if ( randomBoolean ( ) ) { idx ++ ; features . add ( new MatchQueryBuilder ( "test" , "foo" ) ) ; } if ( randomBoolean ( ) ) { mustRewrite = true ; features . add ( new WrapperQueryBuilder ( new MatchQueryBuilder ( "test" , "foo3" ) . toString ( ) ) ) ; } if ( randomBoolean ( ) ) { features . add ( new MatchQueryBuilder ( "test" , "foo2" ) ) ; } LtrQueryBuilder builder = new LtrQueryBuilder ( script , features ) ; QueryBuilder rewritten = builder . rewrite ( createSearchExecutionContext ( ) ) ; if ( ! mustRewrite && features . isEmpty ( ) ) { assertEquals ( rewritten , new MatchAllQueryBuilder ( ) ) ; } else { LtrQueryBuilder rewrite = ( LtrQueryBuilder ) rewritten ; if ( mustRewrite ) { assertNotSame ( rewrite , builder ) ; if ( ! builder . features ( ) . isEmpty ( ) ) { assertEquals ( builder . features ( ) . size ( ) , rewrite . features ( ) . size ( ) ) ; assertSame ( builder . rankerScript ( ) , rewrite . rankerScript ( ) ) ; assertEquals ( new MatchQueryBuilder ( "test" , "foo3" ) , rewrite . features ( ) . get ( idx ) ) ; } } else { assertSame ( rewrite , builder ) ; } } }
This test ensures that queries that need to be rewritten have dedicated tests.
This test ensures that queries that need to be rewritten have dedicated tests .
// WARNING - this test assumes MatchQueryBuilder does not rewrite, // but that WrappedQueryBuilder does. // if it's empty we rewrite to match all