Package org.springframework.data.solr

Examples of org.springframework.data.solr.ExampleSolrBean


    solrTemplate.commit();
  }

  @Test
  public void testNegativeNumberCriteria() {
    ExampleSolrBean positivePopularity = createExampleBeanWithId("1");
    positivePopularity.setPopularity(100);

    ExampleSolrBean negativePopularity = createExampleBeanWithId("2");
    negativePopularity.setPopularity(-200);

    solrTemplate.saveBeans(Arrays.asList(positivePopularity, negativePopularity));
    solrTemplate.commit();

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(new SimpleQuery(new Criteria("popularity").is(-200)),
        ExampleSolrBean.class);
    Assert.assertEquals(1, result.getContent().size());
    Assert.assertEquals(negativePopularity.getId(), result.getContent().get(0).getId());
  }
View Full Code Here


    Assert.assertEquals(negativePopularity.getId(), result.getContent().get(0).getId());
  }

  @Test
  public void testNegativeNumberInRange() {
    ExampleSolrBean negative100 = createExampleBeanWithId("1");
    negative100.setPopularity(-100);

    ExampleSolrBean negative200 = createExampleBeanWithId("2");
    negative200.setPopularity(-200);

    solrTemplate.saveBeans(Arrays.asList(negative100, negative200));
    solrTemplate.commit();

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(
View Full Code Here

    Assert.assertEquals(negative100.getId(), result.getContent().get(0).getId());
  }

  @Test
  public void testDateValue() {
    ExampleSolrBean searchableBean = createExampleBeanWithId("1");
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.set(2012, 7, 23, 6, 10, 0);
    searchableBean.setLastModified(calendar.getTime());

    solrTemplate.saveBean(searchableBean);
    solrTemplate.commit();

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(
View Full Code Here

    Assert.assertEquals(1, result.getContent().size());
  }

  @Test
  public void testDateValueInRangeQuery() {
    ExampleSolrBean searchableBeanIn2012 = createExampleBeanWithId("1");
    Calendar calendar2012 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar2012.set(2012, 7, 23, 6, 10, 0);
    searchableBeanIn2012.setLastModified(calendar2012.getTime());

    ExampleSolrBean searchableBeanIn2011 = createExampleBeanWithId("2");
    Calendar calendar2011 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar2011.set(2011, 7, 23, 6, 10, 0);
    searchableBeanIn2011.setLastModified(calendar2011.getTime());

    solrTemplate.saveBeans(Arrays.asList(searchableBeanIn2012, searchableBeanIn2011));
    solrTemplate.commit();

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(
View Full Code Here

  }

  @Test
  public void testPoint() {
    ExampleSolrBean searchableBeanInBuffalow = createExampleBeanWithId("1");
    searchableBeanInBuffalow.setStore("45.17614,-93.87341");

    ExampleSolrBean searchableBeanInNYC = createExampleBeanWithId("2");
    searchableBeanInNYC.setStore("40.7143,-74.006");

    solrTemplate.saveBeans(Arrays.asList(searchableBeanInBuffalow, searchableBeanInNYC));
    solrTemplate.commit();

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(
View Full Code Here

    Assert.assertEquals(1, result.getContent().size());
  }

  @Test
  public void testPointWithDistanceInMiles() {
    ExampleSolrBean searchableBeanInBuffalow = createExampleBeanWithId("1");
    searchableBeanInBuffalow.setStore("45.17614,-93.87341");

    ExampleSolrBean searchableBeanInNYC = createExampleBeanWithId("2");
    searchableBeanInNYC.setStore("40.7143,-74.006");

    solrTemplate.saveBeans(Arrays.asList(searchableBeanInBuffalow, searchableBeanInNYC));
    solrTemplate.commit();

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(
View Full Code Here

    solrTemplate.commit();
  }

  @Test
  public void testBeanLifecycle() {
    ExampleSolrBean toInsert = createDefaultExampleBean();

    solrTemplate.saveBean(toInsert);
    ExampleSolrBean recalled = solrTemplate.queryForObject(new SimpleQuery(new Criteria("id").is("1")),
        ExampleSolrBean.class);
    Assert.assertNull(recalled);
    solrTemplate.commit();

    recalled = solrTemplate.queryForObject(new SimpleQuery(new Criteria("id").is("1")), ExampleSolrBean.class);
    Assert.assertEquals(toInsert.getId(), recalled.getId());

    solrTemplate.deleteById(toInsert.getId());
    recalled = solrTemplate.queryForObject(new SimpleQuery(new Criteria("id").is("1")), ExampleSolrBean.class);
    Assert.assertEquals(toInsert.getId(), recalled.getId());

    solrTemplate.commit();
    recalled = solrTemplate.queryForObject(new SimpleQuery(new Criteria("id").is("1")), ExampleSolrBean.class);
    Assert.assertNull(recalled);
  }
View Full Code Here

    Assert.assertNull(recalled);
  }

  @Test
  public void testPartialUpdateSetSingleValueField() {
    ExampleSolrBean toInsert = createDefaultExampleBean();
    toInsert.setPopularity(10);
    solrTemplate.saveBean(toInsert);
    solrTemplate.commit();

    PartialUpdate update = new PartialUpdate("id", DEFAULT_BEAN_ID);
    update.add("name", "updated-name");
    solrTemplate.saveBean(update);
    solrTemplate.commit();

    Assert.assertEquals(1, solrTemplate.count(ALL_DOCUMENTS_QUERY));

    ExampleSolrBean recalled = solrTemplate.queryForObject(DEFAULT_BEAN_OBJECT_QUERY, ExampleSolrBean.class);

    Assert.assertEquals(toInsert.getId(), recalled.getId());
    Assert.assertEquals("updated-name", recalled.getName());
    Assert.assertEquals(toInsert.getPopularity(), recalled.getPopularity());
  }
View Full Code Here

    Assert.assertEquals(toInsert.getPopularity(), recalled.getPopularity());
  }

  @Test
  public void testPartialUpdateAddSingleValueToMultivalueField() {
    ExampleSolrBean toInsert = createDefaultExampleBean();
    toInsert.setPopularity(10);
    toInsert.setCategory(Arrays.asList("nosql"));
    solrTemplate.saveBean(toInsert);
    solrTemplate.commit();

    PartialUpdate update = new PartialUpdate("id", DEFAULT_BEAN_ID);
    update.add(new SimpleUpdateField("cat", "spring-data-solr", UpdateAction.ADD));
    solrTemplate.saveBean(update);
    solrTemplate.commit();

    Assert.assertEquals(1, solrTemplate.count(ALL_DOCUMENTS_QUERY));

    ExampleSolrBean recalled = solrTemplate.queryForObject(DEFAULT_BEAN_OBJECT_QUERY, ExampleSolrBean.class);

    Assert.assertEquals(toInsert.getId(), recalled.getId());

    Assert.assertEquals(2, recalled.getCategory().size());
    Assert.assertEquals(Arrays.asList("nosql", "spring-data-solr"), recalled.getCategory());

    Assert.assertEquals(toInsert.getName(), recalled.getName());
    Assert.assertEquals(toInsert.getPopularity(), recalled.getPopularity());
  }
View Full Code Here

    Assert.assertEquals(toInsert.getPopularity(), recalled.getPopularity());
  }

  @Test
  public void testPartialUpdateIncSingleValue() {
    ExampleSolrBean toInsert = createDefaultExampleBean();
    toInsert.setPopularity(10);
    solrTemplate.saveBean(toInsert);
    solrTemplate.commit();

    PartialUpdate update = new PartialUpdate("id", DEFAULT_BEAN_ID);
    update.add(new SimpleUpdateField("popularity", 1, UpdateAction.INC));
    solrTemplate.saveBean(update);
    solrTemplate.commit();

    Assert.assertEquals(1, solrTemplate.count(ALL_DOCUMENTS_QUERY));

    ExampleSolrBean recalled = solrTemplate.queryForObject(DEFAULT_BEAN_OBJECT_QUERY, ExampleSolrBean.class);

    Assert.assertEquals(toInsert.getId(), recalled.getId());

    Assert.assertEquals(1, recalled.getCategory().size());

    Assert.assertEquals(toInsert.getName(), recalled.getName());
    Assert.assertEquals(Integer.valueOf(11), recalled.getPopularity());
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.solr.ExampleSolrBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.