Example usage for org.springframework.data.solr.core.query PartialUpdate PartialUpdate

List of usage examples for org.springframework.data.solr.core.query PartialUpdate PartialUpdate

Introduction

In this page you can find the example usage for org.springframework.data.solr.core.query PartialUpdate PartialUpdate.

Prototype

public PartialUpdate(Field idField, Object idFieldValue) 

Source Link

Usage

From source file:com.nixmash.springdata.solr.repository.custom.CustomProductRepositoryImpl.java

@Override
public void updateProductCategory(String productId, List<String> categories) {
    PartialUpdate update = new PartialUpdate(IProduct.ID_FIELD, productId);
    update.setValueOfField(IProduct.CATEGORY_FIELD, categories);
    solrTemplate.saveBean(update);/*  ww  w .  j a  v a 2 s. c o  m*/
    solrTemplate.commit();
}

From source file:com.nixmash.springdata.solr.repository.custom.CustomProductRepositoryImpl.java

@Override
public void updateProductName(Product product) {
    logger.debug("Performing partial update for todo entry: {}", product);
    PartialUpdate update = new PartialUpdate(Product.ID_FIELD, product.getId().toString());
    update.add(Product.NAME_FIELD, product.getName());
    solrTemplate.saveBean(update);//  w w  w .  jav a2s  .  c o m
    solrTemplate.commit();
}

From source file:org.springframework.data.solr.core.SolrTemplateTests.java

@SuppressWarnings("unchecked")
@Test//from   w  w  w.  ja v a2s . c  om
public void testPartialUpdate() throws SolrServerException, IOException {
    Mockito.when(solrServerMock.add(Mockito.any(SolrInputDocument.class))).thenReturn(new UpdateResponse());

    PartialUpdate update = new PartialUpdate("id", "update-id");
    update.add("field_1", "update");

    solrTemplate.saveBean(update);
    ArgumentCaptor<SolrInputDocument> captor = ArgumentCaptor.forClass(SolrInputDocument.class);
    Mockito.verify(solrServerMock, Mockito.times(1)).add(captor.capture());

    Assert.assertTrue(captor.getValue().getFieldValue("field_1") instanceof Map);
    Assert.assertEquals("update",
            ((Map<String, Object>) captor.getValue().getFieldValue("field_1")).get("set"));
}