当前位置: 首页>>代码示例>>Java>>正文


Java SortClause类代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.SolrQuery.SortClause的典型用法代码示例。如果您正苦于以下问题:Java SortClause类的具体用法?Java SortClause怎么用?Java SortClause使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SortClause类属于org.apache.solr.client.solrj.SolrQuery包,在下文中一共展示了SortClause类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSortClause

import org.apache.solr.client.solrj.SolrQuery.SortClause; //导入依赖的package包/类
public void testSortClause() {
  new SolrQuery.SortClause("rating", SolrQuery.ORDER.desc);
  new SolrQuery.SortClause("rating", SolrQuery.ORDER.valueOf("desc"));
  new SolrQuery.SortClause("rating", SolrQuery.ORDER.valueOf("desc"));
  SolrQuery.SortClause.create("rating", SolrQuery.ORDER.desc);
  SolrQuery.SortClause.create("rating", SolrQuery.ORDER.desc);
  SolrQuery.SortClause.create("rating", SolrQuery.ORDER.desc);

  SolrQuery.SortClause sc1a = SolrQuery.SortClause.asc("sc1");
  SolrQuery.SortClause sc1b = SolrQuery.SortClause.asc("sc1");
  Assert.assertEquals(sc1a, sc1b);
  Assert.assertEquals(sc1a.hashCode(), sc1b.hashCode());

  SolrQuery.SortClause sc2a = SolrQuery.SortClause.asc("sc2");
  SolrQuery.SortClause sc2b = SolrQuery.SortClause.desc("sc2");
  Assert.assertFalse(sc2a.equals(sc2b));

  SolrQuery.SortClause sc3a = SolrQuery.SortClause.asc("sc2");
  SolrQuery.SortClause sc3b = SolrQuery.SortClause.asc("not sc2");
  Assert.assertFalse(sc3a.equals(sc3b));
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:SolrQueryTest.java

示例2: attachSortClause

import org.apache.solr.client.solrj.SolrQuery.SortClause; //导入依赖的package包/类
@Override
public void attachSortClause(SolrQuery query, SearchCriteria searchCriteria, String defaultSort, List<Field> fields) {
    Map<String, String> solrFieldKeyMap = getSolrFieldKeyMap(searchCriteria, fields);

    String sortQuery = searchCriteria.getSortQuery();
    if (StringUtils.isBlank(sortQuery)) {
        sortQuery = defaultSort;
    }

    if (StringUtils.isNotBlank(sortQuery)) {
        String[] sortFields = sortQuery.split(",");
        for (String sortField : sortFields) {
            String field = sortField.split(" ")[0];
            if (solrFieldKeyMap.containsKey(field)) {
                field = solrFieldKeyMap.get(field);
            }
            ORDER order = "desc".equals(sortField.split(" ")[1]) ? ORDER.desc : ORDER.asc;

            if (field != null) {
                query.addSort(new SortClause(field, order));
            }
        }
    }
}
 
开发者ID:takbani,项目名称:blcdemo,代码行数:25,代码来源:SolrHelperServiceImpl.java

示例3: applySortOptions

import org.apache.solr.client.solrj.SolrQuery.SortClause; //导入依赖的package包/类
public static SolrQuery applySortOptions(SolrQuery q, List<MCRSortBy> sortBy) {
    for (MCRSortBy option : sortBy) {
        SortClause sortClause = new SortClause(option.getFieldName(), option.getSortOrder() ? ORDER.asc
            : ORDER.desc);
        q.addSort(sortClause);
    }
    return q;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:9,代码来源:MCRConditionTransformer.java

示例4: createQuery

import org.apache.solr.client.solrj.SolrQuery.SortClause; //导入依赖的package包/类
private SolrQuery createQuery(String query) {
  SolrQuery q = new SolrQuery("*:*");
  // TODO: Should we add a request handler to the solr cluster to get metrics
  // on the volume and/or performance of these searches in their own bucket?
  q.setFilterQueries(query);
  q.setFields(SOLR_FIELDS);
  q.setSort(SortClause.asc(SolrEnum.ID.toString()));
  q.setRows(solrReadSize);
  return q;
}
 
开发者ID:nla,项目名称:bamboo,代码行数:11,代码来源:RuleChangeUpdateManager.java

示例5: testSort

import org.apache.solr.client.solrj.SolrQuery.SortClause; //导入依赖的package包/类
public void testSort() throws IOException {

    SolrQuery q = new SolrQuery("dog");

    // Simple adds
    q.addSort("price", SolrQuery.ORDER.asc);
    q.addSort("date", SolrQuery.ORDER.desc);
    q.addSort("qty", SolrQuery.ORDER.desc);
    Assert.assertEquals(3, q.getSorts().size());
    Assert.assertEquals("price asc,date desc,qty desc", q.get(CommonParams.SORT));

    // Remove one (middle)
    q.removeSort("date");
    Assert.assertEquals(2, q.getSorts().size());
    Assert.assertEquals("price asc,qty desc", q.get(CommonParams.SORT));

    // Remove remaining (last, first)
    q.removeSort("price");
    q.removeSort("qty");
    Assert.assertTrue(q.getSorts().isEmpty());
    Assert.assertNull(q.get(CommonParams.SORT));

    // Clear sort
    q.addSort("price", SolrQuery.ORDER.asc);
    q.clearSorts();
    Assert.assertTrue(q.getSorts().isEmpty());
    Assert.assertNull(q.get(CommonParams.SORT));

    // Add vs update
    q.clearSorts();
    q.addSort("1", SolrQuery.ORDER.asc);
    q.addSort("2", SolrQuery.ORDER.asc);
    q.addSort("3", SolrQuery.ORDER.asc);
    q.addOrUpdateSort("2", SolrQuery.ORDER.desc);
    q.addOrUpdateSort("4", SolrQuery.ORDER.desc);
    Assert.assertEquals("1 asc,2 desc,3 asc,4 desc", q.get(CommonParams.SORT));

    // Using SortClause
    q.clearSorts();
    q.addSort(new SortClause("1", SolrQuery.ORDER.asc));
    q.addSort(new SortClause("2", SolrQuery.ORDER.asc));
    q.addSort(new SortClause("3", SolrQuery.ORDER.asc));
    q.addOrUpdateSort(SortClause.desc("2"));
    q.addOrUpdateSort(SortClause.asc("4"));
    Assert.assertEquals("1 asc,2 desc,3 asc,4 asc", q.get(CommonParams.SORT));
    q.setSort(SortClause.asc("A"));
    q.addSort(SortClause.asc("B"));
    q.addSort(SortClause.asc("C"));
    q.addSort(SortClause.asc("D"));
    Assert.assertEquals("A asc,B asc,C asc,D asc", q.get(CommonParams.SORT));

    // removeSort should ignore the ORDER
    q.setSort(SortClause.asc("A"));
    q.addSort(SortClause.asc("B"));
    q.addSort(SortClause.asc("C"));
    q.addSort(SortClause.asc("D"));
    q.removeSort("A");
    q.removeSort(SortClause.asc("C"));
    q.removeSort(SortClause.desc("B"));
    Assert.assertEquals("D asc", q.get(CommonParams.SORT));

    // Verify that a query containing a SortClause is serializable
    q.clearSorts();
    q.addSort("1", SolrQuery.ORDER.asc);
    ObjectOutputStream out = new ObjectOutputStream(new ByteArrayOutputStream());
    out.writeObject(q);
    out.close();
  }
 
开发者ID:europeana,项目名称:search,代码行数:69,代码来源:SolrQueryTest.java

示例6: addSortField

import org.apache.solr.client.solrj.SolrQuery.SortClause; //导入依赖的package包/类
/**
 * 增加排序方式。先加入的优先级较高。
 * @param sortField
 * @return
 */
public SortFilter addSortField(SortClause sortField) {
	this.sortClauses.add(sortField);
	return this;
}
 
开发者ID:dowenliu-xyz,项目名称:solrj-util,代码行数:10,代码来源:SortFilter.java


注:本文中的org.apache.solr.client.solrj.SolrQuery.SortClause类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。