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


Java SpanQuery类代码示例

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


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

示例1: toString

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
@Override
public String toString(String field) {
  StringBuilder buffer = new StringBuilder();
  buffer.append("payloadNear([");
  Iterator<SpanQuery> i = clauses.iterator();
  while (i.hasNext()) {
    SpanQuery clause = i.next();
    buffer.append(clause.toString(field));
    if (i.hasNext()) {
      buffer.append(", ");
    }
  }
  buffer.append("], ");
  buffer.append(slop);
  buffer.append(", ");
  buffer.append(inOrder);
  buffer.append(")");
  buffer.append(ToStringUtils.boost(getBoost()));
  return buffer.toString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:PayloadNearQuery.java

示例2: getPayloads

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
private void getPayloads(Collection<byte []> payloads, SpanQuery query)
    throws IOException {
  Map<Term,TermContext> termContexts = new HashMap<>();
  TreeSet<Term> terms = new TreeSet<>();
  query.extractTerms(terms);
  for (Term term : terms) {
    termContexts.put(term, TermContext.build(context, term));
  }
  for (AtomicReaderContext atomicReaderContext : context.leaves()) {
    final Spans spans = query.getSpans(atomicReaderContext, atomicReaderContext.reader().getLiveDocs(), termContexts);
    while (spans.next() == true) {
      if (spans.isPayloadAvailable()) {
        Collection<byte[]> payload = spans.getPayload();
        for (byte [] bytes : payload) {
          payloads.add(bytes);
        }
      }
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:PayloadSpanUtil.java

示例3: getSpanQuery

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
  Element includeElem = DOMUtils.getChildByTagOrFail(e, "Include");
  includeElem = DOMUtils.getFirstChildOrFail(includeElem);

  Element excludeElem = DOMUtils.getChildByTagOrFail(e, "Exclude");
  excludeElem = DOMUtils.getFirstChildOrFail(excludeElem);

  SpanQuery include = factory.getSpanQuery(includeElem);
  SpanQuery exclude = factory.getSpanQuery(excludeElem);

  SpanNotQuery snq = new SpanNotQuery(include, exclude);

  snq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
  return snq;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:SpanNotBuilder.java

示例4: build

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
@Override
public SpanOrQuery build(QueryNode node) throws QueryNodeException {

  // validates node
  BooleanQueryNode booleanNode = (BooleanQueryNode) node;

  List<QueryNode> children = booleanNode.getChildren();
  SpanQuery[] spanQueries = new SpanQuery[children.size()];

  int i = 0;
  for (QueryNode child : children) {
    spanQueries[i++] = (SpanQuery) child
        .getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
  }

  return new SpanOrQuery(spanQueries);

}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:SpanOrQueryNodeBuilder.java

示例5: rewrite

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
@Override
public Query rewrite (IndexReader reader) throws IOException {
    SpanFocusQuery clone = null;
    SpanQuery query = (SpanQuery) this.firstClause.rewrite(reader);

    if (query != this.firstClause) {
        if (clone == null)
            clone = this.clone();
        clone.firstClause = query;
    };

    if (clone != null)
        return clone;

    return this;
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:17,代码来源:SpanFocusQuery.java

示例6: queryJSONwildcardNoFoundry

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
@Test
  public void queryJSONwildcardNoFoundry () throws QueryException, IOException {
      // meine*
      ki = new KrillIndex();
      ki.addDoc(createFieldDoc5());
      ki.commit();

      // treat merging gracefully
SpanQueryWrapper sqw = getJSONQuery(
	getClass().getResource("/queries/bugs/cosmas_wildcards_missingfoundry.jsonld")
	.getFile());
SpanQuery sq = sqw.toQuery();
assertEquals(sq.toString(),"SpanMultiTermQueryWrapper(tokens:l:Erfahr*)");

kr = ki.search(sq, (short) 10);
      assertEquals(4, kr.getMatches().size());
      assertEquals(1, kr.getMatch(0).getStartPos());
      assertEquals(2, kr.getMatch(0).getEndPos());
  }
 
开发者ID:KorAP,项目名称:Krill,代码行数:20,代码来源:TestMultipleDistanceIndex.java

示例7: testCase4

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
/** Same tokens in different elements */
@Test
public void testCase4 () throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();

    SpanQuery sq;
    sq = createQuery("s", "s:b", "s:b", 1, 2, true);
    kr = ki.search(sq, (short) 10);

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

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

示例8: testCase1

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
/**
 * Only terms within an element are matched.
 */
@Test
public void testCase1 () throws IOException {
    //System.out.println("testCase1");
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();

    SpanQuery sq;
    sq = createQuery("s", "s:b", "s:c", 0, 1, false);
    kr = ki.search(sq, (short) 10);

    assertEquals((long) 5, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).startPos);
    assertEquals(1, kr.getMatch(0).endPos);
    assertEquals(0, kr.getMatch(1).startPos);
    assertEquals(3, kr.getMatch(1).endPos);
    assertEquals(2, kr.getMatch(2).startPos);
    assertEquals(4, kr.getMatch(2).endPos);
    assertEquals(3, kr.getMatch(3).startPos);
    assertEquals(5, kr.getMatch(3).endPos);
    assertEquals(4, kr.getMatch(4).startPos);
    assertEquals(7, kr.getMatch(4).endPos);

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

示例9: indexExample3

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
@Test
public void indexExample3 () throws IOException {
    KrillIndex ki = new KrillIndex();

    // abcabcabac
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]"
            + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:c|i:c|_2$<i>2<i>3]"
            + "[(3-4)s:a|i:a|_3$<i>3<i>4|<>:x$<b>64<i>3<i>7<i>7<b>0]"
            + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]"
            + "[(6-7)s:a|i:a|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]"
            + "[(8-9)s:a|i:a|_8$<i>8<i>9]"
            + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
    ki.addDoc(fd);

    ki.commit();

    SpanQuery sq;
    Result kr;

    sq = new SpanNextQuery(new SpanElementQuery("base", "x"),
            new SpanTermQuery(new Term("base", "s:b")));

    kr = ki.search(sq, (short) 10);
    assertEquals("abc[[abcab]]ac", kr.getMatch(0).getSnippetBrackets());
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:27,代码来源:TestNextIndex.java

示例10: testCase3

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的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

示例11: createSpanAttributeQuery

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的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

示例12: testCase2

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
/**
 * Ensure terms and elements are in the same doc
 */
@Test
public void testCase2 () throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();

    SpanQuery sq;
    sq = createQuery("p", "s:b", "s:d", 1, 1, true);
    kr = ki.search(sq, (short) 10);

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

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

示例13: testUnorderedTokenDistance

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的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

示例14: testCase4

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
@Test
public void testCase4 () throws Exception {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.commit();

    String filepath = getClass()
            .getResource("/queries/reference/distance-reference.jsonld")
            .getFile();
    SpanQueryWrapper sqwi = getJSONQuery(filepath);
    SpanQuery sq = sqwi.toQuery();

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

    assertEquals(4, kr.getTotalResults());
    assertEquals("doc-1", kr.getMatch(3).getDocID());
    assertEquals(2, kr.getMatch(3).getStartPos());
    assertEquals(4, kr.getMatch(3).getEndPos());
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:21,代码来源:TestReferenceIndex.java

示例15: checkArguments

import org.apache.lucene.search.spans.SpanQuery; //导入依赖的package包/类
/**
 * Checks if the SpanRelationQuery and the source and target
 * SpanQuery are not null and if the SpanQueries have the same
 * field as the SpanRelationQuery.
 * 
 * @param relation
 *            SpanRelationQery
 * @param source
 *            SpanQuery
 * @param target
 *            SpanQuery
 */
public void checkArguments (SpanRelationQuery relation, SpanQuery source,
        SpanQuery target) {
    checkArguments(relation, source);
    if (target == null) {
        if (source == null) {
            throw new IllegalArgumentException(
                    "The target query cannot be null.");
        }
    }
    if (!target.getField().equals(field)) {
        throw new IllegalArgumentException(
                "Clauses must have the same field.");
    }
    this.operand2Query = target;
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:28,代码来源:SpanRelationMatchQuery.java


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