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


Java Spans类代码示例

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


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

示例1: getPayloads

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
public void getPayloads(Spans[] subSpans) throws IOException {
  for (int i = 0; i < subSpans.length; i++) {
    if (subSpans[i] instanceof NearSpansOrdered) {
      if (((NearSpansOrdered) subSpans[i]).isPayloadAvailable()) {
        processPayloads(((NearSpansOrdered) subSpans[i]).getPayload(),
            subSpans[i].start(), subSpans[i].end());
      }
      getPayloads(((NearSpansOrdered) subSpans[i]).getSubSpans());
    } else if (subSpans[i] instanceof NearSpansUnordered) {
      if (((NearSpansUnordered) subSpans[i]).isPayloadAvailable()) {
        processPayloads(((NearSpansUnordered) subSpans[i]).getPayload(),
            subSpans[i].start(), subSpans[i].end());
      }
      getPayloads(((NearSpansUnordered) subSpans[i]).getSubSpans());
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:PayloadNearQuery.java

示例2: setFreqCurrentDoc

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
@Override
protected boolean setFreqCurrentDoc() throws IOException {
    if (!more) {
        return false;
      }
      doc = spans.doc();
      freq = 0.0f;
      payloadScore = 0;
      payloadsSeen = 0;
      do {
        int matchLength = spans.end() - spans.start();
        freq += docScorer.computeSlopFactor(matchLength);
        Spans[] spansArr = new Spans[1];
        spansArr[0] = spans;
        getPayloads(spansArr);            
        more = spans.next();
      } while (more && (doc == spans.doc()));
      return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:PayloadNearQuery.java

示例3: getPayloads

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

示例4: ensureSameDoc

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
/**
 * If the current x and y are not in the same document, to skip
 * the
 * span with the smaller document number, to the same OR a greater
 * document number than, the document number of the other span. Do
 * this until the x and the y are in the same doc, OR until the
 * last
 * document.
 * 
 * @return true iff such a document exists.
 */
protected boolean ensureSameDoc (Spans x, Spans y) throws IOException {
    while (x.doc() != y.doc()) {
        if (x.doc() < y.doc()) {
            if (!x.skipTo(y.doc())) {
                hasMoreSpans = false;
                return false;
            }
        }
        else {
            if (!y.skipTo(x.doc())) {
                hasMoreSpans = false;
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:29,代码来源:SimpleSpans.java

示例5: CandidateSpan

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
/**
 * Constructs a CandidateSpan for the given Span.
 * 
 * @param span
 *            a Span
 * @throws IOException
 */
public CandidateSpan (Spans span) throws IOException {
    this.doc = span.doc();
    this.start = span.start();
    this.end = span.end();
    this.cost = span.cost();

    this.payloads = new ArrayList<>();
    if (span.isPayloadAvailable()) {
        setPayloads(span.getPayload());
    }
    if (span instanceof SimpleSpans) {
        SimpleSpans temp = (SimpleSpans) span;
        this.spanId = temp.getSpanId();
        this.hasSpanId = temp.hasSpanId;
    }
    else if (span instanceof ClassSpans) {
        this.spanId = ((ClassSpans) span).getNumber();
        this.hasSpanId = true;
    }
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:28,代码来源:CandidateSpan.java

示例6: advanceElementTo

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
/**
 * Advances the element spans until encountering the given span.
 * 
 * @param span
 *            a span
 * @return <code>true</code> if such an element is found,
 *         <code>false</code>
 *         if the span is not in an element.
 * @throws IOException
 */
private boolean advanceElementTo (Spans span) throws IOException {
    while (hasMoreElements && elements.doc() == currentDocNum
            && elements.start() < span.end()) {

        if (span.start() >= elements.start()
                && span.end() <= elements.end()) {
            return true;
        }
        elementList.add(new CandidateSpan(elements, elementPosition));
        hasMoreElements = elements.next();
        elementPosition++;
    }

    return false; // invalid
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:26,代码来源:UnorderedElementDistanceSpans.java

示例7: setCandidateList

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
@Override
protected boolean setCandidateList (List<CandidateSpan> candidateList,
        Spans candidate, boolean hasMoreCandidates,
        List<CandidateSpan> targetList) throws IOException {

    if (!targetList.isEmpty()) {
        CandidateSpan cs;
        CandidateSpan target = targetList.get(0);
        int position;
        while (hasMoreCandidates && candidate.doc() == target.getDoc()) {
            position = findElementPosition(candidate);
            if (position != -1) {
                cs = new CandidateSpan(candidate, position);

                if (isWithinMaxDistance(target, cs)) {
                    candidateList.add(cs);
                }
                else
                    break;
            }
            hasMoreCandidates = candidate.next();
        }
    }
    return hasMoreCandidates;
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:26,代码来源:UnorderedElementDistanceSpans.java

示例8: advanceNotAttributes

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
/**
 * Advances the <em>not-attributes</em> to be in the same or
 * greater
 * document number than referentSpans' document number. If a
 * <em>not-attribute</em> is in the same document, it is advanced
 * to be in
 * the same as or greater start position than the current
 * referentSpan.
 * 
 * @throws IOException
 */
private void advanceNotAttributes (Spans referentSpans) throws IOException {

    for (AttributeSpans a : notAttributeList) {
        // advance the doc# of not AttributeSpans
        // logger.info("a "+a.start());
        while (!a.isFinish() && a.doc() <= referentSpans.doc()) {

            if (a.doc() == referentSpans.doc()
                    && a.start() >= referentSpans.start())
                break;

            if (!a.next())
                a.setFinish(true);
        }
    }
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:28,代码来源:SpansWithAttribute.java

示例9: test

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
public void test() throws IOException {
  PayloadTermQuery query = new PayloadTermQuery(new Term("field", "seventy"),
          new MaxPayloadFunction());
  TopDocs hits = searcher.search(query, null, 100);
  assertTrue("hits is null and it shouldn't be", hits != null);
  assertTrue("hits Size: " + hits.totalHits + " is not: " + 100, hits.totalHits == 100);

  //they should all have the exact same score, because they all contain seventy once, and we set
  //all the other similarity factors to be 1

  assertTrue(hits.getMaxScore() + " does not equal: " + 1, hits.getMaxScore() == 1);
  for (int i = 0; i < hits.scoreDocs.length; i++) {
    ScoreDoc doc = hits.scoreDocs[i];
    assertTrue(doc.score + " does not equal: " + 1, doc.score == 1);
  }
  CheckHits.checkExplanations(query, PayloadHelper.FIELD, searcher, true);
  Spans spans = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), query);
  assertTrue("spans is null and it shouldn't be", spans != null);
  /*float score = hits.score(0);
  for (int i =1; i < hits.length(); i++)
  {
    assertTrue("scores are not equal and they should be", score == hits.score(i));
  }*/

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

示例10: getSpans

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
@Override
public Spans getSpans(final LeafReaderContext context, Postings requiredPostings) throws IOException {

    Terms terms = context.reader().terms(field);
    if (terms == null) {
        return null; // field does not exist
    }

    ArrayList<Spans> subSpans = new ArrayList<>(clauses.size());
    for (CustomSpanWeight w : subWeights) {
        Spans subSpan = w.getSpans(context, requiredPostings);
        if (subSpan != null) {
            subSpans.add(subSpan);
        } else {
            return null; // all required
        }
    }

    // all NearSpans require at least two subSpans
    return (!inOrder) ? new CustomNearSpansUnordered(slop, subSpans)
            : new NearSpansOrdered(slop, subSpans);
}
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:23,代码来源:PhraseCountQuery.java

示例11: getSpans

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
@Override
public Spans getSpans(final LeafReaderContext context, Postings requiredPostings) throws IOException {

    assert termContext.wasBuiltFor(ReaderUtil.getTopLevelContext(context)) : "The top-reader used to create Weight is not the same as the current reader's top-reader (" + ReaderUtil.getTopLevelContext(context);

    final TermState state = termContext.get(context.ord);
    if (state == null) { // term is not present in that reader
        assert context.reader().docFreq(term) == 0 : "no termstate found but term exists in reader term=" + term;
        return null;
    }

    final Terms terms = context.reader().terms(term.field());
    if (terms == null)
        return null;
    if (terms.hasPositions() == false)
        throw new IllegalStateException("field \"" + term.field() + "\" was indexed without position data; cannot run CustomSpanTermQuery (term=" + term.text() + ")");

    final TermsEnum termsEnum = terms.iterator();
    termsEnum.seekExact(term.bytes(), state);

    final PostingsEnum postings = termsEnum.postings(null, requiredPostings.getRequiredPostings());
    float positionsCost = termPositionsCost(termsEnum) * PHRASE_TO_SPAN_TERM_POSITIONS_COST;
    return new TermSpans(getSimScorer(context), postings, term, positionsCost);
}
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:25,代码来源:CustomSpanTermQuery.java

示例12: getPayloads

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
private void getPayloads(Collection<byte []> payloads, SpanQuery query)
    throws IOException {
  Map<Term,TermContext> termContexts = new HashMap<Term,TermContext>();
  TreeSet<Term> terms = new TreeSet<Term>();
  query.extractTerms(terms);
  for (Term term : terms) {
    termContexts.put(term, TermContext.build(context, term, true));
  }
  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:pkarmstr,项目名称:NYBC,代码行数:21,代码来源:PayloadSpanUtil.java

示例13: getPayloads

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
private void getPayloads(Collection<byte []> payloads, SpanQuery query)
    throws IOException {
  Map<Term,TermContext> termContexts = new HashMap<Term,TermContext>();
  TreeSet<Term> terms = new TreeSet<Term>();
  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:yintaoxue,项目名称:read-open-source-code,代码行数:21,代码来源:PayloadSpanUtil.java

示例14: countSpans

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
long countSpans(String field, Query q) throws Exception {
  List<LeafReaderContext> ctxs = reader.leaves();

  assert (ctxs.size() == 1);
  LeafReaderContext leafReaderContext = ctxs.get(0);
  SpanQuery sq = convert(field, q);
  sq = (SpanQuery) sq.rewrite(reader);
  float boost = getBoost(q);
  SpanWeight sw = sq.createWeight(searcher, false, boost);

  final Spans spans = sw.getSpans(leafReaderContext, SpanWeight.Postings.POSITIONS);

  long i = 0;
  if (spans != null) {
    while (spans.nextDoc() != Spans.NO_MORE_DOCS) {
      while (spans.nextStartPosition() != Spans.NO_MORE_POSITIONS) {
        i++;
      }
    }
  }
  return i;
}
 
开发者ID:tballison,项目名称:lucene-addons,代码行数:23,代码来源:SQPTestBase.java

示例15: countDocs

import org.apache.lucene.search.spans.Spans; //导入依赖的package包/类
long countDocs(String field, Query q) throws Exception {
  BitSet docs = new BitSet();
  List<LeafReaderContext> ctxs = reader.leaves();
  assert (ctxs.size() == 1);
  LeafReaderContext leafReaderContext = ctxs.get(0);
  SpanQuery sq = convert(field, q);
  sq = (SpanQuery) sq.rewrite(reader);
  SpanWeight sw = sq.createWeight(searcher, false, getBoost(q));
  
  final Spans spans = sw.getSpans(leafReaderContext, SpanWeight.Postings.POSITIONS);
  if (spans != null) {
    while (spans.nextDoc() != Spans.NO_MORE_DOCS) {
      while (spans.nextStartPosition() != Spans.NO_MORE_POSITIONS) {
        docs.set(spans.docID());
      }
    }
  }
  long spanDocHits = docs.cardinality();
  // double check with a regular searcher and original query
  TotalHitCountCollector coll = new TotalHitCountCollector();
  searcher.search(q, coll);
  assertEquals(coll.getTotalHits(), spanDocHits);
  return spanDocHits;
}
 
开发者ID:tballison,项目名称:lucene-addons,代码行数:25,代码来源:SQPTestBase.java


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