Search in sources :

Example 11 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class SolrIndexConfigTest method testSortingMPSolrIndexConfigCreation.

public void testSortingMPSolrIndexConfigCreation() throws Exception {
    final String expectedFieldName = "timestamp_i_dvo";
    final SortField.Type expectedFieldType = SortField.Type.INT;
    final boolean expectedFieldSortDescending = true;
    SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileNameSortingMergePolicyFactory, null);
    SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
    assertNotNull(solrIndexConfig);
    IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);
    h.getCore().setLatestSchema(indexSchema);
    IndexWriterConfig iwc = solrIndexConfig.toIndexWriterConfig(h.getCore());
    final MergePolicy mergePolicy = iwc.getMergePolicy();
    assertNotNull("null mergePolicy", mergePolicy);
    assertTrue("mergePolicy (" + mergePolicy + ") is not a SortingMergePolicy", mergePolicy instanceof SortingMergePolicy);
    final SortingMergePolicy sortingMergePolicy = (SortingMergePolicy) mergePolicy;
    final Sort expected = new Sort(new SortField(expectedFieldName, expectedFieldType, expectedFieldSortDescending));
    final Sort actual = sortingMergePolicy.getSort();
    assertEquals("SortingMergePolicy.getSort", expected, actual);
}
Also used : SolrConfig(org.apache.solr.core.SolrConfig) SortingMergePolicy(org.apache.solr.index.SortingMergePolicy) MergePolicy(org.apache.lucene.index.MergePolicy) TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) SortingMergePolicy(org.apache.solr.index.SortingMergePolicy) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) IndexSchema(org.apache.solr.schema.IndexSchema) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 12 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class CursorMarkTest method testNextCursorMark.

public void testNextCursorMark() throws IOException {
    final Collection<String> allFieldNames = getAllFieldNames();
    final SolrQueryRequest req = req();
    final IndexSchema schema = req.getSchema();
    final String randomSortString = CursorPagingTest.buildRandomSort(allFieldNames);
    final SortSpec ss = SortSpecParsing.parseSortSpec(randomSortString, req);
    final CursorMark previous = new CursorMark(schema, ss);
    previous.parseSerializedTotem(CURSOR_MARK_START);
    List<Object> nextValues = Arrays.<Object>asList(buildRandomSortObjects(ss));
    final CursorMark next = previous.createNext(nextValues);
    assertEquals("next values not correct", nextValues, next.getSortValues());
    assertEquals("next SortSpec not correct", ss, next.getSortSpec());
    try {
        // append to our random sort string so we know it has wrong num clauses
        final SortSpec otherSort = SortSpecParsing.parseSortSpec(randomSortString + ",id asc", req);
        CursorMark trash = previous.createNext(Arrays.<Object>asList(buildRandomSortObjects(otherSort)));
        fail("didn't fail on next with incorrect num of sortvalues");
    } catch (AssertionError e) {
    // NOOP: we're happy
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 13 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class CursorMarkTest method testGarbageParsing.

public void testGarbageParsing() throws IOException {
    final SolrQueryRequest req = req();
    final IndexSchema schema = req.getSchema();
    final SortSpec ss = SortSpecParsing.parseSortSpec("str asc, float desc, id asc", req);
    final CursorMark totem = new CursorMark(schema, ss);
    // totem string that isn't even valid base64
    try {
        totem.parseSerializedTotem("all the documents please");
        fail("didn't fail on invalid base64 totem");
    } catch (SolrException e) {
        assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
        assertTrue(e.getMessage().contains("Unable to parse 'cursorMark'"));
    }
    // empty totem string
    try {
        totem.parseSerializedTotem("");
        fail("didn't fail on empty totem");
    } catch (SolrException e) {
        assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
        assertTrue(e.getMessage().contains("Unable to parse 'cursorMark'"));
    }
    // whitespace-only totem string
    try {
        totem.parseSerializedTotem("       ");
        fail("didn't fail on whitespace-only totem");
    } catch (SolrException e) {
        assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
        assertTrue(e.getMessage().contains("Unable to parse 'cursorMark'"));
    }
    // totem string from sort with diff num clauses
    try {
        final SortSpec otherSort = SortSpecParsing.parseSortSpec("double desc, id asc", req);
        final CursorMark otherTotem = new CursorMark(schema, otherSort);
        otherTotem.setSortValues(Arrays.<Object>asList(buildRandomSortObjects(otherSort)));
        totem.parseSerializedTotem(otherTotem.getSerializedTotem());
        fail("didn't fail on totem from incorrect sort (num clauses)");
    } catch (SolrException e) {
        assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
        assertTrue(e.getMessage().contains("wrong size"));
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) IndexSchema(org.apache.solr.schema.IndexSchema) SolrException(org.apache.solr.common.SolrException)

Example 14 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class TestAddFieldRealTimeGet method test.

public void test() throws Exception {
    clearIndex();
    assertU(commit());
    String newFieldName = "newfield";
    String newFieldType = "string";
    String newFieldValue = "xyz";
    assertFailedU("Should fail due to unknown field '" + newFieldName + "'", adoc("id", "1", newFieldName, newFieldValue));
    IndexSchema schema = h.getCore().getLatestSchema();
    SchemaField newField = schema.newField(newFieldName, newFieldType, Collections.<String, Object>emptyMap());
    IndexSchema newSchema = schema.addField(newField);
    h.getCore().setLatestSchema(newSchema);
    String newFieldKeyValue = "'" + newFieldName + "':'" + newFieldValue + "'";
    assertU(adoc("id", "1", newFieldName, newFieldValue));
    assertJQ(req("q", "id:1"), "/response/numFound==0");
    assertJQ(req("qt", "/get", "id", "1", "fl", "id," + newFieldName), "=={'doc':{'id':'1'," + newFieldKeyValue + "}}");
    assertJQ(req("qt", "/get", "ids", "1", "fl", "id," + newFieldName), "=={'response':{'numFound':1,'start':0,'docs':[{'id':'1'," + newFieldKeyValue + "}]}}");
    assertU(commit());
    assertJQ(req("q", "id:1"), "/response/numFound==1");
    assertJQ(req("qt", "/get", "id", "1", "fl", "id," + newFieldName), "=={'doc':{'id':'1'," + newFieldKeyValue + "}}");
    assertJQ(req("qt", "/get", "ids", "1", "fl", "id," + newFieldName), "=={'response':{'numFound':1,'start':0,'docs':[{'id':'1'," + newFieldKeyValue + "}]}}");
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) IndexSchema(org.apache.solr.schema.IndexSchema)

Example 15 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class CursorMarkTest method testInvalidUsage.

public void testInvalidUsage() {
    final SolrQueryRequest req = req();
    final IndexSchema schema = req.getSchema();
    try {
        final SortSpec ss = SortSpecParsing.parseSortSpec("str desc, score desc", req);
        final CursorMark totem = new CursorMark(schema, ss);
        fail("no failure from sort that doesn't include uniqueKey field");
    } catch (SolrException e) {
        assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
        assertTrue(0 < e.getMessage().indexOf("uniqueKey"));
    }
    for (final String dir : Arrays.asList("asc", "desc")) {
        try {
            final SortSpec ss = SortSpecParsing.parseSortSpec("score " + dir, req);
            final CursorMark totem = new CursorMark(schema, ss);
            fail("no failure from score only sort: " + dir);
        } catch (SolrException e) {
            assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
            assertTrue(0 < e.getMessage().indexOf("uniqueKey"));
        }
        try {
            final SortSpec ss = SortSpecParsing.parseSortSpec("_docid_ " + dir + ", id desc", req);
            final CursorMark totem = new CursorMark(schema, ss);
            fail("no failure from sort that includes _docid_: " + dir);
        } catch (SolrException e) {
            assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
            assertTrue(0 < e.getMessage().indexOf("_docid_"));
        }
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) IndexSchema(org.apache.solr.schema.IndexSchema) SolrException(org.apache.solr.common.SolrException)

Aggregations

IndexSchema (org.apache.solr.schema.IndexSchema)109 SolrInputDocument (org.apache.solr.common.SolrInputDocument)41 SchemaField (org.apache.solr.schema.SchemaField)31 HashMap (java.util.HashMap)15 SolrException (org.apache.solr.common.SolrException)13 FieldType (org.apache.solr.schema.FieldType)13 Date (java.util.Date)12 LinkedHashMap (java.util.LinkedHashMap)12 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)12 IOException (java.io.IOException)11 NamedList (org.apache.solr.common.util.NamedList)11 ArrayList (java.util.ArrayList)10 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)10 DateTime (org.joda.time.DateTime)10 Document (org.apache.lucene.document.Document)8 SolrParams (org.apache.solr.common.params.SolrParams)8 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)8 Test (org.junit.Test)7 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)6 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)6