org.apache.lucene.index.TermDocs Java Examples

The following examples show how to use org.apache.lucene.index.TermDocs. 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
Source File: AbstractLuceneIndexerImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: TermFreqFilter.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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
Source File: right_PhraseQuery_1.5.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
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
Source File: left_PhraseQuery_1.4.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
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
Source File: AbstractLuceneIndexerImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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
Source File: AbstractLuceneIndexerImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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
Source File: AbstractLuceneIndexerImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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
Source File: TermScorer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** 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
Source File: TermQuery.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 File: LuceneUnsortedIntTermDocIterator.java    From imhotep with 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
Source File: FilterIndexReaderByStringId.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param id String
 * @param in TermDocs
 */
public FilterTermDocs(String id, TermDocs in)
{
    this.in = in;
}
 
Example #12
Source File: FilterIndexReaderByStringId.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public TermDocs termDocs() throws IOException
{
    return new FilterTermDocs(id, super.termDocs());
}
 
Example #13
Source File: LuceneUnsortedIntTermDocIterator.java    From imhotep with 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 File: LuceneDocIdStream.java    From imhotep with Apache License 2.0 4 votes vote down vote up
public LuceneDocIdStream(final TermDocs termDocs) {
    this.termDocs = termDocs;
}