コード例 #1
0
  @Override
  public DeleteResponse deleteByIds(List<String> ids) {
    if (CollectionUtil.isEmpty(ids)) {
      return new DeleteResponse();
    }

    final String idName = schema.getIdName();
    Term[] terms = new Term[ids.size()];
    int index = 0;
    for (String id : ids) {
      terms[index++] = new Term(idName, id);
    }
    try {
      if (logger.isDebugEnabled()) {
        logger.debug("deleting documents...");
      }
      indexWriter.deleteDocuments(terms);
      updateCount.addAndGet(ids.size());
      if (logger.isDebugEnabled()) {
        logger.debug("delete documents finish.");
      }
    } catch (IOException e) {
      logger.error("delete error", e);
      return new DeleteResponse(e.getMessage(), ResultCodes.COMMON_ERROR);
    }
    return new DeleteResponse();
  }
コード例 #2
0
  private Sort getSort(SearchQuery searchQuery) {
    List<FieldSort> fieldSorts = searchQuery.getFieldSorts();

    Sort sort;
    if (CollectionUtil.isEmpty(fieldSorts)) {
      sort = Sort.RELEVANCE;
    } else {
      sort = new Sort();
      SortField[] targetSorts = new SortField[fieldSorts.size()];
      int i = 0;
      for (FieldSort fieldSort : fieldSorts) {
        String name = fieldSort.getName();
        FieldInfo fieldInfo = schema.getFieldInfos().get(name);
        boolean orderOfDesc = (fieldSort.getOrder() == FieldSort.DESC);
        SortField sortField =
            new SortField(name, fieldInfo.getFieldType().getSortType(), orderOfDesc);
        targetSorts[i++] = sortField;
      }
      sort.setSort(targetSorts);
    }
    return sort;
  }