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


Java NumericRangeQuery.newLongRange方法代码示例

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


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

示例1: getNewsOfNewsGroup

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/**
 * Returns all {@link News} of the given news group except the {@link News} with the given id.
 * @param newsGroupId the news group id
 * @param exceptId the news which should not be returned
 * @return a {@link List} with all {@link News} of the requested news group except the {@link News} with the exceptId.
 */
private List<News> getNewsOfNewsGroup(final long newsGroupId, final long exceptId) {
	final BooleanQuery query = new BooleanQuery();

	QueryUtil.addTypeConf(query, NewsIndexType.getInstance());

	final NumericRangeQuery<Long> groupQuery = NumericRangeQuery.newLongRange(
			NewsIndexType.FIELD_NEWSGROUPID, newsGroupId, newsGroupId, true, true);
	query.add(groupQuery, Occur.MUST);

	// exclude news
	query.add(new TermQuery(new Term(IIndexElement.FIELD_ID, String.valueOf(exceptId))), Occur.MUST_NOT);

	final SearchOptions options = new SearchOptions();
	options.setSort(new Sort(ESortField.PUBLISH_DATE.getSortField(ESortOrder.DESC)));

	final DocumentsSearchResult result = IndexSearch.getInstance().search(query, options);
	return NewsIndexType.docsToNews(result.getResults());
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:25,代码来源:NewsDao.java

示例2: getAmountOfNewsInNewsGroups

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/**
 * Returns the amount of {@link News} which are assigned to news groups (news group id > 0)
 * for the given {@link Query}.
 */
private int getAmountOfNewsInNewsGroups(final Query filterQuery) {
	final BooleanQuery query = new BooleanQuery();
	query.add(filterQuery, Occur.MUST);

	// get only news that are in real groups (newsGroupId > 0)
	final NumericRangeQuery<Long> newsGroupFilterQuery = NumericRangeQuery.newLongRange(
			NewsIndexType.FIELD_NEWSGROUPID, 0l, null, false, true);
	query.add(newsGroupFilterQuery, Occur.MUST);

	final SearchOptions options = new SearchOptions();
	options.setMaxResults(0); // we only want the totalHits, not the results.

	final TopDocs topDocs = IndexSearch.getInstance().getTopDocs(query, options);

	return topDocs.totalHits;
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:21,代码来源:NewsDao.java

示例3: rangeQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/**
 * Will create a {@link Query} with a query for numeric ranges, that is
 * values that have been indexed using {@link ValueContext#indexNumeric()}.
 * It will match the type of numbers supplied to the type of values that
 * are indexed in the index, f.ex. long, int, float and double.
 * If both {@code from} and {@code to} is {@code null} then it will default
 * to int.
 *
 * @param key the property key to query.
 * @param from the low end of the range (inclusive)
 * @param to the high end of the range (inclusive)
 * @param includeFrom whether or not {@code from} (the lower bound) is inclusive
 * or not.
 * @param includeTo whether or not {@code to} (the higher bound) is inclusive
 * or not.
 * @return a {@link Query} to do numeric range queries with.
 */
public static Query rangeQuery( String key, Number from, Number to,
        boolean includeFrom, boolean includeTo )
{
    if ( from instanceof Long || to instanceof Long )
    {
        return NumericRangeQuery.newLongRange( key, from != null ? from.longValue() : 0,
                to != null ? to.longValue() : Long.MAX_VALUE, includeFrom, includeTo );
    }
    else if ( from instanceof Double || to instanceof Double )
    {
        return NumericRangeQuery.newDoubleRange( key, from != null ? from.doubleValue() : 0,
                to != null ? to.doubleValue() : Double.MAX_VALUE, includeFrom, includeTo );
    }
    else if ( from instanceof Float || to instanceof Float )
    {
        return NumericRangeQuery.newFloatRange( key, from != null ? from.floatValue() : 0,
                to != null ? to.floatValue() : Float.MAX_VALUE, includeFrom, includeTo );
    }
    else
    {
        return NumericRangeQuery.newIntRange( key, from != null ? from.intValue() : 0,
                to != null ? to.intValue() : Integer.MAX_VALUE, includeFrom, includeTo );
    }
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:42,代码来源:LuceneUtil.java

示例4: getCollectionFilters

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/**
 * Set up the filters for collections - this is for searching within collections.
 * 
 * @param collection - to search within
 * @return - created filter
 * @throws ParseException
 */
private List<Filter> getCollectionFilters(InstitutionalCollection collection) throws ParseException
{
	List<Filter> filters = new LinkedList<Filter>();
	
       //isolate the collection root
	Term t = new Term("collection_root_id", NumericUtils.longToPrefixCoded(collection.getTreeRoot().getId()));
	Query subQuery = new TermQuery( t );
	filters.add(new QueryWrapperFilter(subQuery));
	
	
	//isolate the range of children
	subQuery = NumericRangeQuery.newLongRange("collection_left_value", collection.getLeftValue(), collection.getRightValue(), true, true);
	filters.add(new QueryWrapperFilter(subQuery));
    return filters;
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:23,代码来源:DefaultInstitutionalItemSearchService.java

示例5: getQueryParser

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private MultiFieldQueryParser getQueryParser() {
    MultiFieldQueryParser queryParser = new MultiFieldQueryParser(getAllDefaultSearchableFields(), analyzer) {
        @Override
        protected Query getRangeQuery(String field, String part1, String part2, boolean startInclusive,
                boolean endInclusive) throws ParseException {
            if (field != null && getIndex(field).numeric) {
                Long min = getWithDefault(part1, null);
                Long max = getWithDefault(part2, null);
                return NumericRangeQuery.newLongRange(field, min, max, true, true);
            } else if (field != null) {
                return new TermQuery(new Term(field));
            }
            return super.getRangeQuery(null, part1, part2, startInclusive, endInclusive);
        }
    };
    queryParser.setDefaultOperator(QueryParser.Operator.AND);
    queryParser.setLocale(LOCALE);
    queryParser.setAnalyzeRangeTerms(true);
    queryParser.setLowercaseExpandedTerms(true);
    return queryParser;
}
 
开发者ID:jenkinsci,项目名称:lucene-search-plugin,代码行数:22,代码来源:LuceneSearchBackend.java

示例6: makeQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected Query makeQuery(Token lower, Token upper, boolean includeLower, boolean includeUpper) {
    Long start = lower == null ? null : (Long) lower.getTokenValue();
    Long stop = upper == null ? null : (Long) upper.getTokenValue();
    if (lower != null && lower.isMinimum()) {
        start = null;
    }
    if (upper != null && upper.isMinimum()) {
        stop = null;
    }
    if (start == null && stop == null) {
        return null;
    }
    return NumericRangeQuery.newLongRange(FIELD_NAME, start, stop, includeLower, includeUpper);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:17,代码来源:TokenMapperMurmur.java

示例7: getQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  String field = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
  String lowerTerm = DOMUtils.getAttributeOrFail(e, "lowerTerm");
  String upperTerm = DOMUtils.getAttributeOrFail(e, "upperTerm");
  boolean lowerInclusive = DOMUtils.getAttribute(e, "includeLower", true);
  boolean upperInclusive = DOMUtils.getAttribute(e, "includeUpper", true);
  int precisionStep = DOMUtils.getAttribute(e, "precisionStep", NumericUtils.PRECISION_STEP_DEFAULT);

  String type = DOMUtils.getAttribute(e, "type", "int");
  try {
    Query filter;
    if (type.equalsIgnoreCase("int")) {
      filter = NumericRangeQuery.newIntRange(field, precisionStep, Integer
          .valueOf(lowerTerm), Integer.valueOf(upperTerm), lowerInclusive,
          upperInclusive);
    } else if (type.equalsIgnoreCase("long")) {
      filter = NumericRangeQuery.newLongRange(field, precisionStep, Long
          .valueOf(lowerTerm), Long.valueOf(upperTerm), lowerInclusive,
          upperInclusive);
    } else if (type.equalsIgnoreCase("double")) {
      filter = NumericRangeQuery.newDoubleRange(field, precisionStep, Double
          .valueOf(lowerTerm), Double.valueOf(upperTerm), lowerInclusive,
          upperInclusive);
    } else if (type.equalsIgnoreCase("float")) {
      filter = NumericRangeQuery.newFloatRange(field, precisionStep, Float
          .valueOf(lowerTerm), Float.valueOf(upperTerm), lowerInclusive,
          upperInclusive);
    } else {
      throw new ParserException("type attribute must be one of: [long, int, double, float]");
    }
    return filter;
  } catch (NumberFormatException nfe) {
    throw new ParserException("Could not parse lowerTerm or upperTerm into a number", nfe);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:NumericRangeQueryBuilder.java

示例8: rangeQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) {
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        lowerTerm == null ? null : parseValue(lowerTerm),
        upperTerm == null ? null : parseValue(upperTerm),
        includeLower, includeUpper);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:IpFieldMapper.java

示例9: fuzzyQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) {
    long iValue = parseValue(value);
    long iSim;
    try {
        iSim = ipToLong(fuzziness.asString());
    } catch (IllegalArgumentException e) {
        iSim = fuzziness.asLong();
    }
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        iValue - iSim,
        iValue + iSim,
        true, true);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:IpFieldMapper.java

示例10: fuzzyQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) {
    long iValue = parseValue(value);
    long iSim;
    try {
        iSim = fuzziness.asTimeValue().millis();
    } catch (Exception e) {
        // not a time format
        iSim =  fuzziness.asLong();
    }
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        iValue - iSim,
        iValue + iSim,
        true, true);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:16,代码来源:DateFieldMapper.java

示例11: rangeQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) {
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        lowerTerm == null ? null : parseLongValue(lowerTerm),
        upperTerm == null ? null : parseLongValue(upperTerm),
        includeLower, includeUpper);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:LongFieldMapper.java

示例12: fuzzyQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) {
    long iValue = parseLongValue(value);
    final long iSim = fuzziness.asLong();
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        iValue - iSim,
        iValue + iSim,
        true, true);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:LongFieldMapper.java

示例13: toRangeQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private Query toRangeQuery(RangeLong range) {
  return NumericRangeQuery.newLongRange(
      range.getField(),
      range.hasMin() ? range.getMin() : null,
      range.hasMax() ? range.getMax() : null,
      range.getMinInclusive(),
      range.getMaxInclusive());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:9,代码来源:LuceneQueryConverter.java

示例14: toTermLongQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private Query toTermLongQuery(SearchQuery.TermLong term) {
  return NumericRangeQuery.newLongRange(
    term.getField(),
    term.getValue(),
    term.getValue(),
    true,
    true);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:9,代码来源:LuceneQueryConverter.java

示例15: createIntegerRangeQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
public static Query createIntegerRangeQuery(final String field, final long min, final long max, final boolean minInclusive, final boolean maxInclusive) {
    return new Query() {
        @Override
        public org.apache.lucene.search.Query getLuceneQuery(Schema schema) {
            validateType(field, schema, JsonNode.Type.INTEGER);
            return NumericRangeQuery.newLongRange(field, min, max, minInclusive, maxInclusive);
        }
    };
}
 
开发者ID:brutusin,项目名称:flea-db,代码行数:10,代码来源:Query.java


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