@Override protected void doAssertLuceneQuery(FieldMaskingSpanQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException { String fieldInQuery = queryBuilder.fieldName(); MappedFieldType fieldType = context.getQueryShardContext().fieldMapper(fieldInQuery); if (fieldType != null) { fieldInQuery = fieldType.name(); } assertThat(query, instanceOf(FieldMaskingSpanQuery.class)); FieldMaskingSpanQuery fieldMaskingSpanQuery = (FieldMaskingSpanQuery) query; assertThat(fieldMaskingSpanQuery.getField(), equalTo(fieldInQuery)); assertThat(fieldMaskingSpanQuery.getMaskedQuery(), equalTo(queryBuilder.innerQuery().toQuery(context.getQueryShardContext()))); }
private static void searchForColoredFox(IndexSearcher searcher) throws IOException { final SpanQuery anyColor = new SpanTermQuery(new Term(COLOR_FIELD, ANY_ANNOTATION_TERM)); final SpanQuery colorAsText = new FieldMaskingSpanQuery(anyColor, TEXT_FIELD); final SpanQuery fox = new SpanTermQuery(new Term(TEXT_FIELD, "fox")); final SpanQuery coloredFox = new SpanNearQuery(new SpanQuery[] { colorAsText, fox }, 0, true); search(searcher, coloredFox); }
private static void searchForRedAnimal(IndexSearcher searcher) throws IOException { final SpanQuery red = new SpanTermQuery(new Term(COLOR_FIELD, "red")); final SpanQuery redColorAsAnimal = new FieldMaskingSpanQuery(red, ANIMAL_FIELD); final SpanQuery anyAnimal = new SpanTermQuery(new Term(ANIMAL_FIELD, AnyAnnotationTokenFilter.ANY_ANNOTATION_TERM)); final SpanQuery redAnimals = new SpanNearQuery(new SpanQuery[] { redColorAsAnimal, anyAnimal }, 0, true); search(searcher, redAnimals); }
private static void searchForColoredFox(IndexSearcher searcher) throws IOException { final SpanQuery anyColor = new MultiPositionSpanTermQuery(new Term(COLOR_FIELD, ANY_ANNOTATION_TERM)); final SpanQuery colorAsText = new FieldMaskingSpanQuery(anyColor, TEXT_FIELD); final SpanQuery fox = new SpanTermQuery(new Term(TEXT_FIELD, "fox")); final SpanQuery coloredFox = new SpanNearQuery(new SpanQuery[] { colorAsText, fox }, 0, true); search(searcher, coloredFox); }
private static void searchForBrownFox(IndexSearcher searcher) throws IOException { final SpanQuery brown = new SpanTermQuery(new Term(COLOR_FIELD, "brown")); final SpanQuery brownText = new FieldMaskingSpanQuery(brown, TEXT_FIELD); final SpanQuery fox = new SpanTermQuery(new Term(TEXT_FIELD, "fox")); search(searcher, new SpanNearQuery(new SpanQuery[] { brownText, fox }, 1, true)); }
private static void searchForBrownFox(IndexSearcher searcher) throws IOException { final SpanQuery brown = new SpanTermQuery(new Term(COLOR_FIELD, "brown")); final SpanQuery brownText = new FieldMaskingSpanQuery(brown, TEXT_FIELD); final SpanQuery fox = new SpanTermQuery(new Term(TEXT_FIELD, "fox")); search(searcher, new SpanNearQuery(new SpanQuery[] { brownText, fox }, 0, true)); }