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


Java NumericRangeQuery类代码示例

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


NumericRangeQuery类属于org.apache.lucene.search包,在下文中一共展示了NumericRangeQuery类的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: search

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
@Override
public Collection<IndexedItem> search(IndexSearcher searcher) throws IOException
{
	BooleanQuery overall = new BooleanQuery();
	BooleanQuery collections = new BooleanQuery();
	for( Institution inst : institutions )
	{
		collections.add(
			new TermQuery(new Term(FreeTextQuery.FIELD_INSTITUTION, Long.toString(inst.getUniqueId()))),
			Occur.SHOULD);
	}
	overall.add(collections, Occur.MUST);
	overall.add(NumericRangeQuery.newLongRange(FreeTextQuery.FIELD_ID_RANGEABLE, firstId, lastId, true, true),
		Occur.MUST);
	searcher.search(overall, compareDates);
	return compareDates.getModifiedDocs();
}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:ItemSyncer.java

示例4: delDoucmentFromIndex

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
@Override
public void delDoucmentFromIndex(List<Integer> appIds) throws IOException {
    synchronized (lock) {
        logger.info("Before deleting history .Search's indexWriter has numDos: {}", indexWriter.numDocs());
        if (CollectionUtils.isEmpty(appIds)) {
            return;
        }
        logger.info("prepare delete ids:{}", appIds);

        NumericRangeQuery<Integer> idQuery = null;
        for (Integer id : appIds) {
            idQuery = NumericRangeQuery.newIntRange(LuceneFieldCollection.ColumnName.ID.getName(), id, id, true,
                    true);
            indexWriter.deleteDocuments(idQuery);
        }
        indexWriter.commit();
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:19,代码来源:QuickTipsIndexUpdaterImpl.java

示例5: prefixSearch

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
@Override
public ScoreDoc[] prefixSearch(String keywords) throws IOException {
    if (StringUtils.isEmpty(keywords) || keywords.length() > appConfig.getKeywordMaxLength()) {
        logger.error("empty keywords or over-length! {}", keywords);
        return null;
    }
    Sort sort = new Sort(new SortField("downloadRank", SortField.INT, true));

    Term nameFldTerm = new Term(fieldName, keywords);
    PrefixQuery nameFldQuery = new PrefixQuery(nameFldTerm);

    NumericRangeQuery<Integer> catalogQuery = NumericRangeQuery.newIntRange("catalog",
            (int) EnumCatalog.SOFT.getCatalog(), (int) EnumCatalog.GAME.getCatalog(), true, true);
    BooleanQuery booleanQuery = new BooleanQuery();
    booleanQuery.add(catalogQuery, Occur.MUST);
    booleanQuery.add(nameFldQuery, Occur.MUST);

    TopDocs topDocs = quickTipsSearcher.search(booleanQuery, appConfig.getQuickTipsNum() * 2, sort);
    ScoreDoc[] docs = topDocs.scoreDocs;
    return docs;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:22,代码来源:QuickTipsServiceImpl.java

示例6: prefixSearch

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
@Override
public ScoreDoc[] prefixSearch(String q) throws IOException {
    if (StringUtils.isEmpty(q) || q.length() > appConfig.getKeywordMaxLength()) {
        logger.error("empty keywords or over-length! {}", q);
        return null;
    }

    final TopDocs[] rstTopDocs = new TopDocs[2];
    final Query nameFldQuery = new PrefixQuery(new Term(NAME.getName(), q));
    rstTopDocs[0] = indexSearcher.search(nameFldQuery, appConfig.getQuickTipsNum() * 2, sort);

    final Query downLoadRankQuery = NumericRangeQuery.newIntRange(DOWNOLOAD_RANK.getName(), MIN_DOWNLOAD_RANK,
            Integer.MAX_VALUE, true, false);
    // 从下载量最高的1000条记录中,再过滤符合关键字的记录
    rstTopDocs[1] = indexSearcher.search(downLoadRankQuery, MAX_TOP, sort);
    TopDocs rst = TopDocsUtil.mergeDuplicateDocId(TopDocs.merge(sort, MAX_TOP + appConfig.getQuickTipsNum() * 2,
            rstTopDocs));
    if (rst != null) {
        return rst.scoreDocs;
    }
    return null;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:23,代码来源:QuickTipsService1Impl.java

示例7: prefixSearch

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
@Override
public ScoreDoc[] prefixSearch(String q) throws IOException {
    if (StringUtils.isEmpty(q) || q.length() > appConfig.getKeywordMaxLength()) {
        logger.error("empty keywords or over-length! {}", q);
        return null;
    }
    
    final TopDocs[] rstTopDocs = new TopDocs[2];
    final Query nameFldQuery = new PrefixQuery(new Term(NAME.getName(), q));
    rstTopDocs[0] = indexSearcher.search(nameFldQuery, appConfig.getQuickTipsNum() * 2, sort);

    final Query downLoadRankQuery = NumericRangeQuery.newIntRange(DOWNOLOAD_RANK.getName(), MIN_DOWNLOAD_RANK, Integer.MAX_VALUE, true, false);
    //从下载量最高的1000条记录中,再过滤符合关键字的记录
    rstTopDocs[1] = indexSearcher.search(downLoadRankQuery, MAX_TOP, sort);
    TopDocs rst = TopDocsUtil.mergeDuplicateDocId(TopDocs.merge(sort, MAX_TOP + appConfig.getQuickTipsNum() * 2, rstTopDocs));
    if(rst != null) {
        return rst.scoreDocs;
    }
    return null;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:21,代码来源:QuickTipsServiceImpl.java

示例8: addQueryTerms

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
@Override
public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) {
	try {
		ZipscriptQueryParams queryParams = params.getExtensionData(ZipscriptQueryParams.ZIPSCRIPTQUERYPARAMS);
		if (queryParams.getMinPresent() != null || queryParams.getMaxPresent() != null) {
			Query presentQuery = NumericRangeQuery.newIntRange("present",
					queryParams.getMinPresent(), queryParams.getMaxPresent(), true, true);
			query.add(presentQuery, Occur.MUST);
		}
		if (queryParams.getMinMissing() != null || queryParams.getMaxMissing() != null) {
			Query missingQuery = NumericRangeQuery.newIntRange("missing",
					queryParams.getMinMissing(), queryParams.getMaxMissing(), true, true);
			query.add(missingQuery, Occur.MUST);
		}
		if (queryParams.getMinPercent() != null || queryParams.getMaxPercent() != null) {
			Query percentQuery = NumericRangeQuery.newIntRange("percent",
					queryParams.getMinPercent(), queryParams.getMaxPercent(), true, true);
			query.add(percentQuery, Occur.MUST);
		}
	} catch (KeyNotFoundException e) {
		// No MP3 terms to include, return without amending query
	}
}
 
开发者ID:drftpd-ng,项目名称:drftpd3,代码行数:24,代码来源:ZipscriptQueryExtension.java

示例9: sortNumeric

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
/**
 * Sort the results of a numeric range query if the query in this context
 * is a {@link NumericRangeQuery}, see {@link #numericRange(String, Number, Number)},
 * Otherwise an {@link IllegalStateException} will be thrown.
 *
 * @param key the key to sort on.
 * @param reversed if the sort order should be reversed or not. {@code true}
 * for lowest first (ascending), {@code false} for highest first (descending)
 * @return a QueryContext with sorting by numeric value.
 */
public QueryContext sortNumeric( String key, boolean reversed )
{
    if ( !( queryOrQueryObject instanceof NumericRangeQuery ) )
    {
        throw new IllegalStateException( "Not a numeric range query" );
    }

    Number number = ((NumericRangeQuery)queryOrQueryObject).getMin();
    number = number != null ? number : ((NumericRangeQuery)queryOrQueryObject).getMax();
    SortField.Type fieldType = SortField.Type.INT;
    if ( number instanceof Long )
    {
        fieldType = SortField.Type.LONG;
    }
    else if ( number instanceof Float )
    {
        fieldType = SortField.Type.FLOAT;
    }
    else if ( number instanceof Double )
    {
        fieldType = SortField.Type.DOUBLE;
    }
    sort( new Sort( new SortedNumericSortField( key, fieldType, reversed ) ) );
    return this;
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:36,代码来源:QueryContext.java

示例10: 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

示例11: testNumericValues

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
private void testNumericValues( Index<Node> index )
{
    Node node10 = graphDb.createNode();
    Node node6 = graphDb.createNode();
    Node node31 = graphDb.createNode();

    String key = "key";
    index.add( node10, key, numeric( 10 ) );
    index.add( node6, key, numeric( 6 ) );
    index.add( node31, key, numeric( 31 ) );

    for ( int i = 0; i < 2; i++ )
    {
        assertThat( index.query( NumericRangeQuery.newIntRange( key, 4, 40, true, true ) ), contains( node10, node6, node31 ) );
        assertThat( index.query( NumericRangeQuery.newIntRange( key, 6, 15, true, true ) ), contains( node10, node6 ) );
        assertThat( index.query( NumericRangeQuery.newIntRange( key, 6, 15, false, true ) ), contains( node10 ) );
        restartTx();
    }

    index.remove( node6, key, numeric( 6 ) );
    assertThat( index.query( NumericRangeQuery.newIntRange( key, 4, 40, true, true ) ), contains( node10, node31 ) );
    restartTx();
    assertThat( index.query( NumericRangeQuery.newIntRange( key, 4, 40, true, true ) ), contains( node10, node31 ) );
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:25,代码来源:TestLuceneIndex.java

示例12: 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

示例13: extractPromotionalProducts

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
public List<Products> extractPromotionalProducts() {

        FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(
                em );

        org.apache.lucene.search.Query query = NumericRangeQuery.newDoubleRange( "old_price" , 0.0d ,
                                                                                 1000d , false ,
                                                                                 true );
        FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery( query ,
                                                                                 Products.class );
        Sort sort = new Sort( new SortField( "price" , SortField.DOUBLE ) );
        fullTextQuery.setSort( sort );

        //fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
        List results = fullTextQuery.getResultList();

        return results;
    }
 
开发者ID:juliocnsouzadev,项目名称:omg_mongodb,代码行数:19,代码来源:EShopBean.java

示例14: 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

示例15: makeEquals

import org.apache.lucene.search.NumericRangeQuery; //导入依赖的package包/类
/**
 * Constructs a query for documents that are equal to the 
 * input time period.
 * @return the query
 */
private Query makeEquals() {
  
  /**
   * one determinate and boundaries are equal
   */
  int nStep = this.precisionStep;
  String fSMeta = this.summaryMetaFieldName;
  String fLower = this.getLowerFieldName(0);
  String fUpper = this.getUpperFieldName(0);
  
  String sMeta = "is1determinate";
  Query qIs1Determinate = new TermQuery(new Term(fSMeta,sMeta));
  Query qDocLowerEq = NumericRangeQuery.newLongRange(
        fLower,nStep,queryLower,queryLower,true,true);
  Query qDocUpperEq = NumericRangeQuery.newLongRange(
        fUpper,nStep,queryUpper,queryUpper,true,true);
  
  BooleanQuery bq = new BooleanQuery();
  bq.add(qIs1Determinate,BooleanClause.Occur.MUST);
  bq.add(qDocLowerEq,BooleanClause.Occur.MUST);
  bq.add(qDocUpperEq,BooleanClause.Occur.MUST);
  return bq;
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:29,代码来源:TimeperiodClauseAdapter.java


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