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


Java BooleanFilter类代码示例

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


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

示例1: getFilter

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
@Override
public Filter getFilter(Element e) throws ParserException {
  BooleanFilter bf = new BooleanFilter();
  NodeList nl = e.getChildNodes();

  for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node.getNodeName().equals("Clause")) {
      Element clauseElem = (Element) node;
      BooleanClause.Occur occurs = BooleanQueryBuilder.getOccursValue(clauseElem);

      Element clauseFilter = DOMUtils.getFirstChildOrFail(clauseElem);
      Filter f = factory.getFilter(clauseFilter);
      bf.add(new FilterClause(f, occurs));
    }
  }

  return bf;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:BooleanFilterBuilder.java

示例2: construct

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
@Override
protected Filter construct(LindenFilter lindenFilter, LindenConfig config) throws Exception {
  List<LindenBooleanSubFilter> booleanSubFilterList = lindenFilter.getBooleanFilter().getFilters();
  BooleanFilter booleanFilter = new BooleanFilter();
  for (LindenBooleanSubFilter booleanSubFilter : booleanSubFilterList) {
    LindenFilter subFilter = booleanSubFilter.getFilter();
    switch (booleanSubFilter.clause) {
      case MUST:
        booleanFilter.add(FilterConstructor.constructFilter(subFilter, config), BooleanClause.Occur.MUST);
        continue;
      case SHOULD:
        booleanFilter.add(FilterConstructor.constructFilter(subFilter, config), BooleanClause.Occur.SHOULD);
        continue;
      case MUST_NOT:
        booleanFilter.add(FilterConstructor.constructFilter(subFilter, config), BooleanClause.Occur.MUST_NOT);
    }
  }
  return booleanFilter;
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:20,代码来源:BooleanFilterConstructor.java

示例3: buildNewFilter

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
private Filter buildNewFilter(Query query, ConcurrentMap<String, String> filterAlias, FilterParser filterParser)
    throws ParseException {
  if (query instanceof BooleanQuery) {
    BooleanQuery booleanQuery = (BooleanQuery) query;
    BooleanFilter booleanFilter = new BooleanFilter();
    for (BooleanClause clause : booleanQuery.clauses()) {
      booleanFilter.add(buildNewFilter(clause.getQuery(), filterAlias, filterParser), clause.getOccur());
    }
    return booleanFilter;
  } else if (query instanceof TermQuery) {
    TermQuery termQuery = (TermQuery) query;
    Term term = termQuery.getTerm();
    String key = term.toString();
    String queryStr = filterAlias.get(key);
    if (queryStr == null) {
      return new QueryWrapperFilter(termQuery);
    }
    String id = getId(key);
    return new FilterCache(id, new QueryWrapperFilter(filterParser.parse(queryStr)));
  } else {
    return new QueryWrapperFilter(query);
  }
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:24,代码来源:AliasBlurFilterCache.java

示例4: construct

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
@Override
protected Filter construct(LindenFilter lindenFilter, LindenConfig config) throws Exception {
  LindenNotNullFieldFilter lindenNotNullFieldFilter = lindenFilter.getNotNullFieldFilter();

  NotNullFieldFilter notNullFieldFilter = new NotNullFieldFilter(lindenNotNullFieldFilter.getField());
  if (!lindenNotNullFieldFilter.isReverse()) {
    return notNullFieldFilter;
  }

  BooleanFilter booleanFilter = new BooleanFilter();
  booleanFilter.add(notNullFieldFilter, BooleanClause.Occur.MUST_NOT);
  return booleanFilter;
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:14,代码来源:NotNullFieldFilterConstructor.java

示例5: numericFilter

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
private static final Filter numericFilter(String key, Cmp relation, Number value) {
    switch (relation) {
        case EQUAL:
            return AttributeUtil.isWholeNumber(value) ?
                    NumericRangeFilter.newLongRange(key, value.longValue(), value.longValue(), true, true) :
                    NumericRangeFilter.newDoubleRange(key, value.doubleValue(), value.doubleValue(), true, true);
        case NOT_EQUAL:
            BooleanFilter q = new BooleanFilter();
            if (AttributeUtil.isWholeNumber(value)) {
                q.add(NumericRangeFilter.newLongRange(key, Long.MIN_VALUE, value.longValue(), true, false), BooleanClause.Occur.SHOULD);
                q.add(NumericRangeFilter.newLongRange(key, value.longValue(), Long.MAX_VALUE, false, true), BooleanClause.Occur.SHOULD);
            } else {
                q.add(NumericRangeFilter.newDoubleRange(key, Double.MIN_VALUE, value.doubleValue(), true, false), BooleanClause.Occur.SHOULD);
                q.add(NumericRangeFilter.newDoubleRange(key, value.doubleValue(), Double.MAX_VALUE, false, true), BooleanClause.Occur.SHOULD);
            }
            return q;
        case LESS_THAN:
            return (AttributeUtil.isWholeNumber(value)) ?
                    NumericRangeFilter.newLongRange(key, Long.MIN_VALUE, value.longValue(), true, false) :
                    NumericRangeFilter.newDoubleRange(key, Double.MIN_VALUE, value.doubleValue(), true, false);
        case LESS_THAN_EQUAL:
            return (AttributeUtil.isWholeNumber(value)) ?
                    NumericRangeFilter.newLongRange(key, Long.MIN_VALUE, value.longValue(), true, true) :
                    NumericRangeFilter.newDoubleRange(key, Double.MIN_VALUE, value.doubleValue(), true, true);
        case GREATER_THAN:
            return (AttributeUtil.isWholeNumber(value)) ?
                    NumericRangeFilter.newLongRange(key, value.longValue(), Long.MAX_VALUE, false, true) :
                    NumericRangeFilter.newDoubleRange(key, value.doubleValue(), Double.MAX_VALUE, false, true);
        case GREATER_THAN_EQUAL:
            return (AttributeUtil.isWholeNumber(value)) ?
                    NumericRangeFilter.newLongRange(key, value.longValue(), Long.MAX_VALUE, true, true) :
                    NumericRangeFilter.newDoubleRange(key, value.doubleValue(), Double.MAX_VALUE, true, true);
        default:
            throw new IllegalArgumentException("Unexpected relation: " + relation);
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:37,代码来源:LuceneIndex.java

示例6: convertToLuceneSearchFilter

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
@Override
public Filter convertToLuceneSearchFilter(@Nonnull UserProfileDataFilter filter) {
    final BooleanFilter result = new BooleanFilter();
    final Filter include = toFilter(filter.getIncludingGroups());
    if (include != null) {
        result.add(include, MUST);
    }
    final Filter exclude = toFilter(filter.getExcludingGroups());
    if (exclude != null) {
        result.add(exclude, MUST_NOT);
    }
    return result;
}
 
开发者ID:echocat,项目名称:adam,代码行数:14,代码来源:UserProfileDataFilterMapper.java

示例7: example1

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
@Test
    public void example1() throws Exception {
        Directory dir = FSDirectory.open(path);
        Analyzer analyzer = new StandardAnalyzer();
        IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_4, analyzer);

        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
        IndexWriter writer = new IndexWriter(dir, iwc);

        indexDocs(writer, "doc1", ImmutableMap.of("name","The laborious work of John Doe as we know it",
                                                  "city","Blumenkamp",
                                                  "location",Geoshape.point(51.687882,6.612053),
                                                  "time",1000342034
                ));

        indexDocs(writer, "doc2", ImmutableMap.of("name","Life as we know it or not",
                "city","Essen",
                "location",Geoshape.point(51.787882,6.712053),
                "time",1000342034-500
        ));

        indexDocs(writer, "doc3", ImmutableMap.of("name","Berlin - poor but sexy and a display of the extraordinary",
                "city","Berlin",
                "location",Geoshape.circle(52.509535, 13.425293, 50),
                "time",1000342034+2000
        ));
        writer.close();

        //Search
        IndexReader reader = DirectoryReader.open(FSDirectory.open(path));
        IndexSearcher searcher = new IndexSearcher(reader);
        analyzer = new StandardAnalyzer();

        //Auesee
        BooleanFilter filter = new BooleanFilter();
        //filter.add(new TermsFilter(new Term("name_txt","know")), BooleanClause.Occur.MUST);

        SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,Geoshape.circle(51.666167,6.58905,450).convert2Spatial4j());
        //filter.add(getSpatialStrategy("location").makeFilter(args), BooleanClause.Occur.MUST);

        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034,(long)1000342034,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034-100,Long.MAX_VALUE,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",Long.MIN_VALUE,(long)1000342034+300,true,true), BooleanClause.Occur.MUST);


        filter.add(new PrefixFilter(new Term("city_str","B")), BooleanClause.Occur.MUST);


        TopDocs docs = searcher.search(new MatchAllDocsQuery(), filter, MAX_RESULT);
        if (docs.totalHits>=MAX_RESULT) throw new RuntimeException("Max results exceeded: " + MAX_RESULT);

        Set<String> result = getResults(searcher,docs);
        System.out.println(result);

    }
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:56,代码来源:LuceneExample.java

示例8: getBooleanFilter

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
public BooleanFilter getBooleanFilter() {
    return booleanFilter;
}
 
开发者ID:bbejeck,项目名称:nosql-jdbc-driver,代码行数:4,代码来源:QueryParseResults.java

示例9: withBooleanFilter

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
public Builder withBooleanFilter(BooleanFilter booleanFilter) {
    this.booleanFilter = booleanFilter;
    return this;
}
 
开发者ID:bbejeck,项目名称:nosql-jdbc-driver,代码行数:5,代码来源:QueryParseResults.java

示例10: getBoundingBoxFilter

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
/** Given a latitude and longitude (in degrees) and the
 *  maximum great circle (surface of the earth) distance,
 *  returns a simple Filter bounding box to "fast match"
 *  candidates. */
public static Filter getBoundingBoxFilter(double originLat, double originLng, double maxDistanceKM) {

  // Basic bounding box geo math from
  // http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates,
  // licensed under creative commons 3.0:
  // http://creativecommons.org/licenses/by/3.0

  // TODO: maybe switch to recursive prefix tree instead
  // (in lucene/spatial)?  It should be more efficient
  // since it's a 2D trie...

  // Degrees -> Radians:
  double originLatRadians = Math.toRadians(originLat);
  double originLngRadians = Math.toRadians(originLng);

  double angle = maxDistanceKM / (SloppyMath.earthDiameter(originLat) / 2.0);

  double minLat = originLatRadians - angle;
  double maxLat = originLatRadians + angle;

  double minLng;
  double maxLng;
  if (minLat > Math.toRadians(-90) && maxLat < Math.toRadians(90)) {
    double delta = Math.asin(Math.sin(angle)/Math.cos(originLatRadians));
    minLng = originLngRadians - delta;
    if (minLng < Math.toRadians(-180)) {
      minLng += 2 * Math.PI;
    }
    maxLng = originLngRadians + delta;
    if (maxLng > Math.toRadians(180)) {
      maxLng -= 2 * Math.PI;
    }
  } else {
    // The query includes a pole!
    minLat = Math.max(minLat, Math.toRadians(-90));
    maxLat = Math.min(maxLat, Math.toRadians(90));
    minLng = Math.toRadians(-180);
    maxLng = Math.toRadians(180);
  }

  BooleanFilter f = new BooleanFilter();

  // Add latitude range filter:
  f.add(NumericRangeFilter.newDoubleRange("latitude", Math.toDegrees(minLat), Math.toDegrees(maxLat), true, true),
        BooleanClause.Occur.MUST);

  // Add longitude range filter:
  if (minLng > maxLng) {
    // The bounding box crosses the international date
    // line:
    BooleanFilter lonF = new BooleanFilter();
    lonF.add(NumericRangeFilter.newDoubleRange("longitude", Math.toDegrees(minLng), null, true, true),
             BooleanClause.Occur.SHOULD);
    lonF.add(NumericRangeFilter.newDoubleRange("longitude", null, Math.toDegrees(maxLng), true, true),
             BooleanClause.Occur.SHOULD);
    f.add(lonF, BooleanClause.Occur.MUST);
  } else {
    f.add(NumericRangeFilter.newDoubleRange("longitude", Math.toDegrees(minLng), Math.toDegrees(maxLng), true, true),
          BooleanClause.Occur.MUST);
  }

  return f;
}
 
开发者ID:europeana,项目名称:search,代码行数:68,代码来源:DistanceFacetsExample.java

示例11: example1

import org.apache.lucene.queries.BooleanFilter; //导入依赖的package包/类
@Test
    public void example1() throws Exception {
        Directory dir = FSDirectory.open(path);
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41);
        IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_41, analyzer);

        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
        IndexWriter writer = new IndexWriter(dir, iwc);

        indexDocs(writer, "doc1", ImmutableMap.of("name","The laborious work of John Doe as we know it",
                                                  "city","Blumenkamp",
                                                  "location",Geoshape.point(51.687882,6.612053),
                                                  "time",1000342034
                ));

        indexDocs(writer, "doc2", ImmutableMap.of("name","Life as we know it or not",
                "city","Essen",
                "location",Geoshape.point(51.787882,6.712053),
                "time",1000342034-500
        ));

        indexDocs(writer, "doc3", ImmutableMap.of("name","Berlin - poor but sexy and a display of the extraordinary",
                "city","Berlin",
                "location",Geoshape.circle(52.509535, 13.425293, 50),
                "time",1000342034+2000
        ));
        writer.close();

        //Search
        IndexReader reader = DirectoryReader.open(FSDirectory.open(path));
        IndexSearcher searcher = new IndexSearcher(reader);
        analyzer = new StandardAnalyzer(Version.LUCENE_41);

        //Auesee
        BooleanFilter filter = new BooleanFilter();
        //filter.add(new TermsFilter(new Term("name_txt","know")), BooleanClause.Occur.MUST);

        SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,Geoshape.circle(51.666167,6.58905,450).convert2Spatial4j());
        //filter.add(getSpatialStrategy("location").makeFilter(args), BooleanClause.Occur.MUST);

        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034,(long)1000342034,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034-100,Long.MAX_VALUE,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",Long.MIN_VALUE,(long)1000342034+300,true,true), BooleanClause.Occur.MUST);


        filter.add(new PrefixFilter(new Term("city_str","B")), BooleanClause.Occur.MUST);


        TopDocs docs = searcher.search(new MatchAllDocsQuery(), filter, MAX_RESULT);
        if (docs.totalHits>=MAX_RESULT) throw new RuntimeException("Max results exceeded: " + MAX_RESULT);

        Set<String> result = getResults(searcher,docs);
        System.out.println(result);

    }
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:56,代码来源:LuceneExample.java


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