Java Code Examples for org.apache.lucene.index.TermDocs

The following examples show how to use org.apache.lucene.index.TermDocs. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected boolean locateContainer(String nodeRef, IndexReader reader)
{
    boolean found = false;
    try
    {
        TermDocs td = reader.termDocs(new Term("ID", nodeRef));
        while (td.next())
        {
            int doc = td.doc();
            Document document = reader.document(doc);
            if (document.getField("ISCONTAINER") != null)
            {
                found = true;
                break;
            }
        }
        td.close();
    }
    catch (IOException e)
    {
        throw new LuceneIndexException("Failed to delete container and below for " + nodeRef, e);
    }
    return found;        
}
 
Example 2
public boolean filter(Term t) 
{
	int freq = 0;
	TermDocs tDocs;
	
	try {
	    tDocs = indexReader.termDocs(t);
	    while( tDocs.next() ){
	      freq += tDocs.freq();
	    }
	    if( freq < minFreq ){
	      return false;
	    }
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	
    return true;		
}
 
Example 3
final Scorer scorer(IndexReader reader) throws IOException {
   if (terms.size() == 0)			  // optimize zero-term case
     return null;
   if (terms.size() == 1) {			  // optimize one-term case
     Term term = (Term)terms.elementAt(0);
     TermDocs docs = reader.termDocs(term);
     if (docs == null)
return null;
     return new TermScorer(docs, reader.norms(term.field()), weight);
   }

   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;
   }

   if (slop == 0)				  // optimize exact case
     return new ExactPhraseScorer(tps, reader.norms(field), weight);
   else
     return
new SloppyPhraseScorer(tps, slop, reader.norms(field), weight);

 }
 
Example 4
final Scorer scorer(IndexReader reader) throws IOException {
   if (terms.size() == 0)			  // optimize zero-term case
     return null;
   if (terms.size() == 1) {			  // optimize one-term case
     Term term = (Term)terms.elementAt(0);
     TermDocs docs = reader.termDocs(term);
     if (docs == null)
return null;
     return new TermScorer(docs, reader.norms(term.field()), weight);
   }

   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;
   }

   if (slop == 0)				  // optimize exact case
     return new ExactPhraseScorer(tps, reader.norms(field), weight);
   else
     return
new SloppyPhraseScorer(tps, slop, reader.norms(field), weight);

 }
 
Example 5
protected static Set<String> deletePrimary(Collection<String> nodeRefs, IndexReader reader, boolean delete)
        throws LuceneIndexException
{

    Set<String> refs = new LinkedHashSet<String>();

    for (String nodeRef : nodeRefs)
    {

        try
        {
            TermDocs td = reader.termDocs(new Term("PRIMARYPARENT", nodeRef));
            while (td.next())
            {
                int doc = td.doc();
                Document document = reader.document(doc);
                String[] ids = document.getValues("ID");
                refs.add(ids[ids.length - 1]);
                if (delete)
                {
                    reader.deleteDocument(doc);
                }
            }
            td.close();
        }
        catch (IOException e)
        {
            throw new LuceneIndexException("Failed to delete node by primary parent for " + nodeRef, e);
        }
    }

    return refs;

}
 
Example 6
protected static Set<String> deleteReference(Collection<String> nodeRefs, IndexReader reader, boolean delete)
        throws LuceneIndexException
{

    Set<String> refs = new LinkedHashSet<String>();

    for (String nodeRef : nodeRefs)
    {

        try
        {
            TermDocs td = reader.termDocs(new Term("PARENT", nodeRef));
            while (td.next())
            {
                int doc = td.doc();
                Document document = reader.document(doc);
                String[] ids = document.getValues("ID");
                refs.add(ids[ids.length - 1]);
                if (delete)
                {
                    reader.deleteDocument(doc);
                }
            }
            td.close();
        }
        catch (IOException e)
        {
            throw new LuceneIndexException("Failed to delete node by parent for " + nodeRef, e);
        }
    }

    return refs;

}
 
Example 7
protected static Set<String> deleteContainerAndBelow(String nodeRef, IndexReader reader, boolean delete,
        boolean cascade) throws LuceneIndexException
{
    Set<String> refs = new LinkedHashSet<String>();

    try
    {
        if (delete)
        {
            reader.deleteDocuments(new Term("ID", nodeRef));
        }
        refs.add(nodeRef);
        if (cascade)
        {
            TermDocs td = reader.termDocs(new Term("ANCESTOR", nodeRef));
            while (td.next())
            {
                int doc = td.doc();
                Document document = reader.document(doc);
                String[] ids = document.getValues("ID");
                refs.add(ids[ids.length - 1]);
                if (delete)
                {
                    reader.deleteDocument(doc);
                }
            }
            td.close();
        }
    }
    catch (IOException e)
    {
        throw new LuceneIndexException("Failed to delete container and below for " + nodeRef, e);
    }
    return refs;
}
 
Example 8
/** Construct a <code>TermScorer</code>.
 * @param weight The weight of the <code>Term</code> in the query.
 * @param td An iterator over the documents matching the <code>Term</code>.
 * @param similarity The </code>Similarity</code> implementation to be used for score computations.
 * @param norms The field norms of the document fields for the <code>Term</code>.
 */
TermScorer(Weight weight, TermDocs td, Similarity similarity,
           byte[] norms) {
  super(similarity);
  this.weight = weight;
  this.termDocs = td;
  this.norms = norms;
  this.weightValue = weight.getValue();

  for (int i = 0; i < SCORE_CACHE_SIZE; i++)
    scoreCache[i] = getSimilarity().tf(i) * weightValue;
}
 
Example 9
public Scorer scorer(IndexReader reader) throws IOException {
  TermDocs termDocs = reader.termDocs(term);

  if (termDocs == null)
    return null;

  String field = term.field();
  return new TermScorer(this, termDocs, similarity,
          reader.hasNorms(field) ? reader.norms(field) : null);
}
 
Example 10
Source Project: imhotep   Source File: LuceneUnsortedIntTermDocIterator.java    License: Apache License 2.0 5 votes vote down vote up
static LuceneUnsortedIntTermDocIterator create(final IndexReader r, final String field) throws IOException {
    final TermEnum terms = r.terms(new Term(field, ""));
    final TermDocs termDocs;
    try {
        termDocs = r.termDocs();
    } catch (IOException e) {
        try {
            terms.close();
        } catch (IOException e1) {
            log.error("error closing TermEnum", e1);
        }
        throw e;
    }
    return new LuceneUnsortedIntTermDocIterator(field, terms, termDocs);
}
 
Example 11
/**
 * @param id String
 * @param in TermDocs
 */
public FilterTermDocs(String id, TermDocs in)
{
    this.in = in;
}
 
Example 12
@Override
public TermDocs termDocs() throws IOException
{
    return new FilterTermDocs(id, super.termDocs());
}
 
Example 13
Source Project: imhotep   Source File: LuceneUnsortedIntTermDocIterator.java    License: Apache License 2.0 4 votes vote down vote up
LuceneUnsortedIntTermDocIterator(String field, TermEnum terms, TermDocs termDocs) {
    this.field = field.intern();
    this.terms = terms;
    this.termDocs = termDocs;
}
 
Example 14
Source Project: imhotep   Source File: LuceneDocIdStream.java    License: Apache License 2.0 4 votes vote down vote up
public LuceneDocIdStream(final TermDocs termDocs) {
    this.termDocs = termDocs;
}