Package org.springframework.data.solr.core.query

Examples of org.springframework.data.solr.core.query.SimpleQuery


      values.add(createExampleBeanWithId(Integer.toString(i)));
    }
    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    Query query = new SimpleQuery(new SimpleStringCriteria("*:*")).addSort(new Sort(Sort.Direction.DESC, "name"));
    Page<ExampleSolrBean> page = solrTemplate.queryForPage(query, ExampleSolrBean.class);

    ExampleSolrBean prev = page.getContent().get(0);
    for (int i = 1; i < page.getContent().size(); i++) {
      ExampleSolrBean cur = page.getContent().get(i);
View Full Code Here


      values.add(bean);
    }
    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    Query query = new SimpleQuery(new SimpleStringCriteria("*:*")).addSort(new Sort(Sort.Direction.DESC, "inStock"))
        .addSort(new Sort(Sort.Direction.ASC, "name"));
    Page<ExampleSolrBean> page = solrTemplate.queryForPage(query, ExampleSolrBean.class);

    ExampleSolrBean prev = page.getContent().get(0);
    for (int i = 1; i < 5; i++) {
View Full Code Here

      values.add(bean);
    }
    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    SimpleQuery query = new SimpleQuery(new SimpleStringCriteria("inStock:(true false)"));
    query.setDefaultOperator(Operator.AND);
    Page<ExampleSolrBean> page = solrTemplate.queryForPage(query, ExampleSolrBean.class);
    Assert.assertEquals(0, page.getContent().size());

    query.setDefaultOperator(Operator.OR);
    page = solrTemplate.queryForPage(query, ExampleSolrBean.class);
    Assert.assertEquals(10, page.getContent().size());
  }
View Full Code Here

  public void testQueryWithDefType() {
    List<ExampleSolrBean> values = createBeansWithIdAndPrefix(5, "id-");
    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    SimpleQuery query = new SimpleQuery(new Criteria("id").in("id-1", "id-2", "id-3"));
    query.setDefType("lucene");
    query.setDefaultOperator(Operator.OR);

    Page<ExampleSolrBean> page = solrTemplate.queryForPage(query, ExampleSolrBean.class);
    Assert.assertEquals(3, page.getContent().size());
  }
View Full Code Here

    values.get(1).setInStock(true);

    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    SimpleQuery query = new SimpleQuery(new Criteria("id").in("rh-1", "rh-2"));
    Page<ExampleSolrBean> page = solrTemplate.queryForPage(query, ExampleSolrBean.class);
    Assert.assertEquals(2, page.getContent().size());

    query = new SimpleQuery(new Criteria("id").in("rh-1", "rh-2"));
    query.setRequestHandler("/instock");
    page = solrTemplate.queryForPage(query, ExampleSolrBean.class);
    Assert.assertEquals(1, page.getContent().size());
    Assert.assertEquals("rh-2", page.getContent().get(0).getId());
  }
View Full Code Here

    ipod.setManufacturerId(belkin.getId());

    solrTemplate.saveBeans(Arrays.asList(belkin, apple, ipod));
    solrTemplate.commit();

    SimpleQuery query = new SimpleQuery(new SimpleStringCriteria("text:ipod"));
    query.setJoin(Join.from("manu_id_s").to("id"));

    Page<ExampleSolrBean> page = solrTemplate.queryForPage(query, ExampleSolrBean.class);
    Assert.assertEquals(1, page.getContent().size());
    Assert.assertEquals(belkin.getId(), page.getContent().get(0).getId());
  }
View Full Code Here

    ExampleSolrBean bean1 = new ExampleSolrBean("id-1", "one", null);
    ExampleSolrBean bean2 = new ExampleSolrBean("id-2", "two", null);
    solrTemplate.saveBeans(Arrays.asList(bean1, bean2));
    solrTemplate.commit();

    Query q = new SimpleQuery("*:*").addFilterQuery(new SimpleFilterQuery(new Criteria(QueryFunction
        .query("{!query v = 'one'}"))));

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(q, ExampleSolrBean.class);
    Assert.assertThat(result.getContent().get(0).getId(), IsEqual.equalTo(bean1.getId()));
  }
View Full Code Here

    ExampleSolrBean bean1 = new ExampleSolrBean("id-1", "one", null);
    ExampleSolrBean bean2 = new ExampleSolrBean("id-2", "two", null);
    solrTemplate.saveBeans(Arrays.asList(bean1, bean2));
    solrTemplate.commit();

    Query q = new SimpleQuery(new Criteria(QueryFunction.query("{!query v='two'}")));

    Page<ExampleSolrBean> result = solrTemplate.queryForPage(q, ExampleSolrBean.class);
    Assert.assertThat(result.getContent().get(0).getId(), Is.is(bean2.getId()));
  }
View Full Code Here

    bean2.setStore("40.7143,-74.006");

    solrTemplate.saveBeans(Arrays.asList(bean1, bean2));
    solrTemplate.commit();

    Query q = new SimpleQuery("*:*");
    q.addProjectionOnField(new DistanceField("distance", "store", new Point(45.15, -93.85)));
    Page<ExampleSolrBean> result = solrTemplate.queryForPage(q, ExampleSolrBean.class);
    for (ExampleSolrBean bean : result) {
      Assert.assertThat(bean.getDistance(), IsNull.notNullValue());
    }

View Full Code Here

    solrTemplate.saveBeans(createBeansWithId(100));
    solrTemplate.commit();

    Cursor<ExampleSolrBean> cursor = solrTemplate.queryForCursor(
        new SimpleQuery("*:*").addSort(new Sort(Direction.DESC, "id")), ExampleSolrBean.class);

    int i = 0;
    while (cursor.hasNext()) {
      cursor.next();
      i++;
View Full Code Here

TOP

Related Classes of org.springframework.data.solr.core.query.SimpleQuery

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.