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


Java Grouping类代码示例

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


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

示例1: docIterator

import org.apache.solr.search.Grouping; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private Iterator<Integer> docIterator(ResponseBuilder rb) {
  if (rb.grouping()) {
    List<Integer> docList = new ArrayList<>();
    NamedList values = rb.rsp.getValues();
    NamedList grouped = (NamedList)values.get("grouped");
    for (String field : rb.getGroupingSpec().getFields()) {
      NamedList fieldResults = (NamedList)grouped.get(field);
      if (rb.getGroupingSpec().getResponseFormat() == Grouping.Format.grouped) {
        List<NamedList> groups = (List<NamedList>)fieldResults.get("groups");
        for (NamedList group : groups) {
          for (DocIterator it = ((DocList)group.get("doclist")).iterator(); it.hasNext(); ) {
            docList.add(it.nextDoc());
          }
        }
      } else {
        for (DocIterator it = ((DocList)fieldResults.get("doclist")).iterator(); it.hasNext(); ) {
          docList.add(it.nextDoc());
        }
      }
    }
    return docList.iterator();
  } else {
    return rb.getResults().docList.iterator();
  }
  
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:28,代码来源:XJoinSearchComponent.java

示例2: getResponseFormat

import org.apache.solr.search.Grouping; //导入依赖的package包/类
public Grouping.Format getResponseFormat() {
  return responseFormat;
}
 
开发者ID:europeana,项目名称:search,代码行数:4,代码来源:GroupingSpecification.java

示例3: setResponseFormat

import org.apache.solr.search.Grouping; //导入依赖的package包/类
public void setResponseFormat(Grouping.Format responseFormat) {
  this.responseFormat = responseFormat;
}
 
开发者ID:europeana,项目名称:search,代码行数:4,代码来源:GroupingSpecification.java

示例4: createRequest

import org.apache.solr.search.Grouping; //导入依赖的package包/类
private ShardRequest[] createRequest(ResponseBuilder rb, String[] shards)
{
  ShardRequest sreq = new ShardRequest();
  sreq.shards = shards;
  sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS;
  sreq.params = new ModifiableSolrParams(rb.req.getParams());

  // If group.format=simple group.offset doesn't make sense
  Grouping.Format responseFormat = rb.getGroupingSpec().getResponseFormat();
  if (responseFormat == Grouping.Format.simple || rb.getGroupingSpec().isMain()) {
    sreq.params.remove(GroupParams.GROUP_OFFSET);
  }

  sreq.params.remove(ShardParams.SHARDS);

  // set the start (offset) to 0 for each shard request so we can properly merge
  // results from the start.
  if (rb.shards_start > -1) {
    // if the client set shards.start set this explicitly
    sreq.params.set(CommonParams.START, rb.shards_start);
  } else {
    sreq.params.set(CommonParams.START, "0");
  }
  if (rb.shards_rows > -1) {
    // if the client set shards.rows set this explicity
    sreq.params.set(CommonParams.ROWS, rb.shards_rows);
  } else {
    sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
  }

  sreq.params.set(GroupParams.GROUP_DISTRIBUTED_SECOND, "true");
  final IndexSchema schema = rb.req.getSearcher().getSchema();
  for (Map.Entry<String, Collection<SearchGroup<BytesRef>>> entry : rb.mergedSearchGroups.entrySet()) {
    for (SearchGroup<BytesRef> searchGroup : entry.getValue()) {
      String groupValue;
      if (searchGroup.groupValue != null) {
        String rawGroupValue = searchGroup.groupValue.utf8ToString();
        FieldType fieldType = schema.getField(entry.getKey()).getType();
        groupValue = fieldType.indexedToReadable(rawGroupValue);
      } else {
        groupValue = GROUP_NULL_VALUE;
      }
      sreq.params.add(GroupParams.GROUP_DISTRIBUTED_TOPGROUPS_PREFIX + entry.getKey(), groupValue);
    }
  }

  if ((rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0 || rb.getSortSpec().includesScore()) {
    sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName() + ",score");
  } else {
    sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName());
  }
  
  int origTimeAllowed = sreq.params.getInt(CommonParams.TIME_ALLOWED, -1);
  if (origTimeAllowed > 0) {
    sreq.params.set(CommonParams.TIME_ALLOWED, Math.max(1,origTimeAllowed - rb.firstPhaseElapsedTime));
  }

  return new ShardRequest[] {sreq};
}
 
开发者ID:europeana,项目名称:search,代码行数:60,代码来源:TopGroupsShardRequestFactory.java

示例5: prepareGrouping

import org.apache.solr.search.Grouping; //导入依赖的package包/类
private void prepareGrouping(ResponseBuilder rb) throws IOException {

    SolrQueryRequest req = rb.req;
    SolrParams params = req.getParams();

    if (null != rb.getCursorMark()) {
      // It's hard to imagine, conceptually, what it would mean to combine
      // grouping with a cursor - so for now we just don't allow the combination at all
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can not use Grouping with " +
                              CursorMarkParams.CURSOR_MARK_PARAM);
    }

    SolrIndexSearcher.QueryCommand cmd = rb.getQueryCommand();
    SolrIndexSearcher searcher = rb.req.getSearcher();
    GroupingSpecification groupingSpec = new GroupingSpecification();
    rb.setGroupingSpec(groupingSpec);

    //TODO: move weighting of sort
    Sort groupSort = searcher.weightSort(cmd.getSort());
    if (groupSort == null) {
      groupSort = Sort.RELEVANCE;
    }

    // groupSort defaults to sort
    String groupSortStr = params.get(GroupParams.GROUP_SORT);
    //TODO: move weighting of sort
    Sort sortWithinGroup = groupSortStr == null ?  groupSort : searcher.weightSort(QueryParsing.parseSortSpec(groupSortStr, req).getSort());
    if (sortWithinGroup == null) {
      sortWithinGroup = Sort.RELEVANCE;
    }

    groupingSpec.setSortWithinGroup(sortWithinGroup);
    groupingSpec.setGroupSort(groupSort);

    String formatStr = params.get(GroupParams.GROUP_FORMAT, Grouping.Format.grouped.name());
    Grouping.Format responseFormat;
    try {
       responseFormat = Grouping.Format.valueOf(formatStr);
    } catch (IllegalArgumentException e) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, String.format(Locale.ROOT, "Illegal %s parameter", GroupParams.GROUP_FORMAT));
    }
    groupingSpec.setResponseFormat(responseFormat);

    groupingSpec.setFields(params.getParams(GroupParams.GROUP_FIELD));
    groupingSpec.setQueries(params.getParams(GroupParams.GROUP_QUERY));
    groupingSpec.setFunctions(params.getParams(GroupParams.GROUP_FUNC));
    groupingSpec.setGroupOffset(params.getInt(GroupParams.GROUP_OFFSET, 0));
    groupingSpec.setGroupLimit(params.getInt(GroupParams.GROUP_LIMIT, 1));
    groupingSpec.setOffset(rb.getSortSpec().getOffset());
    groupingSpec.setLimit(rb.getSortSpec().getCount());
    groupingSpec.setIncludeGroupCount(params.getBool(GroupParams.GROUP_TOTAL_COUNT, false));
    groupingSpec.setMain(params.getBool(GroupParams.GROUP_MAIN, false));
    groupingSpec.setNeedScore((cmd.getFlags() & SolrIndexSearcher.GET_SCORES) != 0);
    groupingSpec.setTruncateGroups(params.getBool(GroupParams.GROUP_TRUNCATE, false));
  }
 
开发者ID:europeana,项目名称:search,代码行数:56,代码来源:QueryComponent.java

示例6: createRequest

import org.apache.solr.search.Grouping; //导入依赖的package包/类
private ShardRequest[] createRequest(ResponseBuilder rb, String[] shards)
{
  ShardRequest sreq = new ShardRequest();
  sreq.shards = shards;
  sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS;
  sreq.params = new ModifiableSolrParams(rb.req.getParams());

  // If group.format=simple group.offset doesn't make sense
  Grouping.Format responseFormat = rb.getGroupingSpec().getResponseFormat();
  if (responseFormat == Grouping.Format.simple || rb.getGroupingSpec().isMain()) {
    sreq.params.remove(GroupParams.GROUP_OFFSET);
  }

  sreq.params.remove(ShardParams.SHARDS);

  // set the start (offset) to 0 for each shard request so we can properly merge
  // results from the start.
  if (rb.shards_start > -1) {
    // if the client set shards.start set this explicitly
    sreq.params.set(CommonParams.START, rb.shards_start);
  } else {
    sreq.params.set(CommonParams.START, "0");
  }
  if (rb.shards_rows > -1) {
    // if the client set shards.rows set this explicity
    sreq.params.set(CommonParams.ROWS, rb.shards_rows);
  } else {
    sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
  }

  sreq.params.set(GroupParams.GROUP_DISTRIBUTED_SECOND, "true");
  for (Map.Entry<String, Collection<SearchGroup<BytesRef>>> entry : rb.mergedSearchGroups.entrySet()) {
    for (SearchGroup<BytesRef> searchGroup : entry.getValue()) {
      String groupValue;
      if (searchGroup.groupValue != null) {
        String rawGroupValue = searchGroup.groupValue.utf8ToString();
        FieldType fieldType = rb.req.getSearcher().getSchema().getField(entry.getKey()).getType();
        groupValue = fieldType.indexedToReadable(rawGroupValue);
      } else {
        groupValue = GROUP_NULL_VALUE;
      }
      sreq.params.add(GroupParams.GROUP_DISTRIBUTED_TOPGROUPS_PREFIX + entry.getKey(), groupValue);
    }
  }

  if ((rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0 || rb.getSortSpec().includesScore()) {
    sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName() + ",score");
  } else {
    sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName());
  }
  
  int origTimeAllowed = sreq.params.getInt(CommonParams.TIME_ALLOWED, -1);
  if (origTimeAllowed > 0) {
    sreq.params.set(CommonParams.TIME_ALLOWED, Math.max(1,origTimeAllowed - rb.firstPhaseElapsedTime));
  }

  return new ShardRequest[] {sreq};
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:59,代码来源:TopGroupsShardRequestFactory.java

示例7: prepareGrouping

import org.apache.solr.search.Grouping; //导入依赖的package包/类
private void prepareGrouping(ResponseBuilder rb) throws IOException {

    SolrQueryRequest req = rb.req;
    SolrParams params = req.getParams();

    if (null != rb.getCursorMark()) {
      // It's hard to imagine, conceptually, what it would mean to combine
      // grouping with a cursor - so for now we just don't allow the combination at all
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can not use Grouping with " + 
                              CursorMarkParams.CURSOR_MARK_PARAM);
    }
 
    SolrIndexSearcher.QueryCommand cmd = rb.getQueryCommand();
    SolrIndexSearcher searcher = rb.req.getSearcher();
    GroupingSpecification groupingSpec = new GroupingSpecification();
    rb.setGroupingSpec(groupingSpec);

    //TODO: move weighting of sort
    Sort groupSort = searcher.weightSort(cmd.getSort());
    if (groupSort == null) {
      groupSort = Sort.RELEVANCE;
    }

    // groupSort defaults to sort
    String groupSortStr = params.get(GroupParams.GROUP_SORT);
    //TODO: move weighting of sort
    Sort sortWithinGroup = groupSortStr == null ?  groupSort : searcher.weightSort(QueryParsing.parseSortSpec(groupSortStr, req).getSort());
    if (sortWithinGroup == null) {
      sortWithinGroup = Sort.RELEVANCE;
    }

    groupingSpec.setSortWithinGroup(sortWithinGroup);
    groupingSpec.setGroupSort(groupSort);

    String formatStr = params.get(GroupParams.GROUP_FORMAT, Grouping.Format.grouped.name());
    Grouping.Format responseFormat;
    try {
       responseFormat = Grouping.Format.valueOf(formatStr);
    } catch (IllegalArgumentException e) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, String.format(Locale.ROOT, "Illegal %s parameter", GroupParams.GROUP_FORMAT));
    }
    groupingSpec.setResponseFormat(responseFormat);

    groupingSpec.setFields(params.getParams(GroupParams.GROUP_FIELD));
    groupingSpec.setQueries(params.getParams(GroupParams.GROUP_QUERY));
    groupingSpec.setFunctions(params.getParams(GroupParams.GROUP_FUNC));
    groupingSpec.setGroupOffset(params.getInt(GroupParams.GROUP_OFFSET, 0));
    groupingSpec.setGroupLimit(params.getInt(GroupParams.GROUP_LIMIT, 1));
    groupingSpec.setOffset(rb.getSortSpec().getOffset());
    groupingSpec.setLimit(rb.getSortSpec().getCount());
    groupingSpec.setIncludeGroupCount(params.getBool(GroupParams.GROUP_TOTAL_COUNT, false));
    groupingSpec.setMain(params.getBool(GroupParams.GROUP_MAIN, false));
    groupingSpec.setNeedScore((cmd.getFlags() & SolrIndexSearcher.GET_SCORES) != 0);
    groupingSpec.setTruncateGroups(params.getBool(GroupParams.GROUP_TRUNCATE, false));
  }
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:56,代码来源:QueryComponent.java


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