Search in sources :

Example 1 with SearchDefinition

use of com.yahoo.vespa.model.search.SearchDefinition in project vespa by vespa-engine.

the class ClusterTest method newSearchDefinition.

private static SearchDefinition newSearchDefinition(String name) throws ParseException {
    SearchBuilder builder = new SearchBuilder();
    builder.importString("search " + name + " { document " + name + " { } }");
    builder.build();
    return new SearchDefinition(name, builder.getSearch(name));
}
Also used : SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) SearchDefinition(com.yahoo.vespa.model.search.SearchDefinition)

Example 2 with SearchDefinition

use of com.yahoo.vespa.model.search.SearchDefinition in project vespa by vespa-engine.

the class RankingConstantsValidator method validate.

@Override
public void validate(VespaModel model, DeployState deployState) {
    ApplicationPackage applicationPackage = deployState.getApplicationPackage();
    ExceptionMessageCollector exceptionMessageCollector = new ExceptionMessageCollector("Invalid constant tensor file(s):");
    for (SearchDefinition sd : deployState.getSearchDefinitions()) {
        for (RankingConstant rc : sd.getSearch().getRankingConstants().values()) {
            try {
                validateRankingConstant(rc, applicationPackage);
            } catch (InvalidConstantTensor | FileNotFoundException ex) {
                exceptionMessageCollector.add(ex, rc.getName(), rc.getFileName());
            }
        }
    }
    if (exceptionMessageCollector.exceptionsOccurred) {
        throw new TensorValidationFailed(exceptionMessageCollector.combinedMessage);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) FilesApplicationPackage(com.yahoo.config.model.application.provider.FilesApplicationPackage) SearchDefinition(com.yahoo.vespa.model.search.SearchDefinition) RankingConstant(com.yahoo.searchdefinition.RankingConstant) InvalidConstantTensor(com.yahoo.vespa.model.application.validation.ConstantTensorJsonValidator.InvalidConstantTensor)

Example 3 with SearchDefinition

use of com.yahoo.vespa.model.search.SearchDefinition in project vespa by vespa-engine.

the class ApplicationDeployTest method testVespaModel.

@Test
public void testVespaModel() throws SAXException, IOException {
    FilesApplicationPackage app = createAppPkg(TESTDIR + "app1");
    assertThat(app.getApplicationName(), is("app1"));
    VespaModel model = new VespaModel(app);
    List<SearchDefinition> searchDefinitions = getSearchDefinitions(app);
    assertEquals(searchDefinitions.size(), 5);
    for (SearchDefinition searchDefinition : searchDefinitions) {
        Search s = searchDefinition.getSearch();
        switch(s.getName()) {
            case "music":
            case "laptop":
            case "pc":
            case "sock":
                break;
            case "product":
                assertTrue(s instanceof UnproperSearch);
                assertEquals(s.getDocument().getField("title").getDataType(), DataType.STRING);
                break;
            default:
                fail();
        }
    }
    File[] truth = new File[] { new File(TESTSDDIR + "laptop.sd"), new File(TESTSDDIR + "music.sd"), new File(TESTSDDIR + "pc.sd"), new File(TESTSDDIR + "product.sd"), new File(TESTSDDIR + "sock.sd") };
    Arrays.sort(truth);
    List<File> appSdFiles = app.getSearchDefinitionFiles();
    Collections.sort(appSdFiles);
    assertEquals(appSdFiles, Arrays.asList(truth));
    List<FilesApplicationPackage.Component> components = app.getComponents();
    assertEquals(1, components.size());
    Map<String, Bundle.DefEntry> defEntriesByName = defEntries2map(components.get(0).getDefEntries());
    assertEquals(5, defEntriesByName.size());
    Bundle.DefEntry def1 = defEntriesByName.get("test-namespace");
    assertNotNull(def1);
    assertEquals("namespace=config\nintVal int default=0", def1.contents);
    Bundle.DefEntry def2 = defEntriesByName.get("namespace-in-filename");
    assertNotNull(def2);
    assertEquals("namespace=a.b\n\ndoubleVal double default=0.0", def2.contents);
    // Check that getFilename works
    ArrayList<String> sdFileNames = new ArrayList<>();
    for (SearchDefinition sd : searchDefinitions) {
        sdFileNames.add(sd.getFilename());
    }
    Collections.sort(sdFileNames);
    assertThat(sdFileNames.get(0), is("laptop.sd"));
    assertThat(sdFileNames.get(1), is("music.sd"));
    assertThat(sdFileNames.get(2), is("pc.sd"));
    assertThat(sdFileNames.get(3), is("product.sd"));
    assertThat(sdFileNames.get(4), is("sock.sd"));
}
Also used : ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SearchDefinition(com.yahoo.vespa.model.search.SearchDefinition) UnproperSearch(com.yahoo.searchdefinition.UnproperSearch) VespaModel(com.yahoo.vespa.model.VespaModel) Search(com.yahoo.searchdefinition.Search) UnproperSearch(com.yahoo.searchdefinition.UnproperSearch) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Aggregations

SearchDefinition (com.yahoo.vespa.model.search.SearchDefinition)3 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)1 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)1 RankingConstant (com.yahoo.searchdefinition.RankingConstant)1 Search (com.yahoo.searchdefinition.Search)1 SearchBuilder (com.yahoo.searchdefinition.SearchBuilder)1 UnproperSearch (com.yahoo.searchdefinition.UnproperSearch)1 VespaModel (com.yahoo.vespa.model.VespaModel)1 InvalidConstantTensor (com.yahoo.vespa.model.application.validation.ConstantTensorJsonValidator.InvalidConstantTensor)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 JarFile (java.util.jar.JarFile)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1