Search in sources :

Example 41 with Search

use of com.yahoo.searchdefinition.Search in project vespa by vespa-engine.

the class SummaryTestCase method testDeriving.

@Test
public void testDeriving() throws IOException, ParseException {
    Search search = SearchBuilder.buildFromFile("src/test/examples/simple.sd");
    SummaryClass summary = new SummaryClass(search, search.getSummary("default"), new BaseDeployLogger());
    assertEquals("default", summary.getName());
    Iterator<SummaryClassField> fields = summary.fieldIterator();
    SummaryClassField field;
    assertEquals(13, summary.getFieldCount());
    field = (SummaryClassField) fields.next();
    assertEquals("exactemento", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("exact", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("title", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("description", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("dyndesc", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("longdesc", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("longstat", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("dynlong", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("dyndesc2", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("measurement", field.getName());
    assertEquals(SummaryClassField.Type.INTEGER, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("rankfeatures", field.getName());
    assertEquals(SummaryClassField.Type.FEATUREDATA, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("summaryfeatures", field.getName());
    assertEquals(SummaryClassField.Type.FEATUREDATA, field.getType());
    field = (SummaryClassField) fields.next();
    assertEquals("documentid", field.getName());
    assertEquals(SummaryClassField.Type.LONGSTRING, field.getType());
}
Also used : BaseDeployLogger(com.yahoo.config.model.application.provider.BaseDeployLogger) Search(com.yahoo.searchdefinition.Search) Test(org.junit.Test)

Example 42 with Search

use of com.yahoo.searchdefinition.Search in project vespa by vespa-engine.

the class TypeConversionTestCase method testExactStringToStringTypeConversion.

/**
 * Tests that exact-string stuff is not spilled over to the default index
 */
@Test
public void testExactStringToStringTypeConversion() {
    Search search = new Search("test", null);
    RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);
    SDDocumentType document = new SDDocumentType("test");
    search.addDocument(document);
    SDField a = new SDField("a", DataType.STRING);
    a.parseIndexingScript("{ index }");
    document.addField(a);
    Processing.process(search, new BaseDeployLogger(), rankProfileRegistry, new QueryProfiles(), true);
    DerivedConfiguration derived = new DerivedConfiguration(search, rankProfileRegistry, new QueryProfileRegistry());
    IndexInfo indexInfo = derived.getIndexInfo();
    assertFalse(indexInfo.hasCommand("default", "compact-to-term"));
}
Also used : RankProfileRegistry(com.yahoo.searchdefinition.RankProfileRegistry) SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) BaseDeployLogger(com.yahoo.config.model.application.provider.BaseDeployLogger) Search(com.yahoo.searchdefinition.Search) QueryProfiles(com.yahoo.vespa.model.container.search.QueryProfiles) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) Test(org.junit.Test)

Example 43 with Search

use of com.yahoo.searchdefinition.Search in project vespa by vespa-engine.

the class ImportedFieldsResolver method validateTargetField.

private SDField validateTargetField(TemporaryImportedField importedField, DocumentReference reference, boolean validate) {
    String targetFieldName = importedField.targetFieldName();
    Search targetSearch = reference.targetSearch();
    if (validate && isImportedField(targetSearch, targetFieldName)) {
        fail(importedField, targetFieldAsString(targetFieldName, reference) + ": Is an imported field. Not supported");
    }
    SDField targetField = targetSearch.getConcreteField(targetFieldName);
    if (targetField == null) {
        fail(importedField, targetFieldAsString(targetFieldName, reference) + ": Not found");
    } else if (!targetField.doesAttributing()) {
        if (validate)
            fail(importedField, targetFieldAsString(targetFieldName, reference) + ": Is not an attribute field. Only attribute fields supported");
    } else if (targetField.doesIndexing()) {
        if (validate)
            fail(importedField, targetFieldAsString(targetFieldName, reference) + ": Is an index field. Not supported");
    }
    return targetField;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Search(com.yahoo.searchdefinition.Search)

Example 44 with Search

use of com.yahoo.searchdefinition.Search in project vespa by vespa-engine.

the class NoPrefixForIndexes method validate.

@Override
public void validate(VespaModel model, DeployState deployState) {
    for (AbstractSearchCluster cluster : model.getSearchClusters()) {
        if (cluster instanceof IndexedSearchCluster) {
            IndexedSearchCluster sc = (IndexedSearchCluster) cluster;
            for (DocumentDatabase docDb : sc.getDocumentDbs()) {
                DerivedConfiguration sdConfig = docDb.getDerivedConfiguration();
                Search search = sdConfig.getSearch();
                for (SDField field : search.allConcreteFields()) {
                    if (field.doesIndexing()) {
                        // if (!field.getIndexTo().isEmpty() && !field.getIndexTo().contains(field.getName())) continue;
                        if (field.getMatching().getAlgorithm().equals(Matching.Algorithm.PREFIX)) {
                            failField(search, field);
                        }
                        for (Map.Entry<String, Index> e : field.getIndices().entrySet()) {
                            if (e.getValue().isPrefix()) {
                                failField(search, field);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IndexedSearchCluster(com.yahoo.vespa.model.search.IndexedSearchCluster) DerivedConfiguration(com.yahoo.searchdefinition.derived.DerivedConfiguration) SDField(com.yahoo.searchdefinition.document.SDField) AbstractSearchCluster(com.yahoo.vespa.model.search.AbstractSearchCluster) Search(com.yahoo.searchdefinition.Search) Index(com.yahoo.searchdefinition.Index) DocumentDatabase(com.yahoo.vespa.model.search.DocumentDatabase) Map(java.util.Map)

Example 45 with Search

use of com.yahoo.searchdefinition.Search 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

Search (com.yahoo.searchdefinition.Search)62 Test (org.junit.Test)47 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)21 SDField (com.yahoo.searchdefinition.document.SDField)15 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)13 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)12 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)8 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)8 SearchBuilder (com.yahoo.searchdefinition.SearchBuilder)6 File (java.io.File)5 SummaryField (com.yahoo.vespa.documentmodel.SummaryField)4 RankProfile (com.yahoo.searchdefinition.RankProfile)3 Field (com.yahoo.document.Field)2 StructDataType (com.yahoo.document.StructDataType)2 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)2 DocumentReference (com.yahoo.searchdefinition.DocumentReference)2 Index (com.yahoo.searchdefinition.Index)2 UnprocessingSearchBuilder (com.yahoo.searchdefinition.UnprocessingSearchBuilder)2 Attribute (com.yahoo.searchdefinition.document.Attribute)2 ImportedField (com.yahoo.searchdefinition.document.ImportedField)2