Example usage for org.apache.lucene.document LongPoint newExactQuery

List of usage examples for org.apache.lucene.document LongPoint newExactQuery

Introduction

In this page you can find the example usage for org.apache.lucene.document LongPoint newExactQuery.

Prototype

public static Query newExactQuery(String field, long value) 

Source Link

Document

Create a query for matching an exact long value.

Usage

From source file:com.b2international.index.lucene.LongIndexField.java

License:Apache License

@Override
public Query toQuery(Long value) {
    return LongPoint.newExactQuery(fieldName(), value);
}

From source file:org.alfresco.solr.tracker.DistributedAlfrescoSolrTrackerStateTest.java

License:Open Source License

/**
 * Creates and indexes a transaction with a certain number of nodes.
 *
 * @param howManyTestNodes how many nodes we want to index.
 * @param acl the related ACL.//w  w  w .  ja  va  2 s.  c  om
 * @param sampleTextContent a sample text content that will be used to assert nodes have been actually indexed.
 */
private static void createAndIndexTransactionWithSomeNodes(int howManyTestNodes, Acl acl,
        String sampleTextContent) {
    try {
        Transaction txn = getTransaction(0, howManyTestNodes);
        Map.Entry<List<Node>, List<NodeMetaData>> data = TestDataProvider.nSampleNodesWithSampleContent(acl,
                txn, howManyTestNodes);

        indexTransaction(txn, data.getKey(), data.getValue(),
                range(0, howManyTestNodes).mapToObj(index -> sampleTextContent).collect(Collectors.toList()));

        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        builder.add(
                new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_SOLR4_ID, "TRACKER!STATE!TX")),
                        BooleanClause.Occur.MUST));
        builder.add(new BooleanClause(LongPoint.newExactQuery(QueryConstants.FIELD_S_TXID, txn.getId()),
                BooleanClause.Occur.MUST));
        BooleanQuery waitForQuery = builder.build();

        waitForDocCountAllCores(waitForQuery, 1, MAX_WAIT_TIME);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}

From source file:org.apache.solr.schema.DatePointField.java

License:Apache License

@Override
protected Query getExactQuery(SchemaField field, String externalVal) {
    return LongPoint.newExactQuery(field.getName(), DateMathParser.parseMath(null, externalVal).getTime());
}

From source file:org.apache.solr.schema.LongPointField.java

License:Apache License

@Override
protected Query getExactQuery(SchemaField field, String externalVal) {
    return LongPoint.newExactQuery(field.getName(), Long.parseLong(externalVal));
}

From source file:org.elasticsearch.index.mapper.core.DateFieldTypeTests.java

License:Apache License

public void testTermQuery() {
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    String date = "2015-10-12T14:10:55";
    long instant = LegacyDateFieldMapper.Defaults.DATE_TIME_FORMATTER.parser().parseDateTime(date).getMillis();
    ft.setIndexOptions(IndexOptions.DOCS);
    assertEquals(LongPoint.newExactQuery("field", instant), ft.termQuery(date, null));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ft.termQuery(date, null));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}

From source file:org.elasticsearch.index.mapper.core.NumberFieldTypeTests.java

License:Apache License

public void testTermQuery() {
    MappedFieldType ft = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    ft.setName("field");
    ft.setIndexOptions(IndexOptions.DOCS);
    assertEquals(LongPoint.newExactQuery("field", 42), ft.termQuery("42", null));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ft.termQuery("42", null));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}

From source file:org.elasticsearch.index.mapper.core.ScaledFloatFieldTypeTests.java

License:Apache License

public void testTermQuery() {
    ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType();
    ft.setName("scaled_float");
    ft.setScalingFactor(0.1 + randomDouble() * 100);
    double value = (randomDouble() * 2 - 1) * 10000;
    long scaledValue = Math.round(value * ft.getScalingFactor());
    assertEquals(LongPoint.newExactQuery("scaled_float", scaledValue), ft.termQuery(value, null));
}

From source file:org.hibernate.search.backend.lucene.types.predicate.impl.LocalDateMatchPredicateBuilder.java

License:LGPL

@Override
protected Query doBuild(LuceneSearchPredicateContext context) {
    return LongPoint.newExactQuery(absoluteFieldPath, value);
}

From source file:org.janusgraph.diskstorage.lucene.NumericTranslationQueryParser.java

License:Apache License

private Query buildNumericQuery(final String field, final String value, Class<?> type) {
    if (AttributeUtil.isWholeNumber(type)) {
        if (isMatchAll(value)) {
            return LongPoint.newRangeQuery(field, Long.MIN_VALUE, Long.MAX_VALUE);
        } else {//  w ww  .  jav a 2s  . com
            return LongPoint.newExactQuery(field, Long.parseLong(value));
        }
    } else {
        if (isMatchAll(value)) {
            return DoublePoint.newRangeQuery(field, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
        } else {
            return DoublePoint.newExactQuery(field, Double.parseDouble(value));
        }
    }
}