Package org.apache.lucene.search

Examples of org.apache.lucene.search.NumericRangeQuery


        writeFieldVal(ut, ft, out, flags);
      }

      out.append(q.includesUpper() ? ']' : '}');
    } else if (query instanceof NumericRangeQuery) {
      NumericRangeQuery q = (NumericRangeQuery) query;
      String fname = q.getField();
      FieldType ft = writeFieldName(fname, schema, out, flags);
      out.append(q.includesMin() ? '[' : '{');
      Number lt = q.getMin();
      Number ut = q.getMax();
      if (lt == null) {
        out.append('*');
      } else {
        out.append(lt.toString());
      }

      out.append(" TO ");

      if (ut == null) {
        out.append('*');
      } else {
        out.append(ut.toString());
      }

      out.append(q.includesMax() ? ']' : '}');
    } else if (query instanceof BooleanQuery) {
      BooleanQuery q = (BooleanQuery) query;
      boolean needParens = false;

      if (q.getBoost() != 1.0 || q.getMinimumNumberShouldMatch() != 0) {
        needParens = true;
      }
      if (needParens) {
        out.append('(');
      }
      boolean first = true;
      for (BooleanClause c : q.clauses()) {
        if (!first) {
          out.append(' ');
        } else {
          first = false;
        }

        if (c.isProhibited()) {
          out.append('-');
        } else if (c.isRequired()) {
          out.append('+');
        }
        Query subQuery = c.getQuery();
        boolean wrapQuery = false;

        // TODO: may need to put parens around other types
        // of queries too, depending on future syntax.
        if (subQuery instanceof BooleanQuery) {
          wrapQuery = true;
        }

        if (wrapQuery) {
          out.append('(');
        }

        toString(subQuery, schema, out, flags);

        if (wrapQuery) {
          out.append(')');
        }
      }

      if (needParens) {
        out.append(')');
      }
      if (q.getMinimumNumberShouldMatch() > 0) {
        out.append('~');
        out.append(Integer.toString(q.getMinimumNumberShouldMatch()));
      }

    } else if (query instanceof PrefixQuery) {
      PrefixQuery q = (PrefixQuery) query;
      Term prefix = q.getPrefix();
      FieldType ft = writeFieldName(prefix.field(), schema, out, flags);
      out.append(prefix.text());
      out.append('*');
    } else if (query instanceof ConstantScorePrefixQuery) {
      ConstantScorePrefixQuery q = (ConstantScorePrefixQuery) query;
      Term prefix = q.getPrefix();
      FieldType ft = writeFieldName(prefix.field(), schema, out, flags);
      out.append(prefix.text());
      out.append('*');
    } else if (query instanceof WildcardQuery) {
      out.append(query.toString());
View Full Code Here


    }
    return o;
  }

  private Query createNumericRangeQuery() {
    NumericRangeQuery query;
    // either end of the range must have a valid value (see also HSEARCH-770)
    Object minOrMax = getNonNullMinOrMax( range );
    if ( minOrMax instanceof Double ) {
      query = NumericRangeQuery.newDoubleRange(
          getFieldName(),
View Full Code Here

    }
    return o;
  }

  private Query createNumericRangeQuery() {
    NumericRangeQuery query;
    // either end of the range must have a valid value (see also HSEARCH-770)
    Object minOrMax = getNonNullMinOrMax( range );
    if ( minOrMax instanceof Double ) {
      query = NumericRangeQuery.newDoubleRange(
          getFieldName(),
View Full Code Here

    }
    return o;
  }

  private Query createNumericRangeQuery() {
    NumericRangeQuery query;
    // either end of the range must have a valid value (see also HSEARCH-770)
    Object minOrMax = getNonNullMinOrMax( range );
    if ( minOrMax instanceof Double ) {
      query = NumericRangeQuery.newDoubleRange(
          getFieldName(),
View Full Code Here

        writeFieldVal(ut, ft, out, flags);
      }

      out.append(q.includesUpper() ? ']' : '}');
    } else if (query instanceof NumericRangeQuery) {
      NumericRangeQuery q = (NumericRangeQuery) query;
      String fname = q.getField();
      FieldType ft = writeFieldName(fname, schema, out, flags);
      out.append(q.includesMin() ? '[' : '{');
      Number lt = q.getMin();
      Number ut = q.getMax();
      if (lt == null) {
        out.append('*');
      } else {
        out.append(lt.toString());
      }

      out.append(" TO ");

      if (ut == null) {
        out.append('*');
      } else {
        out.append(ut.toString());
      }

      out.append(q.includesMax() ? ']' : '}');
    } else if (query instanceof BooleanQuery) {
      BooleanQuery q = (BooleanQuery) query;
      boolean needParens = false;

      if (q.getBoost() != 1.0 || q.getMinimumNumberShouldMatch() != 0) {
        needParens = true;
      }
      if (needParens) {
        out.append('(');
      }
      boolean first = true;
      for (BooleanClause c : q.clauses()) {
        if (!first) {
          out.append(' ');
        } else {
          first = false;
        }

        if (c.isProhibited()) {
          out.append('-');
        } else if (c.isRequired()) {
          out.append('+');
        }
        Query subQuery = c.getQuery();
        boolean wrapQuery = false;

        // TODO: may need to put parens around other types
        // of queries too, depending on future syntax.
        if (subQuery instanceof BooleanQuery) {
          wrapQuery = true;
        }

        if (wrapQuery) {
          out.append('(');
        }

        toString(subQuery, schema, out, flags);

        if (wrapQuery) {
          out.append(')');
        }
      }

      if (needParens) {
        out.append(')');
      }
      if (q.getMinimumNumberShouldMatch() > 0) {
        out.append('~');
        out.append(Integer.toString(q.getMinimumNumberShouldMatch()));
      }

    } else if (query instanceof PrefixQuery) {
      PrefixQuery q = (PrefixQuery) query;
      Term prefix = q.getPrefix();
      FieldType ft = writeFieldName(prefix.field(), schema, out, flags);
      out.append(prefix.text());
      out.append('*');
    } else if (query instanceof ConstantScorePrefixQuery) {
      ConstantScorePrefixQuery q = (ConstantScorePrefixQuery) query;
      Term prefix = q.getPrefix();
      FieldType ft = writeFieldName(prefix.field(), schema, out, flags);
      out.append(prefix.text());
      out.append('*');
    } else if (query instanceof WildcardQuery) {
      out.append(query.toString());
View Full Code Here

    }
    return o;
  }

  private Query createNumericRangeQuery() {
    NumericRangeQuery query;
    // either end of the range must have a valid value (see also HSEARCH-770)
    Object minOrMax = getNonNullMinOrMax( range );
    if ( minOrMax instanceof Double ) {
      query = NumericRangeQuery.newDoubleRange(
          getFieldName(),
View Full Code Here

    }
    return o;
  }

  private Query createNumericRangeQuery() {
    NumericRangeQuery query;
    // either end of the range must have a valid value (see also HSEARCH-770)
    Object minOrMax = getNonNullMinOrMax( range );
    if ( minOrMax instanceof Double ) {
      query = NumericRangeQuery.newDoubleRange(
          getFieldName(),
View Full Code Here

    }
    return o;
  }

  private Query createNumericRangeQuery() {
    NumericRangeQuery query;
    if ( range.getMin() instanceof Double ) {
      query = NumericRangeQuery.newDoubleRange(
          getFieldName(),
          (Double) range.getMin(),
          (Double) range.getMax(),
View Full Code Here

      // log.info(doc);
    }
    Query query = null;
    String key = "ipse".toLowerCase();
    if(false) {
      NumericRangeQuery q = NumericRangeQuery.newIntRange("userCount", Integer.valueOf(30), Integer.valueOf(10000), true, true);
      //q = NumericRangeQuery.newLongRange("userCount", Long.valueOf(30), Long.valueOf(10000), true, true);
      query = q;
    } else {
      TermQuery q1 = new TermQuery(new Term("contents", key));
      TermRangeQuery q2 = new TermRangeQuery("userCount", NumericUtils.longToPrefixCoded(30), NumericUtils.longToPrefixCoded(300), false, false);
      BooleanQuery q = new BooleanQuery();
      //q.add(q1, BooleanClause.Occur.MUST);
      q.add(q2, BooleanClause.Occur.MUST);
      query = q;
    }
    log.info(query);
    if (true) {
      TopDocs docs = searcher.search(query, Integer.MAX_VALUE);
View Full Code Here

    }
    return o;
  }

  private Query createNumericRangeQuery() {
    NumericRangeQuery query;
    // either end of the range must have a valid value (see also HSEARCH-770)
    Object minOrMax = getNonNullMinOrMax( range );
    if ( minOrMax instanceof Double ) {
      query = NumericRangeQuery.newDoubleRange(
          getFieldName(),
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.NumericRangeQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.