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


Java NumericRangeQuery.newIntRange方法代码示例

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


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

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

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

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

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

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

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

示例7: toRangeQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private <T extends Enum<T> & HasIndex> Query toRangeQuery(String field, Set<T> set) {
  Set<Integer> indexes = Sets.newHashSet();
  for (T element : set) {
    indexes.add(element.getIndex());
  }

  BooleanQuery query = new BooleanQuery();
  int begin = -1;
  for (int i = 0; i < 31; ++i) {
    if (indexes.contains(i)) {
      if (begin == -1) {
        begin = i;
      }
    } else {
      if (begin == -1) {
        continue;
      }
      Query q = NumericRangeQuery.newIntRange(field, begin, i, true, false);
      query.add(q, Occur.SHOULD);
      begin = -1;
    }
  }

  return query;
}
 
开发者ID:nodchip,项目名称:QMAClone,代码行数:26,代码来源:FullTextSearch.java

示例8: testAnd

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
public void testAnd() throws Exception {
  TermQuery searchingBooks =
    new TermQuery(new Term("subject","search"));  //#1

  Query books2010 =                       //#2
    NumericRangeQuery.newIntRange("pubmonth", 201001,       //#2
                                  201012,                   //#2
                                  true, true);                //#2

  BooleanQuery searchingBooks2010 = new BooleanQuery();              //#3
  searchingBooks2010.add(searchingBooks, BooleanClause.Occur.MUST);  //#3
  searchingBooks2010.add(books2010, BooleanClause.Occur.MUST);       //#3

  Directory dir = TestUtil.getBookIndexDirectory();
  IndexSearcher searcher = new IndexSearcher(dir);
  TopDocs matches = searcher.search(searchingBooks2010, 10);

  assertTrue(TestUtil.hitsIncludeTitle(searcher, matches,
                               "Lucene in Action, Second Edition"));
  searcher.close();
  dir.close();
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:23,代码来源:BooleanQueryTest.java

示例9: testInclusive

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
public void testInclusive() throws Exception {
  Directory dir = TestUtil.getBookIndexDirectory();
  IndexSearcher searcher = new IndexSearcher(dir);
  // pub date of TTC was September 2006
  NumericRangeQuery query = NumericRangeQuery.newIntRange("pubmonth",
                                                          200605,
                                                          200609,
                                                          true,
                                                          true);

  TopDocs matches = searcher.search(query, 10);
  /*
  for(int i=0;i<matches.totalHits;i++) {
    LOGGER.info("match " + i + ": " + searcher.doc(matches.scoreDocs[i].doc).get("author"));
  }
  */
  assertEquals(1, matches.totalHits);
  searcher.close();
  dir.close();
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:21,代码来源:NumericRangeQueryTest.java

示例10: getRangeQuery

import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
public Query getRangeQuery(String field,
                           String part1,
                           String part2,
                           boolean inclusive)
  throws ParseException {
  TermRangeQuery query = (TermRangeQuery)
      super.getRangeQuery(field, part1, part2, inclusive);

  if ("pubmonth".equals(field)) {
    return NumericRangeQuery.newIntRange(
                "pubmonth",
                Integer.parseInt(query.getLowerTerm()),
                Integer.parseInt(query.getUpperTerm()),
                query.includesLower(),
                query.includesUpper());
  } else {
    return query;
  }
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:20,代码来源:NumericQueryParserTest.java

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

示例12: rangeQuery

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

示例13: fuzzyQuery

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

示例14: rangeQuery

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

示例15: fuzzyQuery

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


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