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);
}
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
}
}
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"));
}
}
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 + "}]}}");
}
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_"));
}
}
}
Aggregations