Example usage for org.apache.solr.client.solrj SolrQuery getSortField

List of usage examples for org.apache.solr.client.solrj SolrQuery getSortField

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrQuery getSortField.

Prototype

public String getSortField() 

Source Link

Document

Gets the raw sort field, as it will be sent to Solr.

Usage

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

License:Apache License

@Test
public void testWithSortMixedDirections() {
    SimpleStringCriteria criteria = new SimpleStringCriteria("field_1:value_1");
    Query query = new SimpleQuery(criteria);
    query.addSort(new Sort("field_1"));
    query.addSort(new Sort(Sort.Direction.DESC, "field_2", "field_3"));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertEquals("field_1 asc,field_2 desc,field_3 desc", solrQuery.getSortField());
    Assert.assertEquals(3, solrQuery.getSorts().size());
}

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

License:Apache License

@Test
public void testWithNullSort() {
    SimpleStringCriteria criteria = new SimpleStringCriteria("field_1:value_1");
    Query query = new SimpleQuery(criteria);
    query.addSort(null); // do this explicitly

    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertNull(solrQuery.getSortField());
    Assert.assertNull(solrQuery.getSortFields());
}

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

License:Apache License

@Test
public void testWithSortAscOnSingleField() {
    SimpleStringCriteria criteria = new SimpleStringCriteria("field_1:value_1");
    Query query = new SimpleQuery(criteria);
    query.addSort(new Sort("field_2"));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertEquals("field_2 asc", solrQuery.getSortField());
    Assert.assertEquals(1, solrQuery.getSortFields().length);
}

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

License:Apache License

@Test
public void testWithSortDescOnSingleField() {
    SimpleStringCriteria criteria = new SimpleStringCriteria("field_1:value_1");
    Query query = new SimpleQuery(criteria);
    query.addSort(new Sort(Sort.Direction.DESC, "field_2"));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertEquals("field_2 desc", solrQuery.getSortField());
    Assert.assertEquals(1, solrQuery.getSortFields().length);
}

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

License:Apache License

@Test
public void testWithSortAscMultipleFields() {
    SimpleStringCriteria criteria = new SimpleStringCriteria("field_1:value_1");
    Query query = new SimpleQuery(criteria);
    query.addSort(new Sort("field_2, field_3"));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertEquals("field_2, field_3 asc", solrQuery.getSortField());
    Assert.assertEquals(2, solrQuery.getSortFields().length);
}

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

License:Apache License

@Test
public void testWithSortDescMultipleFields() {
    SimpleStringCriteria criteria = new SimpleStringCriteria("field_1:value_1");
    Query query = new SimpleQuery(criteria);
    query.addSort(new Sort(Sort.Direction.DESC, "field_2, field_3"));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertEquals("field_2, field_3 desc", solrQuery.getSortField());
    Assert.assertEquals(2, solrQuery.getSortFields().length);
}

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

License:Apache License

@Test
public void testWithSortMixedDirections() {
    SimpleStringCriteria criteria = new SimpleStringCriteria("field_1:value_1");
    Query query = new SimpleQuery(criteria);
    query.addSort(new Sort("field_1"));
    query.addSort(new Sort(Sort.Direction.DESC, "field_2, field_3"));
    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertEquals("field_1 asc,field_2, field_3 desc", solrQuery.getSortField());
    Assert.assertEquals(3, solrQuery.getSortFields().length);
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.params.UrlSolrParamsTest.java

License:Apache License

@Test
public void params1() throws Exception {
    String params = "q=*:*&sort=rigid asc&rows=30&fq=+dataset:(\"Cancer\")&fq=+go_expanded_id:(\"GO:0048511\")&start=0";

    UrlSolrParams solrParams = new UrlSolrParams(params);

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.add(solrParams);//ww w  . j av  a2 s  . c  om

    Assert.assertEquals("*:*", solrQuery.getQuery());
    Assert.assertEquals("rigid asc", solrQuery.getSortField());
    Assert.assertEquals(Integer.valueOf(30), solrQuery.getRows());
    Assert.assertEquals(Integer.valueOf(0), solrQuery.getStart());

    Assert.assertTrue(Arrays.asList(solrQuery.getFilterQueries()).contains("+go_expanded_id:(\"GO:0048511\")"));
    Assert.assertTrue(Arrays.asList(solrQuery.getFilterQueries()).contains("+dataset:(\"Cancer\")"));
}