protected Query stringRange( Path<?> leftHandSide, String field, @Nullable Expression<?> min, @Nullable Expression<?> max, boolean minInc, boolean maxInc, QueryMetadata metadata) { if (min == null) { return new TermRangeQuery( field, null, convert(leftHandSide, max, metadata)[0], minInc, maxInc); } else if (max == null) { return new TermRangeQuery( field, convert(leftHandSide, min, metadata)[0], null, minInc, maxInc); } else { return new TermRangeQuery( field, convert(leftHandSide, min, metadata)[0], convert(leftHandSide, max, metadata)[0], minInc, maxInc); } }
/** * Factory that creates a new TermRangeQuery using Strings for term text. */ public static TermRangeQuery newStringRange(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) { BytesRef lower = lowerTerm == null ? null : new BytesRef(lowerTerm); BytesRef upper = upperTerm == null ? null : new BytesRef(upperTerm); return new TermRangeQuery(field, lower, upper, includeLower, includeUpper); }
/** * @return a lucene query. * @see org.apache.lucene.search.Query */ public org.apache.lucene.search.Query getLuceneQuery() { //Translation from Lucene 2.4. We need to check if it is actually the exact same thing to do. return new TermRangeQuery(field,start,end,includeStart,includeEnd); //return new ConstantScoreRangeQuery(field,start,end,includeStart,includeEnd); }
@Override public Query existsQuery(QueryShardContext context) { // This query is not performance sensitive, it only helps assess // quality of the data, so we may use a slow query. It shouldn't // be too slow in practice since the number of unique terms in this // field is bounded by the number of fields in the mappings. return new TermRangeQuery(name(), null, null, true, true); }
boolean includeLower = true; boolean includeUpper = true; TermRangeQuery query = new TermRangeQuery("date", lowerDate, upperDate, includeLower, includeUpper);
public String generateRSS(Path indexFile) throws CorruptIndexException, IOException { StringBuffer output = new StringBuffer(); output.append(getRSSHeaders()); IndexSearcher searcher = null; try { reader = DirectoryReader.open(FSDirectory.open(indexFile)); searcher = new IndexSearcher(reader); GregorianCalendar gc = new java.util.GregorianCalendar(TimeZone.getDefault(), Locale.getDefault()); gc.setTime(new Date()); String nowDateTime = ISO8601.format(gc); gc.add(java.util.GregorianCalendar.MINUTE, -5); String fiveMinsAgo = ISO8601.format(gc); TermRangeQuery query = new TermRangeQuery( TikaCoreProperties.CREATED.getName(), new BytesRef(fiveMinsAgo), new BytesRef(nowDateTime), true, true); TopScoreDocCollector collector = TopScoreDocCollector.create(20); searcher.search(query, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; for (int i = 0; i < hits.length; i++) { Document doc = searcher.doc(hits[i].doc); output.append(getRSSItem(doc)); } } finally { if (reader != null) reader.close(); } output.append(getRSSFooters()); return output.toString(); }
@Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) { failIfNotIndexed(); return new TermRangeQuery(name(), lowerTerm == null ? null : indexedValueForSearch(lowerTerm), upperTerm == null ? null : indexedValueForSearch(upperTerm), includeLower, includeUpper); } }
@Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) { failIfNotIndexed(); return new TermRangeQuery(name(), lowerTerm == null ? null : indexedValueForSearch(lowerTerm), upperTerm == null ? null : indexedValueForSearch(upperTerm), includeLower, includeUpper); }
@Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) { if (context.getIndexSettings().isSingleType() == false) { return new TermRangeQuery(name(), lowerTerm == null ? null : indexedValueForSearch(lowerTerm), upperTerm == null ? null : indexedValueForSearch(upperTerm), includeLower, includeUpper); } else {
private static void assertTextRange(String query, String lo, String hi) throws ParseException { Query parsed = parseFreeTextQuery(query); assertThat(parsed, CoreMatchers.instanceOf(TermRangeQuery.class)); assertEquals(new TermRangeQuery(((TermRangeQuery) parsed).getField(), lo == null ? null : new BytesRef(lo), hi == null ? null : new BytesRef(hi), true, true), parsed); } }
query = new TermRangeQuery(this.fieldName, BytesRefs.toBytesRef(from), BytesRefs.toBytesRef(to), includeLower, includeUpper);
Query handleLessThan(final String fieldName, final T value) { return new TermRangeQuery(fieldName, null, valueFactory.get(value), true, false); }
/** * Split an index based on a given primary key term * and a 'middle' term. If the middle term is present, it's * sent to dir2. */ public PKIndexSplitter(Directory input, Directory dir1, Directory dir2, Term midTerm) { this(input, dir1, dir2, new TermRangeQuery(midTerm.field(), null, midTerm.bytes(), true, false)); }
public PKIndexSplitter(Directory input, Directory dir1, Directory dir2, Term midTerm, IndexWriterConfig config1, IndexWriterConfig config2) { this(input, dir1, dir2, new TermRangeQuery(midTerm.field(), null, midTerm.bytes(), true, false), config1, config2); }
Query handleDuring(final String fieldName, final T lowerValue, final T upperValue) { return new TermRangeQuery(fieldName, valueFactory.get(lowerValue), valueFactory.get(upperValue), true, true); } }
private Query handleNotEquals(final String fieldName, final LocalDate value) { final BooleanQuery combined = new BooleanQuery(); final String indexedValue = jqlLocalDateSupport.getIndexedValue(value); combined.add(new TermRangeQuery(fieldName, null, indexedValue, true, false), BooleanClause.Occur.SHOULD); combined.add(new TermRangeQuery(fieldName, indexedValue, null, false, true), BooleanClause.Occur.SHOULD); return combined; }
private Query handleNotEquals(final String fieldName, final Date value) { final BooleanQuery combined = new BooleanQuery(); final String indexedValue = jqlDateSupport.getIndexedValue(value); combined.add(new TermRangeQuery(fieldName, null, indexedValue, true, false), BooleanClause.Occur.SHOULD); combined.add(new TermRangeQuery(fieldName, indexedValue, null, false, true), BooleanClause.Occur.SHOULD); return combined; }
public PKIndexSplitter(Directory input, Directory dir1, Directory dir2, Term midTerm, IndexWriterConfig config1, IndexWriterConfig config2) { this(input, dir1, dir2, new TermRangeQuery(midTerm.field(), null, midTerm.bytes(), true, false), config1, config2); }
/** * Factory that creates a new TermRangeQuery using Strings for term text. */ public static TermRangeQuery newStringRange(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) { BytesRef lower = lowerTerm == null ? null : new BytesRef(lowerTerm); BytesRef upper = upperTerm == null ? null : new BytesRef(upperTerm); return new TermRangeQuery(field, lower, upper, includeLower, includeUpper); }
private static Query createRangeQuery(final long min, final long max, final boolean minInclusive, final boolean maxInclusive) { return new TermRangeQuery(SystemSearchConstants.forIssueKey().getKeyIndexOrderField(), processRangeLong(min), processRangeLong(max), minInclusive, maxInclusive); }