Search in sources :

Example 91 with SolrInputDocument

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);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) LongPoint(org.apache.lucene.document.LongPoint) DoublePoint(org.apache.lucene.document.DoublePoint) IntPoint(org.apache.lucene.document.IntPoint) FloatPoint(org.apache.lucene.document.FloatPoint)

Example 92 with SolrInputDocument

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());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) LongPoint(org.apache.lucene.document.LongPoint) DoublePoint(org.apache.lucene.document.DoublePoint) IntPoint(org.apache.lucene.document.IntPoint) FloatPoint(org.apache.lucene.document.FloatPoint)

Example 93 with SolrInputDocument

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);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) SolrQuery(org.apache.solr.client.solrj.SolrQuery) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 94 with SolrInputDocument

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"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument)

Example 95 with SolrInputDocument

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"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument)

Aggregations

SolrInputDocument (org.apache.solr.common.SolrInputDocument)520 Test (org.junit.Test)166 ArrayList (java.util.ArrayList)98 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)76 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)69 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)63 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)55 SolrQuery (org.apache.solr.client.solrj.SolrQuery)54 IOException (java.io.IOException)47 SolrException (org.apache.solr.common.SolrException)47 IndexSchema (org.apache.solr.schema.IndexSchema)41 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)41 HashMap (java.util.HashMap)39 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 List (java.util.List)33 SolrServerException (org.apache.solr.client.solrj.SolrServerException)32 SolrDocument (org.apache.solr.common.SolrDocument)31 NamedList (org.apache.solr.common.util.NamedList)31 Map (java.util.Map)30 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)29