Search in sources :

Example 1 with Query

use of play.modules.solr.Query in project play-cookbook by spinscale.

the class SolrSearchTest method testPagination.

@Test
public void testPagination() throws Exception {
    Car.deleteAll();
    clearSolrServerIndex();
    Fixtures.loadModels("test-data-many-cars.yml");
    List<Model> result = new Query("brand_s:*", Car.class).limit(10).start(10).fetch();
    assertEquals(3, result.size());
}
Also used : Query(play.modules.solr.Query) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Car(models.Car) Model(play.db.jpa.Model) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 2 with Query

use of play.modules.solr.Query in project play-cookbook by spinscale.

the class SolrSearchTest method testQuery.

@Test
public void testQuery() {
    List<User> users = new Query("name:alex", User.class).fetch();
    assertEquals(1, users.size());
    assertEquals("alex", users.get(0).name);
}
Also used : User(models.User) Query(play.modules.solr.Query) SolrQuery(org.apache.solr.client.solrj.SolrQuery) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 3 with Query

use of play.modules.solr.Query in project play-cookbook by spinscale.

the class SolrSearchTest method testQueryResultIds.

@Test
public void testQueryResultIds() {
    User u = User.find("byName", "alex").first();
    List<String> users = new Query("name:alex", User.class).fetchIds();
    assertEquals(u.id.toString(), users.get(0));
}
Also used : User(models.User) Query(play.modules.solr.Query) SolrQuery(org.apache.solr.client.solrj.SolrQuery) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 4 with Query

use of play.modules.solr.Query in project play-cookbook by spinscale.

the class SolrSearchTest method ensureDeletionWorks.

@Test
public void ensureDeletionWorks() throws Exception {
    List<Car> cars = Car.findAll();
    for (Car car : cars) {
        car.delete();
    }
    assertEquals(0, new Query("brand_s:*", Car.class).fetchIds().size());
}
Also used : Query(play.modules.solr.Query) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Car(models.Car) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 5 with Query

use of play.modules.solr.Query in project play-cookbook by spinscale.

the class SolrSearchTest method testOffset.

@Test
public void testOffset() throws Exception {
    Car.deleteAll();
    clearSolrServerIndex();
    Fixtures.loadModels("test-data-many-cars.yml");
    List<Model> result = new Query("brand_s:*", Car.class).limit(5).start(0).fetch();
    assertEquals(5, result.size());
    result = new Query("brand_s:*", Car.class).limit(5).start(5).fetch();
    assertEquals(5, result.size());
    result = new Query("brand_s:*", Car.class).limit(5).start(10).fetch();
    assertEquals(3, result.size());
}
Also used : Query(play.modules.solr.Query) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Car(models.Car) Model(play.db.jpa.Model) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Aggregations

SolrQuery (org.apache.solr.client.solrj.SolrQuery)5 Test (org.junit.Test)5 Query (play.modules.solr.Query)5 UnitTest (play.test.UnitTest)5 Car (models.Car)3 User (models.User)2 Model (play.db.jpa.Model)2