当前位置: 首页>>代码示例>>Java>>正文


Java SpanTermQuery类代码示例

本文整理汇总了Java中org.apache.lucene.search.spans.SpanTermQuery的典型用法代码示例。如果您正苦于以下问题:Java SpanTermQuery类的具体用法?Java SpanTermQuery怎么用?Java SpanTermQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SpanTermQuery类属于org.apache.lucene.search.spans包,在下文中一共展示了SpanTermQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testExtractQueryMetadata_spanTermQuery

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
public void testExtractQueryMetadata_spanTermQuery() {
    // the following span queries aren't exposed in the query dsl and are therefor not supported:
    // 1) SpanPositionRangeQuery
    // 2) PayloadScoreQuery
    // 3) SpanBoostQuery

    // The following span queries can't be supported because of how these queries work:
    // 1) SpanMultiTermQueryWrapper, not supported, because there is no support for MTQ typed queries yet.
    // 2) SpanContainingQuery, is kind of range of spans and we don't know what is between the little and big terms
    // 3) SpanWithinQuery, same reason as SpanContainingQuery
    // 4) FieldMaskingSpanQuery is a tricky query so we shouldn't optimize this

    SpanTermQuery spanTermQuery1 = new SpanTermQuery(new Term("_field", "_short_term"));
    Result result = analyze(spanTermQuery1);
    assertThat(result.verified, is(true));
    assertTermsEqual(result.terms, spanTermQuery1.getTerm());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:QueryAnalyzerTests.java

示例2: flatten

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
@Override
void flatten(Query sourceQuery, IndexReader reader, Collection<Query> flatQueries, float boost) throws IOException {
    if (sourceQuery instanceof SpanTermQuery) {
        super.flatten(new TermQuery(((SpanTermQuery) sourceQuery).getTerm()), reader, flatQueries, boost);
    } else if (sourceQuery instanceof ConstantScoreQuery) {
        flatten(((ConstantScoreQuery) sourceQuery).getQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof FunctionScoreQuery) {
        flatten(((FunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof MultiPhrasePrefixQuery) {
        flatten(sourceQuery.rewrite(reader), reader, flatQueries, boost);
    } else if (sourceQuery instanceof FiltersFunctionScoreQuery) {
        flatten(((FiltersFunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof MultiPhraseQuery) {
        MultiPhraseQuery q = ((MultiPhraseQuery) sourceQuery);
        convertMultiPhraseQuery(0, new int[q.getTermArrays().size()], q, q.getTermArrays(), q.getPositions(), reader, flatQueries);
    } else if (sourceQuery instanceof BlendedTermQuery) {
        final BlendedTermQuery blendedTermQuery = (BlendedTermQuery) sourceQuery;
        flatten(blendedTermQuery.rewrite(reader), reader, flatQueries, boost);
    } else {
        super.flatten(sourceQuery, reader, flatQueries, boost);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:CustomFieldQuery.java

示例3: toFragmentQuery

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
@Override
public SpanQuery toFragmentQuery () throws QueryException {
    if (this.isNull()) {
        return null;
    }

    SpanQuery sq = subquery.retrieveNode(this.retrieveNode)
            .toFragmentQuery();
    if (sq == null)
        return null;
    if (sq instanceof SpanTermQuery) {
        if (subquery.isNegative()) {
            return sq;
        }
        else if ((startOffset == 0 || startOffset == -1)
                && (length == 1 || length == 0)) {
            // if (DEBUG) log.warn("Not SpanSubspanQuery. " +
            // "Creating only a SpanQuery for the subquery.");
            return sq;
        }
        return null;
    }

    return new SpanSubspanQuery(sq, startOffset, length, true);
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:26,代码来源:SpanSubspanQueryWrapper.java

示例4: createSpanAttributeQuery

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
private SpanAttributeQuery createSpanAttributeQuery (
        SpanQueryWrapper attrQueryWrapper) throws QueryException {
    SpanQuery sq = attrQueryWrapper.toFragmentQuery();
    if (sq != null) {
        if (sq instanceof SpanAttributeQuery)
            return (SpanAttributeQuery) sq;
        if (sq instanceof SpanTermQuery) {
            return new SpanAttributeQuery((SpanTermQuery) sq,
                    attrQueryWrapper.isNegative, true);
        }
        else {
            throw new IllegalArgumentException(
                    "The subquery is not a SpanTermQuery.");
        }
    }
    return null;
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:18,代码来源:SpanWithAttributeQueryWrapper.java

示例5: toFragmentQuery

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
@Override
public SpanQuery toFragmentQuery () throws QueryException {
    if (isNull || isEmpty)
        return null;

    SpanQuery sq = subquery.retrieveNode(this.retrieveNode)
            .toFragmentQuery();
    if (sq == null) {
        isNull = true;
        return null;
    }

    if (sq instanceof SpanTermQuery) {
        return new SpanAttributeQuery((SpanTermQuery) sq, isNegative, true);
    }
    else {
        throw new IllegalArgumentException(
                "The subquery is not a SpanTermQuery.");
    }
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:21,代码来源:SpanAttributeQueryWrapper.java

示例6: testCase3

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/** Skip to */
@Test
public void testCase3 () throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc3());
    ki.commit();

    SpanQuery sq, edq;
    edq = createQuery("s", "s:b", "s:c", 1, 1, true);

    sq = new SpanNextQuery(edq,
            new SpanTermQuery(new Term("tokens", "s:d")));

    kr = ki.search(sq, (short) 10);

    assertEquals(1, kr.getTotalResults());
    assertEquals(2, kr.getMatch(0).getLocalDocID());
    assertEquals(2, kr.getMatch(0).startPos);
    assertEquals(5, kr.getMatch(0).endPos);

}
 
开发者ID:KorAP,项目名称:Krill,代码行数:24,代码来源:TestElementDistanceIndex.java

示例7: testCase4

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/** Skip to */
@Test
public void testCase4 () throws IOException {
    //System.out.println("testcase 4");
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();

    SpanQuery sq = new SpanNextQuery(createQuery("s:d", "s:e", 1, 2, false),
            new SpanTermQuery(new Term("base", "s:f")));

    kr = ki.search(sq, (short) 10);
    assertEquals(kr.getTotalResults(), 2);
    assertEquals(2, kr.getMatch(0).getLocalDocID());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(6, kr.getMatch(0).getEndPos());
    assertEquals(3, kr.getMatch(1).getStartPos());
    assertEquals(6, kr.getMatch(1).getEndPos());
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:22,代码来源:TestUnorderedDistanceIndex.java

示例8: testCase8

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/**
 * Multiple NextSpans in the same first span position
 */
@Test
public void testCase8 () throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.commit();
    SpanQuery sq = new SpanNextQuery(
            new SpanTermQuery(new Term("base", "s:d")),
            createQuery("s:c", "s:e", 1, 2, false));
    kr = ki.search(sq, (short) 10);

    assertEquals(kr.getTotalResults(), 3);
    assertEquals(0, kr.getMatch(1).getStartPos());
    assertEquals(4, kr.getMatch(1).getEndPos());

}
 
开发者ID:KorAP,项目名称:Krill,代码行数:19,代码来源:TestUnorderedDistanceIndex.java

示例9: testCase12

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/**
 * Check Skipto focus spans
 */
@Test
public void testCase12 () throws IOException {
    ki.addDoc(TestRelationIndex.createFieldDoc0());
    ki.addDoc(TestRelationIndex.createFieldDoc1());
    ki.commit();
    SpanRelationQuery sq = new SpanRelationQuery(
            new SpanTermQuery(new Term("base", ">:xip/syntax-dep_rel")),
            true, RelationDirection.RIGHT);
    sq.setSourceClass((byte) 1);

    SpanFocusQuery sfq = new SpanFocusQuery(sq, (byte) 1);
    sfq.setSorted(false);
    SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:c"));
    SpanNextQuery snq = new SpanNextQuery(stq, sfq);

    kr = ki.search(snq, (short) 20);

    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(2, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(9, kr.getMatch(1).getEndPos());
    // for (Match m : kr.getMatches()) {
    // System.out.println(m.getStartPos() + " " + m.getEndPos());
    // }
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:29,代码来源:TestFocusIndex.java

示例10: TestSampleIndex

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
public TestSampleIndex () throws IOException {
    sample = getSampleIndex();
    String jsonCollection = getJsonString(getClass()
            .getResource("/collection/availability-all.jsonld").getFile());
    KrillCollection collection = new KrillCollection(jsonCollection);
    krillAvailabilityAll = new Krill();
    krillAvailabilityAll.setCollection(collection);

    // &Erfahrung
    sq = new SpanTermQuery(new Term("tokens", "tt/l:Erfahrung"));

    // /+w1:2,s0
    constraints = new ArrayList<DistanceConstraint>();
    constraints.add(TestMultipleDistanceIndex.createConstraint("w", 1, 2,
            true, false));
    constraints.add(TestMultipleDistanceIndex.createConstraint("tokens",
            "base/s:s", 0, 0, true, false));

}
 
开发者ID:KorAP,项目名称:Krill,代码行数:20,代码来源:TestSampleIndex.java

示例11: testcase6

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/** Skip to SegmentSpan */
@Test
public void testcase6 () throws IOException {
    ki.addDoc(createFieldDoc4());
    ki.commit();
    sq = new SpanNextQuery(
            new SpanSegmentQuery(new SpanTermQuery(new Term("base", "s:b")),
                    new SpanTermQuery(new Term("base", "s:c"))),
            new SpanTermQuery(new Term("base", "s:d")));

    kr = ki.search(sq, (short) 10);
    ki.close();

    assertEquals("totalResults", kr.getTotalResults(), 2);
    // Match #0
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos (0)", 4, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 6, kr.getMatch(0).endPos);
    // Match #1 in the other atomic index
    assertEquals("doc-number", 0, kr.getMatch(1).getLocalDocID());
    assertEquals("StartPos (0)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (0)", 2, kr.getMatch(1).endPos);
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:24,代码来源:TestSegmentIndex.java

示例12: testCase3

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/**
 * same attribute types referring to different element types
 */
@Test
public void testCase3 () throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();

    List<SpanQuery> sql = new ArrayList<>();
    sql.add(new SpanAttributeQuery(
            new SpanTermQuery(new Term("base", "@:class=header")), true));
    sql.add(new SpanAttributeQuery(
            new SpanTermQuery(new Term("base", "@:class=book")), true,
            true));
    SpanQuery sq = new SpanWithAttributeQuery(
            new SpanElementQuery("base", "div"), sql, true);

    kr = ki.search(sq, (short) 10);

    assertEquals((long) 3, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(2, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(6, kr.getMatch(1).getEndPos());
    assertEquals(6, kr.getMatch(2).getStartPos());
    assertEquals(7, kr.getMatch(2).getEndPos());
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:28,代码来源:TestAttributeIndex.java

示例13: testCase5

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/**
 * Arbitrary elements with a specific attribute.
 */
@Test
public void testCase5 () throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanAttributeQuery saq = new SpanAttributeQuery(
            new SpanTermQuery(new Term("base", "@:class=book")), true);

    SpanWithAttributeQuery swaq = new SpanWithAttributeQuery(saq, true);
    kr = ki.search(swaq, (short) 10);
    assertEquals(6, kr.getTotalResults());

    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(3, kr.getMatch(0).getEndPos());
    assertEquals(0, kr.getMatch(1).getStartPos());
    assertEquals(5, kr.getMatch(1).getEndPos());
    assertEquals(1, kr.getMatch(2).getStartPos());
    assertEquals(2, kr.getMatch(2).getEndPos());
    assertEquals(2, kr.getMatch(3).getStartPos());
    assertEquals(5, kr.getMatch(3).getEndPos());
    assertEquals(4, kr.getMatch(4).getStartPos());
    assertEquals(5, kr.getMatch(4).getEndPos());
    assertEquals(6, kr.getMatch(5).getStartPos());
    assertEquals(7, kr.getMatch(5).getEndPos());
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:28,代码来源:TestAttributeIndex.java

示例14: testCase6

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/**
 * Arbitrary elements with multiple attributes.
 */
@Test
public void testCase6 () throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();

    List<SpanQuery> sql = new ArrayList<>();
    sql.add(new SpanAttributeQuery(
            new SpanTermQuery(new Term("base", "@:class=header")), true));
    sql.add(new SpanAttributeQuery(
            new SpanTermQuery(new Term("base", "@:class=book")), true));

    SpanWithAttributeQuery swaq = new SpanWithAttributeQuery(sql, true);
    kr = ki.search(swaq, (short) 10);
    assertEquals(2, kr.getTotalResults());

    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(3, kr.getMatch(0).getEndPos());
    assertEquals(4, kr.getMatch(1).getStartPos());
    assertEquals(5, kr.getMatch(1).getEndPos());

}
 
开发者ID:KorAP,项目名称:Krill,代码行数:25,代码来源:TestAttributeIndex.java

示例15: testCase8

import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/**
 * Arbitrary elements with only not attributes.
 */
@Test(expected = IllegalArgumentException.class)
public void testCase8 () throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();

    List<SpanQuery> sql = new ArrayList<>();
    sql.add(new SpanAttributeQuery(
            new SpanTermQuery(new Term("base", "@:class=header")), true,
            true));
    sql.add(new SpanAttributeQuery(
            new SpanTermQuery(new Term("base", "@:class=book")), true,
            true));

    SpanWithAttributeQuery swaq = new SpanWithAttributeQuery(sql, true);
    kr = ki.search(swaq, (short) 10);
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:20,代码来源:TestAttributeIndex.java


注:本文中的org.apache.lucene.search.spans.SpanTermQuery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。