Examples of TermPositions


Examples of org.apache.lucene.index.TermPositions

      if (terms.size() == 0)        // optimize zero-term case
        return null;

      TermPositions[] tps = new TermPositions[terms.size()];
      for (int i = 0; i < terms.size(); i++) {
        TermPositions p = reader.termPositions((Term)terms.elementAt(i));
        if (p == null)
          return null;
        tps[i] = p;
      }
View Full Code Here

Examples of org.apache.lucene.index.TermPositions

   
      TermPositions[] tps = new TermPositions[termArrays.size()];
      for (int i=0; i<tps.length; i++) {
        Term[] terms = (Term[])termArrays.get(i);
     
        TermPositions p;
        if (terms.length > 1)
          p = new MultipleTermPositions(reader, terms);
        else
          p = reader.termPositions(terms[0]);
     
View Full Code Here

Examples of org.apache.lucene.index.TermPositions

 
  private void init(IndexReader reader) throws IOException
  {
    int maxDoc = reader.maxDoc();
    _uidArray = new long[maxDoc];
    TermPositions tp = null;
    byte[] payloadBuffer = new byte[8];       // four bytes for a long
    try
    {
          tp = reader.termPositions(UID_TERM);
          int idx = 0;
          while (tp.next())
          {
            int doc = tp.doc();
            assert doc < maxDoc;
           
            while(idx < doc) _uidArray[idx++] = DELETED_UID; // fill the gap
           
            tp.nextPosition();
            tp.getPayload(payloadBuffer, 0);
            long uid = bytesToLong(payloadBuffer);
            if(uid < _minUID) _minUID = uid;
            if(uid > _maxUID) _maxUID = uid;
            _uidArray[idx++] = uid;
        }
          while(idx < maxDoc) _uidArray[idx++] = DELETED_UID; // fill the gap
    }
    finally
    {
          if (tp!=null)
          {
            tp.close();
          }
    }
  }
View Full Code Here

Examples of org.apache.lucene.index.TermPositions

  }
 
  @Override
  public TermPositions termPositions(Term term) throws IOException {
    ensureOpen();
      TermPositions tp = in.termPositions(term);
        if(_noDedup) return tp;
       
        int[] delDocIds = _delDocIds;//.get();
        if(tp == null || delDocIds == null || delDocIds.length == 0) return tp;
       
View Full Code Here

Examples of org.apache.lucene.index.TermPositions

  @Override
  public TermPositions termPositions() throws IOException
  {
    ensureOpen();
    TermPositions tp = in.termPositions();
      if(_noDedup) return tp;
     
      int[] delDocIds = _delDocIds;//.get();
      if(tp == null || delDocIds == null || delDocIds.length == 0) return tp;
     
View Full Code Here

Examples of org.apache.lucene.index.TermPositions

        }
    }

    public static DocIdAndVersion loadDocIdAndVersion(IndexReader reader, Term term) {
        int docId = Lucene.NO_DOC;
        TermPositions uid = null;
        try {
            uid = reader.termPositions(term);
            if (!uid.next()) {
                return null; // no doc
            }
            // Note, only master docs uid have version payload, so we can use that info to not
            // take them into account
            do {
                docId = uid.doc();
                uid.nextPosition();
                if (!uid.isPayloadAvailable()) {
                    continue;
                }
                if (uid.getPayloadLength() < 8) {
                    continue;
                }
                byte[] payload = uid.getPayload(new byte[8], 0);
                return new DocIdAndVersion(docId, Numbers.bytesToLong(payload), reader);
            } while (uid.next());
            return new DocIdAndVersion(docId, -2, reader);
        } catch (Exception e) {
            return new DocIdAndVersion(docId, -2, reader);
        } finally {
            if (uid != null) {
                try {
                    uid.close();
                } catch (IOException e) {
                    // nothing to do here...
                }
            }
        }
View Full Code Here

Examples of org.apache.lucene.index.TermPositions

    /**
     * Load the version for the uid from the reader, returning -1 if no doc exists, or -2 if
     * no version is available (for backward comp.)
     */
    public static long loadVersion(IndexReader reader, Term term) {
        TermPositions uid = null;
        try {
            uid = reader.termPositions(term);
            if (!uid.next()) {
                return -1;
            }
            // Note, only master docs uid have version payload, so we can use that info to not
            // take them into account
            do {
                uid.nextPosition();
                if (!uid.isPayloadAvailable()) {
                    continue;
                }
                if (uid.getPayloadLength() < 8) {
                    continue;
                }
                byte[] payload = uid.getPayload(new byte[8], 0);
                return Numbers.bytesToLong(payload);
            } while (uid.next());
            return -2;
        } catch (Exception e) {
            return -2;
        } finally {
            if (uid != null) {
                try {
                    uid.close();
                } catch (IOException e) {
                    // nothing to do here...
                }
            }
        }
View Full Code Here

Examples of org.apache.lucene.index.TermPositions

          prefetchParentOrdinal.length);
      prefetchParentOrdinal = newarray;
    }

    // Read the new part of the parents array from the positions:
    TermPositions positions = indexReader.termPositions(
        new Term(Consts.FIELD_PAYLOADS, Consts.PAYLOAD_PARENT));
    try {
      if (!positions.skipTo(first) && first < num) {
        throw new CorruptIndexException("Missing parent data for category " + first);
      }
      for (int i=first; i<num; i++) {
        // Note that we know positions.doc() >= i (this is an
        // invariant kept throughout this loop)
        if (positions.doc()==i) {
          if (positions.freq() == 0) { // shouldn't happen
            throw new CorruptIndexException(
                "Missing parent data for category "+i);
          }

          // TODO (Facet): keep a local (non-volatile) copy of the prefetchParentOrdinal
          // reference, because access to volatile reference is slower (?).
          // Note: The positions we get here are one less than the position
          // increment we added originally, so we get here the right numbers:
          prefetchParentOrdinal[i] = positions.nextPosition();

          if (!positions.next()) {
            if ( i+1 < num ) {
              throw new CorruptIndexException(
                  "Missing parent data for category "+(i+1));
            }
            break;
          }
        } else { // this shouldn't happen
          throw new CorruptIndexException(
              "Missing parent data for category "+i);
        }
      }
    } finally {
      positions.close(); // to be on the safe side.
    }
  }
View Full Code Here

Examples of org.apache.lucene.index.TermPositions

    writer.close();
   

    IndexSearcher searcher = newSearcher(reader);
   
    TermPositions pos = searcher.getIndexReader().termPositions(new Term("field", "1"));
    pos.next();
    // first token should be at position 0
    assertEquals(0, pos.nextPosition());
   
    pos = searcher.getIndexReader().termPositions(new Term("field", "2"));
    pos.next();
    // second token should be at position 2
    assertEquals(2, pos.nextPosition());
   
    PhraseQuery q;
    ScoreDoc[] hits;

    q = new PhraseQuery();
View Full Code Here

Examples of org.apache.lucene.index.TermPositions

                      new StringReader("a a b c d e a f g h i j a b k k")));
    writer.addDocument(doc);

    IndexReader r = writer.getReader();

    TermPositions tp = r.termPositions(new Term("content", "a"));
    int count = 0;
    assertTrue(tp.next());
    // "a" occurs 4 times
    assertEquals(4, tp.freq());
    int expected = 0;
    assertEquals(expected, tp.nextPosition());
    assertEquals(1, tp.nextPosition());
    assertEquals(3, tp.nextPosition());
    assertEquals(6, tp.nextPosition());

    // only one doc has "a"
    assertFalse(tp.next());

    IndexSearcher is = newSearcher(r);
 
    SpanTermQuery stq1 = new SpanTermQuery(new Term("content", "a"));
    SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.