本文整理汇总了Java中org.apache.lucene.search.spans.SpanTermQuery类的典型用法代码示例。如果您正苦于以下问题:Java SpanTermQuery类的具体用法?Java SpanTermQuery怎么用?Java SpanTermQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpanTermQuery类属于org.apache.lucene.search.spans包,在下文中一共展示了SpanTermQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: getSpanTermQueries
import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
private void getSpanTermQueries(Query query, List<Query> spanTermQueries, List<Query> nonSpamTermQueries) throws IOException, InterruptedException {
Query q;
synchronized (query) {
q = query.rewrite(indexReader);
}
if (q instanceof SpanTermQuery) {
spanTermQueries.add(q);
} else {
if (q instanceof BooleanQuery) {
BooleanClause[] bcs = ((BooleanQuery) q).getClauses();
for (BooleanClause bc : bcs) {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException("Snippet extraction thread interrupted during boolean clauses processing");
}
getSpanTermQueries(bc.getQuery(), spanTermQueries, nonSpamTermQueries);
}
} else {
nonSpamTermQueries.add(q);
}
}
}
开发者ID:martinliska,项目名称:MIaS,代码行数:22,代码来源:NiceSnippetExtractor.java
示例17: testCase6
import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/** Next and repetition */
@Test
public void testCase6 () throws IOException {
SpanQuery sq = new SpanNextQuery(
new SpanTermQuery(new Term("tokens", "tt/p:NN")),
new SpanRepetitionQuery(
new SpanTermQuery(new Term("tokens", "mate/p:ADJA")), 2,
2, true));
ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 30223);
// 1.1s
SpanQuery sq2 = new SpanNextQuery(sq,
new SpanTermQuery(new Term("tokens", "tt/p:NN")));
ks = new Krill(sq2);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 26607);
// 1.1s
}
开发者ID:KorAP,项目名称:Krill,代码行数:21,代码来源:TestWPDIndex.java
示例18: indexExample9
import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
@Test
public void indexExample9 () throws IOException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
SpanQuery sq = new SpanNextQuery(
new SpanOrQuery(new SpanTermQuery(new Term("base", "s:a")),
new SpanTermQuery(new Term("base", "s:b"))),
new SpanTermQuery(new Term("base", "s:c")));
Result kr = ki.search(sq, (short) 10);
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
assertEquals(3, kr.getMatch(1).getStartPos());
assertEquals(5, kr.getMatch(1).getEndPos());
}
开发者ID:KorAP,项目名称:Krill,代码行数:19,代码来源:TestNextIndex.java
示例19: testUnorderedTokenDistance
import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
@Test
public void testUnorderedTokenDistance () throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc4());
ki.commit();
List<DistanceConstraint> constraints =
new ArrayList<DistanceConstraint>();
constraints.add(createConstraint("w", 0, 5, true, false));
constraints.add(createConstraint("s", 0, 0, true, false));
SpanQuery mdq;
mdq = createQuery("s:Begin", "s:Moderator", constraints, false);
kr = ki.search(mdq, (short) 10);
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(7, kr.getMatch(0).getEndPos());
SpanQuery sq = new SpanDistanceQuery(mdq,
new SpanTermQuery(new Term("base", "s:ruft")),
new DistanceConstraint(0, 0, false, false), true);
kr = ki.search(sq, (short) 10);
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(7, kr.getMatch(0).getEndPos());
}
开发者ID:KorAP,项目名称:Krill,代码行数:26,代码来源:TestMultipleDistanceIndex.java
示例20: testCase3
import org.apache.lucene.search.spans.SpanTermQuery; //导入依赖的package包/类
/** OR */
@Test
public void testCase3 () throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.commit();
SpanQuery sq, sq2;
// ec{1,2}
sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:e")),
new SpanOrQuery(new SpanRepetitionQuery(
new SpanTermQuery(new Term("base", "s:c")), 1, 1, true),
new SpanRepetitionQuery(
new SpanTermQuery(new Term("base", "s:b")), 1,
1, true)));
kr = ki.search(sq, (short) 10);
assertEquals((long) 3, kr.getTotalResults());
assertEquals(1, kr.getMatch(0).startPos);
assertEquals(3, kr.getMatch(0).endPos);
assertEquals(4, kr.getMatch(1).startPos);
assertEquals(6, kr.getMatch(1).endPos);
assertEquals(7, kr.getMatch(2).startPos);
assertEquals(9, kr.getMatch(2).endPos);
}
开发者ID:KorAP,项目名称:Krill,代码行数:26,代码来源:TestRepetitionIndex.java
注:本文中的org.apache.lucene.search.spans.SpanTermQuery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论