summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/searchdefinition/derived/NearestNeighborTestCase.java
blob: ea69d36b03e577c701af28b8a3a2119aef5dd584 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.derived;

import com.yahoo.component.ComponentId;
import com.yahoo.search.Query;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
import com.yahoo.search.query.profile.config.QueryProfileConfigurer;
import com.yahoo.searchdefinition.parser.ParseException;
import com.yahoo.vespa.model.container.search.QueryProfiles;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class NearestNeighborTestCase extends AbstractExportingTestCase {

    @Test
    public void testNearestNeighbor() throws IOException, ParseException {
        try {
            ComponentId.resetGlobalCountersForTests();
            DerivedConfiguration c = assertCorrectDeriving("nearestneighbor");

            CompiledQueryProfileRegistry queryProfiles =
                    QueryProfileConfigurer.createFromConfig(new QueryProfiles(c.getQueryProfiles(), (level, message) -> {}).getConfig()).compile();
            Query q = new Query("?ranking.features.query(q_vec)=[1,2,3,4,5,6]", // length is 6, not 5
                                queryProfiles.getComponent("default"));
            fail("This should fail when q_vec is parsed as a tensor");
        } catch (IllegalInputException e) {
            // success
            assertEquals("Invalid request parameter", e.getMessage());
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

}