use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class TestPointFields method doTestPointFieldSortError.
/**
* Checks that the specified field can not be sorted on, even if there are documents
* with (all) the specified values in the index.
*
* @param field the field name to try and sort on
* @param errSubStr substring to look for in the error msg
* @param values one or more values to put into the doc(s) in the index - may be more then one for multivalued fields
*/
private void doTestPointFieldSortError(String field, String errSubStr, String... values) throws Exception {
final int numDocs = atLeast(random(), 10);
for (int i = 0; i < numDocs; i++) {
SolrInputDocument doc = sdoc("id", String.valueOf(i));
for (String v : values) {
doc.addField(field, v);
}
assertU(adoc(doc));
}
assertQEx("Should not be able to sort on field: " + field, errSubStr, req("q", "*:*", "fl", "id", "sort", field + " desc"), SolrException.ErrorCode.BAD_REQUEST);
clearIndex();
assertU(commit());
// empty index should (also) give same error
assertQEx("Should not be able to sort on field: " + field, errSubStr, req("q", "*:*", "fl", "id", "sort", field + " desc"), SolrException.ErrorCode.BAD_REQUEST);
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class TestPointFields method doTestPointFieldSort.
/**
* For each value, creates a doc with that value in the specified field and then asserts that
* asc/desc sorts on that field succeeds and that the docs are in the (relatively) expected order
*
* @param field name of field to sort on
* @param values list of values in ascending order
*/
private void doTestPointFieldSort(String field, String... values) throws Exception {
assert values != null && 2 <= values.length;
// TODO: need to add sort missing coverage...
//
// idea: accept "null" as possible value for sort missing tests ?
//
// need to account for possibility that multiple nulls will be in non deterministic order
// always using secondary sort on id seems prudent ... handles any "dups" in values[]
final List<SolrInputDocument> docs = new ArrayList<>(values.length);
final String[] ascXpathChecks = new String[values.length + 1];
final String[] descXpathChecks = new String[values.length + 1];
ascXpathChecks[values.length] = "//*[@numFound='" + values.length + "']";
descXpathChecks[values.length] = "//*[@numFound='" + values.length + "']";
for (int i = values.length - 1; i >= 0; i--) {
docs.add(sdoc("id", String.valueOf(i), field, String.valueOf(values[i])));
// reminder: xpath array indexes start at 1
ascXpathChecks[i] = "//result/doc[" + (1 + i) + "]/str[@name='id'][.='" + i + "']";
descXpathChecks[i] = "//result/doc[" + (values.length - i) + "]/str[@name='id'][.='" + i + "']";
}
// ensure doc add order doesn't affect results
Collections.shuffle(docs, random());
for (SolrInputDocument doc : docs) {
assertU(adoc(doc));
}
assertU(commit());
assertQ(req("q", "*:*", "fl", "id", "sort", field + " asc"), ascXpathChecks);
assertQ(req("q", "*:*", "fl", "id", "sort", field + " desc"), descXpathChecks);
clearIndex();
assertU(commit());
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class TestSolrCloudWithHadoopAuthPlugin method testCollectionCreateSearchDelete.
protected void testCollectionCreateSearchDelete() throws Exception {
CloudSolrClient solrClient = cluster.getSolrClient();
String collectionName = "testkerberoscollection";
// create collection
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, "conf1", NUM_SHARDS, REPLICATION_FACTOR);
create.process(solrClient);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
solrClient.add(collectionName, doc);
solrClient.commit(collectionName);
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
QueryResponse rsp = solrClient.query(collectionName, query);
assertEquals(1, rsp.getResults().getNumFound());
CollectionAdminRequest.Delete deleteReq = CollectionAdminRequest.deleteCollection(collectionName);
deleteReq.process(solrClient);
AbstractDistribZkTestBase.waitForCollectionToDisappear(collectionName, solrClient.getZkStateReader(), true, true, 330);
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class FieldMutatingUpdateProcessorTest method doSimpleDelimTest.
private void doSimpleDelimTest(final String chain, final String delim) throws Exception {
SolrInputDocument d = null;
d = processAdd(chain, doc(f("id", "1111"), f("foo_t", "string1", "string2"), f("foo_d", new Integer(42)), field("foo_s", "string3", "string4")));
assertNotNull(d);
assertEquals(Arrays.asList("string1", "string2"), d.getFieldValues("foo_t"));
assertEquals("string3" + delim + "string4", d.getFieldValue("foo_s"));
// slightly more interesting
assertEquals("processor borked non string value", new Integer(42), d.getFieldValue("foo_d"));
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class FieldMutatingUpdateProcessorTest method testRegexReplace.
public void testRegexReplace() throws Exception {
SolrInputDocument d = null;
d = processAdd("regex-replace", doc(f("id", "doc1"), f("content", "This is a text\t with a lot\n of whitespace"), f("title", "This\ttitle has a lot of spaces")));
assertNotNull(d);
assertEquals("ThisXisXaXtextXwithXaXlotXofXwhitespace", d.getFieldValue("content"));
assertEquals("ThisXtitleXhasXaXlotXofXspaces", d.getFieldValue("title"));
// literalReplacement = true
d = processAdd("regex-replace-literal-true", doc(f("id", "doc2"), f("content", "Let's try this one"), f("title", "Let's try try this one")));
assertNotNull(d);
assertEquals("Let's <$1> this one", d.getFieldValue("content"));
assertEquals("Let's <$1> <$1> this one", d.getFieldValue("title"));
// literalReplacement is not specified, defaults to true
d = processAdd("regex-replace-literal-default-true", doc(f("id", "doc3"), f("content", "Let's try this one"), f("title", "Let's try try this one")));
assertNotNull(d);
assertEquals("Let's <$1> this one", d.getFieldValue("content"));
assertEquals("Let's <$1> <$1> this one", d.getFieldValue("title"));
// if user passes literalReplacement as a string param instead of boolean
d = processAdd("regex-replace-literal-str-true", doc(f("id", "doc4"), f("content", "Let's try this one"), f("title", "Let's try try this one")));
assertNotNull(d);
assertEquals("Let's <$1> this one", d.getFieldValue("content"));
assertEquals("Let's <$1> <$1> this one", d.getFieldValue("title"));
// This is with literalReplacement = false
d = processAdd("regex-replace-literal-false", doc(f("id", "doc5"), f("content", "Let's try this one"), f("title", "Let's try try this one")));
assertNotNull(d);
assertEquals("Let's <try> this one", d.getFieldValue("content"));
assertEquals("Let's <try> <try> this one", d.getFieldValue("title"));
}
Aggregations