• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FieldCacheRangeFilter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FieldCacheRangeFilter类属于org.apache.lucene.search包,在下文中一共展示了FieldCacheRangeFilter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getRangeQuery

import org.apache.lucene.search.FieldCacheRangeFilter; //导入依赖的package包/类
@Override
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  String f = field.getName();
  BytesRef low = part1 == null ? null : getCollationKey(f, part1);
  BytesRef high = part2 == null ? null : getCollationKey(f, part2);
  if (!field.indexed() && field.hasDocValues()) {
    if (field.multiValued()) {
        return new ConstantScoreQuery(DocTermOrdsRangeFilter.newBytesRefRange(
            field.getName(), low, high, minInclusive, maxInclusive));
      } else {
        return new ConstantScoreQuery(FieldCacheRangeFilter.newBytesRefRange(
            field.getName(), low, high, minInclusive, maxInclusive));
      } 
  } else {
    return new TermRangeQuery(field.getName(), low, high, minInclusive, maxInclusive);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:ICUCollationField.java


示例2: testRanges

import org.apache.lucene.search.FieldCacheRangeFilter; //导入依赖的package包/类
public void testRanges() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  Field field = newField("field", "", StringField.TYPE_STORED);
  Collator collator = Collator.getInstance(); // uses -Dtests.locale
  if (random().nextBoolean()) {
    collator.setStrength(Collator.PRIMARY);
  }
  ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", collator);
  doc.add(field);
  doc.add(collationField);
  
  int numDocs = atLeast(500);
  for (int i = 0; i < numDocs; i++) {
    String value = TestUtil.randomSimpleString(random());
    field.setStringValue(value);
    collationField.setStringValue(value);
    iw.addDocument(doc);
  }
  
  IndexReader ir = iw.getReader();
  iw.close();
  IndexSearcher is = newSearcher(ir);
  
  int numChecks = atLeast(100);
  for (int i = 0; i < numChecks; i++) {
    String start = TestUtil.randomSimpleString(random());
    String end = TestUtil.randomSimpleString(random());
    BytesRef lowerVal = new BytesRef(collator.getCollationKey(start).toByteArray());
    BytesRef upperVal = new BytesRef(collator.getCollationKey(end).toByteArray());
    Query query = new ConstantScoreQuery(FieldCacheRangeFilter.newBytesRefRange("collated", lowerVal, upperVal, true, true));
    doTestRanges(is, start, end, query, collator);
  }
  
  ir.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:TestICUCollationDocValuesField.java


示例3: getRangeQuery

import org.apache.lucene.search.FieldCacheRangeFilter; //导入依赖的package包/类
/**
 * Returns a Query instance for doing range searches on this field type. {@link org.apache.solr.search.SolrQueryParser}
 * currently passes part1 and part2 as null if they are '*' respectively. minInclusive and maxInclusive are both true
 * currently by SolrQueryParser but that may change in the future. Also, other QueryParser implementations may have
 * different semantics.
 * <p/>
 * Sub-classes should override this method to provide their own range query implementation. They should strive to
 * handle nulls in part1 and/or part2 as well as unequal minInclusive and maxInclusive parameters gracefully.
 *
 * @param parser       the {@link org.apache.solr.search.QParser} calling the method
 * @param field        the schema field
 * @param part1        the lower boundary of the range, nulls are allowed.
 * @param part2        the upper boundary of the range, nulls are allowed
 * @param minInclusive whether the minimum of the range is inclusive or not
 * @param maxInclusive whether the maximum of the range is inclusive or not
 *  @return a Query instance to perform range search according to given parameters
 *
 */
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  // TODO: change these all to use readableToIndexed/bytes instead (e.g. for unicode collation)
  if (field.hasDocValues() && !field.indexed()) {
    if (field.multiValued()) {
      return new ConstantScoreQuery(DocTermOrdsRangeFilter.newBytesRefRange(
          field.getName(),
          part1 == null ? null : new BytesRef(toInternal(part1)),
          part2 == null ? null : new BytesRef(toInternal(part2)),
          minInclusive, maxInclusive));
    } else {
      return new ConstantScoreQuery(FieldCacheRangeFilter.newStringRange(
          field.getName(), 
          part1 == null ? null : toInternal(part1),
          part2 == null ? null : toInternal(part2),
          minInclusive, maxInclusive));
    }
  } else {
    MultiTermQuery rangeQuery = TermRangeQuery.newStringRange(
          field.getName(),
          part1 == null ? null : toInternal(part1),
          part2 == null ? null : toInternal(part2),
          minInclusive, maxInclusive);
    rangeQuery.setRewriteMethod(getRewriteMethod(parser, field));
    return rangeQuery;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:45,代码来源:FieldType.java


示例4: testRanges

import org.apache.lucene.search.FieldCacheRangeFilter; //导入依赖的package包/类
public void testRanges() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  Field field = newField("field", "", StringField.TYPE_STORED);
  Collator collator = Collator.getInstance(); // uses -Dtests.locale
  if (random().nextBoolean()) {
    collator.setStrength(Collator.PRIMARY);
  }
  ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", collator);
  doc.add(field);
  doc.add(collationField);
  
  int numDocs = atLeast(500);
  for (int i = 0; i < numDocs; i++) {
    String value = _TestUtil.randomSimpleString(random());
    field.setStringValue(value);
    collationField.setStringValue(value);
    iw.addDocument(doc);
  }
  
  IndexReader ir = iw.getReader();
  iw.close();
  IndexSearcher is = newSearcher(ir);
  
  int numChecks = atLeast(100);
  for (int i = 0; i < numChecks; i++) {
    String start = _TestUtil.randomSimpleString(random());
    String end = _TestUtil.randomSimpleString(random());
    BytesRef lowerVal = new BytesRef(collator.getCollationKey(start).toByteArray());
    BytesRef upperVal = new BytesRef(collator.getCollationKey(end).toByteArray());
    Query query = new ConstantScoreQuery(FieldCacheRangeFilter.newBytesRefRange("collated", lowerVal, upperVal, true, true));
    doTestRanges(is, start, end, query, collator);
  }
  
  ir.close();
  dir.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:39,代码来源:TestICUCollationDocValuesField.java


示例5: getRangeQuery

import org.apache.lucene.search.FieldCacheRangeFilter; //导入依赖的package包/类
/**
 * Returns a Query instance for doing range searches on this field type. {@link org.apache.solr.search.SolrQueryParser}
 * currently passes part1 and part2 as null if they are '*' respectively. minInclusive and maxInclusive are both true
 * currently by SolrQueryParser but that may change in the future. Also, other QueryParser implementations may have
 * different semantics.
 * <p/>
 * Sub-classes should override this method to provide their own range query implementation. They should strive to
 * handle nulls in part1 and/or part2 as well as unequal minInclusive and maxInclusive parameters gracefully.
 *
 * @param field        the schema field
 * @param part1        the lower boundary of the range, nulls are allowed.
 * @param part2        the upper boundary of the range, nulls are allowed
 * @param minInclusive whether the minimum of the range is inclusive or not
 * @param maxInclusive whether the maximum of the range is inclusive or not
 *  @return a Query instance to perform range search according to given parameters
 *
 */
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  // TODO: change these all to use readableToIndexed/bytes instead (e.g. for unicode collation)
  if (field.hasDocValues() && !field.indexed()) {
    if (field.multiValued()) {
      return new ConstantScoreQuery(DocTermOrdsRangeFilter.newBytesRefRange(
          field.getName(),
          part1 == null ? null : new BytesRef(toInternal(part1)),
          part2 == null ? null : new BytesRef(toInternal(part2)),
          minInclusive, maxInclusive));
    } else {
      return new ConstantScoreQuery(FieldCacheRangeFilter.newStringRange(
          field.getName(), 
          part1 == null ? null : toInternal(part1),
          part2 == null ? null : toInternal(part2),
          minInclusive, maxInclusive));
    }
  } else {
    MultiTermQuery rangeQuery = TermRangeQuery.newStringRange(
          field.getName(),
          part1 == null ? null : toInternal(part1),
          part2 == null ? null : toInternal(part2),
          minInclusive, maxInclusive);
    rangeQuery.setRewriteMethod(getRewriteMethod(parser, field));
    return rangeQuery;
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:44,代码来源:FieldType.java


示例6: testFieldCacheRangeFilter

import org.apache.lucene.search.FieldCacheRangeFilter; //导入依赖的package包/类
public void testFieldCacheRangeFilter() throws Exception {
  Filter filter = FieldCacheRangeFilter.newStringRange("title2", "d", "j", true, true);
  assertEquals(3, TestUtil.hitCount(searcher, allBooks, filter));

  filter = FieldCacheRangeFilter.newIntRange("pubmonth",
                                             201001,
                                             201006,
                                             true,
                                             true);
  assertEquals(2, TestUtil.hitCount(searcher, allBooks, filter));
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:12,代码来源:FilterTest.java


示例7: getFilters

import org.apache.lucene.search.FieldCacheRangeFilter; //导入依赖的package包/类
/**
 * Takes a search request and prepares a Lucene Filter object, or null if no
 * filtering is required.
 */
protected Collection<Filter> getFilters(Search request)
{
	List<Filter> filters = Lists.newArrayList();

	Date[] dateRange = request.getDateRange();
	if( dateRange != null )
	{
		filters.add(createDateFilter(FreeTextQuery.FIELD_REALLASTMODIFIED, dateRange, Dates.ISO));
	}

	Collection<com.tle.common.searching.DateFilter> dateFilters = request.getDateFilters();
	if( dateFilters != null )
	{
		for( com.tle.common.searching.DateFilter dateFilter : dateFilters )
		{
			Date[] range = dateFilter.getRange();
			String indexFieldName = dateFilter.getIndexFieldName();
			if( dateFilter.getFormat() == Format.ISO )
			{
				filters.add(createDateFilter(indexFieldName, range, Dates.ISO));
			}
			else
			{
				Long start = range[0] != null ? range[0].getTime() : null;
				Long end = range[1] != null ? range[1].getTime() : null;
				filters.add(FieldCacheRangeFilter.newLongRange(indexFieldName, start, end, true, true));
			}
		}
	}

	String privPrefix = request.getPrivilegePrefix();
	String privilege = request.getPrivilege();
	if( privPrefix == null && privilege != null )
	{
		privPrefix = getPrefixForPrivilege(privilege);
	}
	if( privPrefix != null )
	{
		filters.add(new SecurityFilter(privPrefix));
	}

	List<List<Field>> must = request.getMust();
	List<List<Field>> mustNot = request.getMustNot();
	if( LOGGER.isDebugEnabled() )
	{
		LOGGER.debug("Must " + must + ": Must Not: " + mustNot + " Privilege:" + privilege);
	}
	if( must != null && !must.isEmpty() )
	{
		filters.add(new MustFilter(must));
	}
	if( mustNot != null && !mustNot.isEmpty() )
	{
		filters.add(new MustNotFilter(mustNot));
	}
	List<Field> matrixFields = request.getMatrixFields();
	if( matrixFields != null )
	{
		filters.add(new MatrixFilter(matrixFields));
	}
	filters.add(new InstitutionFilter());
	return filters;
}
 
开发者ID:equella,项目名称:Equella,代码行数:68,代码来源:ItemIndex.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SyncInfo类代码示例发布时间:2022-05-22
下一篇:
Java Extensions类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap