本文整理汇总了Java中org.apache.lucene.index.TermDocs.doc方法的典型用法代码示例。如果您正苦于以下问题:Java TermDocs.doc方法的具体用法?Java TermDocs.doc怎么用?Java TermDocs.doc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.index.TermDocs
的用法示例。
在下文中一共展示了TermDocs.doc方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: locateContainer
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
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;
}
示例2: deletePrimary
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
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;
}
示例3: deleteReference
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
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;
}
示例4: deleteContainerAndBelow
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
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;
}
示例5: getTermPostings
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
/**
* Devuelve los postings de un término dado
*
* @param term Termino a buscar para devolver sus postings
* @return lista de postings de un termino
*/
@Override
public List<Posting> getTermPostings(String term) {
ArrayList<Posting> postingList = new ArrayList<>();
try {
TermDocs termDocs = ireader.termDocs(new Term("content", term));
TermPositions termPositions = ireader.termPositions(new Term("content", term));
//si se usa seek termDocs se borra
//termDocs.seek(new Term(term));
while(termDocs.next()) {
int docId = termDocs.doc();
int freq = termDocs.freq();
ArrayList<Long> positions = new ArrayList<>();
while (termPositions.next()) {
positions.add((long)termPositions.nextPosition());
}
Posting p = new Posting(docId + "", freq, positions);
postingList.add(p);
}
return postingList;
} catch (IOException ex) {
Logger.getLogger(LuceneIndexing.class.getName()).log(Level.SEVERE, null, ex);
}
return postingList;
}
示例6: load
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
private synchronized void load()
{
// If already loaded, don't do it again.
if (docNums != null)
return;
try
{
// Figure out how many entries we'll have, and make our array
// that big.
//
Term term = new Term("docInfo", "1");
nDocs = reader.docFreq(term);
docNums = new int[nDocs];
// Get a list of all the "header" chunks for documents in this
// index (i.e., documents with a "docInfo" field.)
//
TermDocs docHeaders = reader.termDocs(term);
// Record each document number.
int i = 0;
while (docHeaders.next())
docNums[i++] = docHeaders.doc();
nDocs = i; // Account for possibly deleted docs
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
示例7: accept
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
@Override
public void accept(TermDocs termDocs) throws IOException {
if (termDocs == null)
return;
while (termDocs.next()) {
int doc = termDocs.doc();
if (!reader.isDeletedNoLock(doc))
docIDs[count++] = doc;
}
}
示例8: getDocIdSet
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public DocIdSet getDocIdSet(final IndexReader indexReader) throws IOException {
final BitSet bitSet = new BitSet(indexReader.maxDoc());
final TermDocs termDocs = indexReader.termDocs(new Term(CommitIndexer.FIELD_PROJECTKEY, projectKey));
while (termDocs.next()) {
final int docId = termDocs.doc();
final Document theDoc = indexReader.document(docId, issueKeysFieldSelector);
boolean allow = false;
final String[] issueKeys = theDoc.getValues(CommitIndexer.FIELD_ISSUEKEY);
if (issueKeys != null) {
for (final String issueKey : issueKeys) {
final Issue anIssue = issueManager.getIssueObject(StringUtils.upperCase(issueKey));
if (anIssue != null && permissionManager.hasPermission(Permissions.VIEW_VERSION_CONTROL, anIssue, user)) {
allow = true;
break;
}
}
}
bitSet.set(docId, allow);
}
return new DocIdBitSet(bitSet);
}
示例9: buildReaderAclIds
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
public static HashSet<Long> buildReaderAclIds(SolrIndexSearcher searcher, String authority, long[] aclIdByDocId) throws IOException
{
HashSet<Long> aclsAsSet = new HashSet<Long>();
IndexReader reader = searcher.getReader();
TermEnum termEnum = reader.terms(new Term("READER", authority));
try
{
Term term = termEnum.term();
if (term == null)
{
return aclsAsSet;
}
if (term.field().equals("READER") && term.text().equals(authority))
{
TermDocs termDocs = reader.termDocs(term);
try
{
while (termDocs.next())
{
int currentDoc = termDocs.doc();
long acl = aclIdByDocId[currentDoc];
aclsAsSet.add(acl);
}
}
finally
{
termDocs.close();
}
return aclsAsSet;
}
else
{
return aclsAsSet;
}
}
finally
{
termEnum.close();
}
}
示例10: buildReaderAclIds
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
public HashSet<Long> buildReaderAclIds(SolrIndexSearcher searcher, String authority, long[] aclIdByDocId) throws IOException
{
HashSet<Long> aclsAsSet = new HashSet<Long>();
IndexReader reader = searcher.getReader();
TermEnum termEnum = reader.terms(new Term("READER", authority));
try
{
Term term = termEnum.term();
if (term == null)
{
return aclsAsSet;
}
if (term.field().equals("READER") && term.text().equals(authority))
{
TermDocs termDocs = reader.termDocs(term);
try
{
while (termDocs.next())
{
int currentDoc = termDocs.doc();
long acl = aclIdByDocId[currentDoc];
aclsAsSet.add(acl);
}
}
finally
{
termDocs.close();
}
return aclsAsSet;
}
else
{
return aclsAsSet;
}
}
finally
{
termEnum.close();
}
}
示例11: dumpTermFreqs
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
private static void dumpTermFreqs(IndexReader indexReader,
DocNumMap docNumMap, String[] fields,
Writer out)
throws IOException
{
TermDocs docs = indexReader.termDocs();
// Iterate every field.
for (int i = 0; i < fields.length; i++)
{
// Iterate all the terms for this field.
TermEnum terms = indexReader.terms(new Term(fields[i], ""));
while (terms.next())
{
Term t = terms.term();
if (!t.field().equals(fields[i]))
break;
// Skip bi-grams
String text = t.text();
if (text.indexOf("~") >= 0)
continue;
// Skip empty terms (there shouldn't be any though)
if (text.length() == 0)
continue;
// Skip special start/end of field marks (normal terms will also
// be present, without the marks.) Also skip element and attribute
// markers.
//
char c = text.charAt(0);
if (c == Constants.FIELD_START_MARKER ||
c == Constants.ELEMENT_MARKER ||
c == Constants.ATTRIBUTE_MARKER)
{
continue;
}
c = text.charAt(text.length() - 1);
if (c == Constants.FIELD_END_MARKER ||
c == Constants.ELEMENT_MARKER ||
c == Constants.ATTRIBUTE_MARKER)
{
continue;
}
// Okay, we have a live one. Accumulate the total occurrences of
// the term in all documents. For the benefit of the 'text' field,
// accumulate chunk counts into the main document.
//
int prevMainDoc = -1;
int docFreq = 0;
docs.seek(terms);
int termFreq = 0;
while (docs.next())
{
int mainDoc = docs.doc();
if (t.field().equals("text"))
mainDoc = docNumMap.getDocNum(docs.doc());
if (mainDoc != prevMainDoc) {
++docFreq;
prevMainDoc = mainDoc;
}
termFreq += docs.freq();
}
// Output the results.
out.write(
fields[i] + "|" + docFreq + "|" + termFreq + "|" + t.text() + "\n");
} // while
} // for i
}
示例12: getCollectionInfo
import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
/**
* Este método obtiene la relación de ocurrencia de los términos en el
* índice de la colección especificada.
*
* @return relación documentos por término
*
* @throws IndexException si ocurre una error el el proceso de obtención de
* los términos de la colección.
*/
public CollectionInfo getCollectionInfo() throws IndexException {
try {
this.indexLSIPath = new File(defaultIndexLSIPath);
this.directory = FSDirectory.open(this.indexLSIPath);
if (IndexReader.indexExists(this.directory)) {
// se verifica que exista un índice en el directorio especificado
this.reader = IndexReader.open(this.directory);
TermEnum terms = this.reader.terms(); // se obtienen todos los términos del índice de la colección
Map<TermInfo, List<DocTermInfo>> termsMap = new HashMap<TermInfo, List<DocTermInfo>>();
List<DocTermInfo> list;
Term termItem;
TermDocs docs;
int docsCount = 0, termsCount = 0;
docs = this.reader.termDocs();
Document doc;
List<String> termsList = new ArrayList<String>();
Set<Integer> docsIds = new HashSet<Integer>();
docsCount = this.reader.numDocs();
Map<Integer, Integer> docsMap = new HashMap<Integer, Integer>();
List<DocInfo> docInfoList = new ArrayList<DocInfo>(docsCount);
String name, filePath;
int index = 0;
for (int i = 0; i < docsCount; i += 2) {
doc = this.reader.document(i);
name = doc.get("name");
filePath = doc.get("filepath");
docInfoList.add(new DocInfo(name, filePath));
docsMap.put(i + 1, index);
index++;
}
docsMap.remove(docsCount + 1);
while (terms.next()) {
termItem = terms.term();
list = new ArrayList<DocTermInfo>();
docs = this.reader.termDocs(termItem);
while (docs.next()) {
int docNum = docs.doc();
if (!(docNum % 2 == 0)) {
doc = this.reader.document(docNum);
int termFreq = docs.freq();
list.add(new DocTermInfo(docsMap.get(docNum), termFreq));
docsIds.add(docNum);
}
}
if (!list.isEmpty()) {
termsMap.put(new TermInfo(termsCount, termItem.text(), reader.docFreq(termItem)), list);
termsList.add(termItem.text());
termsCount++;
}
}
return new CollectionInfo(termsMap, "Apache Lucene", termsList, docInfoList, singularValue);
} else {
throw new IndexException("Index invalid. Not exist index in the directory: " + defaultIndexLSIPath);
}
} catch (IOException ex) {
throw new IndexException(ex.getMessage());
}
}