當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。