Search in sources :

Example 1 with Field

use of org.apache.solr.client.solrj.request.schema.SchemaRequest.Field in project lucene-solr by apache.

the class TestInPlaceUpdatesDistrib method checkExpectedSchemaField.

/**
   * Use the schema API to verify that the specified expected Field exists with those exact attributes. 
   */
public void checkExpectedSchemaField(Map<String, Object> expected) throws Exception {
    String fieldName = (String) expected.get("name");
    assertNotNull("expected contains no name: " + expected, fieldName);
    FieldResponse rsp = new Field(fieldName).process(this.cloudClient);
    assertNotNull("Field Null Response: " + fieldName, rsp);
    assertEquals("Field Status: " + fieldName + " => " + rsp.toString(), 0, rsp.getStatus());
    assertEquals("Field: " + fieldName, expected, rsp.getField());
}
Also used : Field(org.apache.solr.client.solrj.request.schema.SchemaRequest.Field) FieldResponse(org.apache.solr.client.solrj.response.schema.SchemaResponse.FieldResponse)

Example 2 with Field

use of org.apache.solr.client.solrj.request.schema.SchemaRequest.Field in project lucene-solr by apache.

the class TestStressCloudBlindAtomicUpdates method checkExpectedSchemaField.

/**
   * Use the schema API to verify that the specified expected Field exists with those exact attributes. 
   * @see #CLOUD_CLIENT
   */
public static void checkExpectedSchemaField(Map<String, Object> expected) throws Exception {
    String fieldName = (String) expected.get("name");
    assertNotNull("expected contains no name: " + expected, fieldName);
    FieldResponse rsp = new Field(fieldName).process(CLOUD_CLIENT);
    assertNotNull("Field Null Response: " + fieldName, rsp);
    assertEquals("Field Status: " + fieldName + " => " + rsp.toString(), 0, rsp.getStatus());
    assertEquals("Field: " + fieldName, expected, rsp.getField());
}
Also used : SolrInputField(org.apache.solr.common.SolrInputField) Field(org.apache.solr.client.solrj.request.schema.SchemaRequest.Field) FieldResponse(org.apache.solr.client.solrj.response.schema.SchemaResponse.FieldResponse)

Example 3 with Field

use of org.apache.solr.client.solrj.request.schema.SchemaRequest.Field in project lucene-solr by apache.

the class TestSegmentSorting method testAtomicUpdateOfSegmentSortField.

/** 
   * Verify that atomic updates against our (DVO) segment sort field doesn't cause errors.
   * In this situation, the updates should *NOT* be done inplace, because that would
   * break the index sorting
   */
public void testAtomicUpdateOfSegmentSortField() throws Exception {
    final CloudSolrClient cloudSolrClient = cluster.getSolrClient();
    final String updateField = SegmentTerminateEarlyTestState.TIMESTAMP_FIELD;
    // sanity check that updateField is in fact a DocValues only field, meaning it
    // would normally be eligable for inplace updates -- if it weren't also used for merge sorting
    final Map<String, Object> schemaOpts = new Field(updateField, params("includeDynamic", "true", "showDefaults", "true")).process(cloudSolrClient).getField();
    assertEquals(true, schemaOpts.get("docValues"));
    assertEquals(false, schemaOpts.get("indexed"));
    assertEquals(false, schemaOpts.get("stored"));
    // add some documents
    final int numDocs = atLeast(1000);
    for (int id = 1; id <= numDocs; id++) {
        cloudSolrClient.add(sdoc("id", id, updateField, random().nextInt(60)));
    }
    cloudSolrClient.commit();
    // (at this point we're just sanity checking no serious failures)
    for (int iter = 0; iter < 20; iter++) {
        final int iterSize = atLeast(20);
        for (int i = 0; i < iterSize; i++) {
            // replace
            cloudSolrClient.add(sdoc("id", TestUtil.nextInt(random(), 1, numDocs), updateField, random().nextInt(60)));
            // atomic update
            cloudSolrClient.add(sdoc("id", TestUtil.nextInt(random(), 1, numDocs), updateField, map("set", random().nextInt(60))));
        }
        cloudSolrClient.commit();
    }
    // pick a random doc, and verify that doing an atomic update causes the docid to change
    // ie: not an inplace update
    final int id = TestUtil.nextInt(random(), 1, numDocs);
    final int oldDocId = (Integer) cloudSolrClient.getById("" + id, params("fl", "[docid]")).get("[docid]");
    cloudSolrClient.add(sdoc("id", id, updateField, map("inc", "666")));
    cloudSolrClient.commit();
    // loop incase we're waiting for a newSearcher to be opened
    int newDocId = -1;
    int attempts = 10;
    while ((newDocId < 0) && (0 < attempts--)) {
        SolrDocumentList docs = cloudSolrClient.query(params("q", "id:" + id, "fl", "[docid]", "fq", updateField + "[666 TO *]")).getResults();
        if (0 < docs.size()) {
            newDocId = (Integer) docs.get(0).get("[docid]");
        } else {
            Thread.sleep(50);
        }
    }
    assertTrue(oldDocId != newDocId);
}
Also used : Field(org.apache.solr.client.solrj.request.schema.SchemaRequest.Field) SolrDocumentList(org.apache.solr.common.SolrDocumentList) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 4 with Field

use of org.apache.solr.client.solrj.request.schema.SchemaRequest.Field in project lucene-solr by apache.

the class TestCloudPseudoReturnFields method testMultiValued.

public void testMultiValued() throws Exception {
    // score as psuedo field - precondition checks
    for (String name : new String[] { "score", "val_ss" }) {
        try {
            FieldResponse frsp = new Field(name, params("includeDynamic", "true", "showDefaults", "true")).process(CLOUD_CLIENT);
            assertNotNull("Test depends on a (dynamic) field matching '" + name + "', Null response", frsp);
            assertEquals("Test depends on a (dynamic) field matching '" + name + "', bad status: " + frsp.toString(), 0, frsp.getStatus());
            assertNotNull("Test depends on a (dynamic) field matching '" + name + "', schema was changed out from under us? ... " + frsp.toString(), frsp.getField());
            assertEquals("Test depends on a multivalued dynamic field matching '" + name + "', schema was changed out from under us? ... " + frsp.toString(), Boolean.TRUE, frsp.getField().get("multiValued"));
        } catch (SolrServerException e) {
            assertEquals("Couldn't fetch field for '" + name + "' ... schema changed out from under us?", null, e);
        }
    }
    SolrDocument doc = null;
    // score as psuedo field
    doc = assertSearchOneDoc(params("q", "*:*", "fq", "id:42", "fl", "id,score,val_ss,val2_ss"));
    assertEquals("42", doc.getFieldValue("id"));
    assertEquals(1.0F, doc.getFieldValue("score"));
    // no value for val2_ss or val_ss ... yet...
    assertEquals("" + doc, 2, doc.size());
    // TODO: update this test & TestPseudoReturnFields to index docs using a (multivalued) "val_ss" instead of "ssto"
    //
    // that way we can first sanity check a single value in a multivalued field is returned correctly
    // as a "List" of one element, *AND* then we could be testing that a (single valued) psuedo-field correctly
    // overrides that actual (real) value in a multivalued field (ie: not returning a an List)
    //
    // (NOTE: not doing this yet due to how it will impact most other tests, many of which are currently
    // @AwaitsFix'ed)
    //
    //assertTrue(doc.getFieldValue("val_ss").getClass().toString(),
    //           doc.getFieldValue("val_ss") instanceof List);
    // single value int using alias that matches multivalued dynamic field
    doc = assertSearchOneDoc(params("q", "id:42", "fl", "val_ss:val_i, val2_ss:10"));
    assertEquals("" + doc, 2, doc.size());
    assertEquals("" + doc, 1, doc.getFieldValue("val_ss"));
    assertEquals("" + doc, 10L, doc.getFieldValue("val2_ss"));
}
Also used : Field(org.apache.solr.client.solrj.request.schema.SchemaRequest.Field) SolrDocument(org.apache.solr.common.SolrDocument) SolrServerException(org.apache.solr.client.solrj.SolrServerException) FieldResponse(org.apache.solr.client.solrj.response.schema.SchemaResponse.FieldResponse)

Aggregations

Field (org.apache.solr.client.solrj.request.schema.SchemaRequest.Field)4 FieldResponse (org.apache.solr.client.solrj.response.schema.SchemaResponse.FieldResponse)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 SolrInputField (org.apache.solr.common.SolrInputField)1