org.apache.lucene.search.spans.SpanWithinQuery Java Examples

The following examples show how to use org.apache.lucene.search.spans.SpanWithinQuery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSpanExtractors.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testSpanWithin() {
  Term t1 = new Term("field", "term1");
  Term t2 = new Term("field", "term22");
  Term t3 = new Term("field", "term333");
  SpanWithinQuery swq = new SpanWithinQuery(
      SpanNearQuery.newOrderedNearQuery("field")
          .addClause(new SpanTermQuery(t1))
          .addClause(new SpanTermQuery(t2))
          .build(),
      new SpanTermQuery(t3));

  assertEquals(Collections.singleton(t3), collectTerms(swq));
}
 
Example #2
Source File: MtasSpanWithinQuery.java    From mtas with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new mtas span within query.
 *
 * @param q1 the q 1
 * @param q2 the q 2
 * @param leftMinimum the left minimum
 * @param leftMaximum the left maximum
 * @param rightMinimum the right minimum
 * @param rightMaximum the right maximum
 * @param adjustBigQuery the adjust big query
 */
public MtasSpanWithinQuery(MtasSpanQuery q1, MtasSpanQuery q2,
    int leftMinimum, int leftMaximum, int rightMinimum, int rightMaximum,
    boolean adjustBigQuery) {
  super(null, null);
  bigQuery = q1;
  smallQuery = q2;
  leftBoundaryBigMinimum = leftMinimum;
  leftBoundaryBigMaximum = leftMaximum;
  rightBoundaryBigMinimum = rightMinimum;
  rightBoundaryBigMaximum = rightMaximum;
  autoAdjustBigQuery = adjustBigQuery;
  // recompute width
  Integer minimumWidth = null;
  Integer maximumWidth = null;
  if (bigQuery != null) {
    maximumWidth = bigQuery.getMaximumWidth();
    maximumWidth = (maximumWidth != null)
        ? maximumWidth + rightBoundaryBigMaximum + leftBoundaryBigMaximum
        : null;
  }
  if (smallQuery != null) {
    if (smallQuery.getMaximumWidth() != null && (maximumWidth == null
        || smallQuery.getMaximumWidth() < maximumWidth)) {
      maximumWidth = smallQuery.getMaximumWidth();
    }
    minimumWidth = smallQuery.getMinimumWidth();
  }
  setWidth(minimumWidth, maximumWidth);
  // compute field
  if (bigQuery != null && bigQuery.getField() != null) {
    field = bigQuery.getField();
  } else if (smallQuery != null && smallQuery.getField() != null) {
    field = smallQuery.getField();
  } else {
    field = null;
  }
  if (field != null) {
    baseQuery = new SpanWithinQuery(new MtasMaximumExpandSpanQuery(bigQuery,
        leftBoundaryBigMinimum, leftBoundaryBigMaximum,
        rightBoundaryBigMinimum, rightBoundaryBigMaximum), smallQuery);
  } else {
    baseQuery = null;
  }
}