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


Java Sort.RELEVANCE属性代码示例

本文整理汇总了Java中org.apache.lucene.search.Sort.RELEVANCE属性的典型用法代码示例。如果您正苦于以下问题:Java Sort.RELEVANCE属性的具体用法?Java Sort.RELEVANCE怎么用?Java Sort.RELEVANCE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.lucene.search.Sort的用法示例。


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

示例1: search

public Map<DocumentType, List<SearchResult>> search(String searchString) throws ParseException {
    Map<DocumentType, List<SearchResult>> resultMap = new TreeMap<DocumentType, List<SearchResult>>();
    try {
        Query query = parser.parse(searchString);
        final SecondPassGroupingCollector collector = new SecondPassGroupingCollector("documentType", searchGroups,
                Sort.RELEVANCE, null, 5, true, false, true);
        searcher.search(query, collector);
        final TopGroups groups = collector.getTopGroups(0);
        for (GroupDocs groupDocs : groups.groups) {
            DocumentType docType = DocumentType.valueOf(groupDocs.groupValue);
            List<SearchResult> results = new ArrayList<SearchResult>();
            for (ScoreDoc scoreDoc : groupDocs.scoreDocs) {
                Document doc = searcher.doc(scoreDoc.doc);
                SearchResult result = new SearchResult(
                        docType,
                        doc.get("name"),
                        doc.get("url"),
                        doc.get("className"),
                        doc.get("package"),
                        doc.get("ensemblePath"),
                        doc.get("shortDescription")
                );
                results.add(result);
            }
            resultMap.put(docType, results);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return resultMap;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:31,代码来源:IndexSearcher.java

示例2: getSort

/**
 * Converts the Tripod Sort clauses to a Lucene Sort instance.
 *
 * @param sorts the Tripod Sorts
 * @return the Lucene Sort matching the given Tripod Sorts,
 *              or the Lucene Sort for relevance order if no sorts are specified
 */
public static Sort getSort(final List<com.bbende.tripod.api.query.Sort> sorts,
                           final SortTypeFactory sortTypeFactory) {
    if (sorts == null || sorts.isEmpty()) {
        return Sort.RELEVANCE;
    } else {
        List<SortField> luceneSorts = new ArrayList<>();
        for (com.bbende.tripod.api.query.Sort sort : sorts) {
            boolean reverse = (sort.getSortOrder() == SortOrder.DESC);
            SortField.Type sortType =  sortTypeFactory.getSortType(sort.getField());
            luceneSorts.add(new SortField(sort.getField().getName(), sortType, reverse));
        }
        return new Sort(luceneSorts.toArray(new SortField[luceneSorts.size()]));
    }
}
 
开发者ID:bbende,项目名称:tripod,代码行数:21,代码来源:LuceneServiceUtil.java

示例3: testBadSort

public void testBadSort() throws Exception {
  try {
    new SortingMergePolicy(newMergePolicy(), Sort.RELEVANCE);
    fail("Didn't get expected exception");
  } catch (IllegalArgumentException e) {
    assertEquals("Cannot sort an index with a Sort that refers to the relevance score", e.getMessage());
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:TestSortingMergePolicy.java

示例4: createFirstPassCollector

/**
 * {@inheritDoc}
 */
@Override
protected Collector createFirstPassCollector() throws IOException {
  // Ok we don't want groups, but do want a total count
  if (actualGroupsToFind <= 0) {
    fallBackCollector = new TotalHitCountCollector();
    return fallBackCollector;
  }

  sort = sort == null ? Sort.RELEVANCE : sort;
  firstPass = new TermFirstPassGroupingCollector(groupBy, sort, actualGroupsToFind);
  return firstPass;
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:Grouping.java

示例5: newCollector

TopDocsCollector newCollector(Sort sort, boolean needScores) throws IOException {
  int groupDocsToCollect = getMax(groupOffset, docsPerGroup, maxDoc);
  if (sort == null || sort == Sort.RELEVANCE) {
    return TopScoreDocCollector.create(groupDocsToCollect, true);
  } else {
    return TopFieldCollector.create(searcher.weightSort(sort), groupDocsToCollect, false, needScores, needScores, true);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:Grouping.java

示例6: prepareGrouping

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,代码行数:55,代码来源:QueryComponent.java


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