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


Java TermDocs.seek方法代码示例

本文整理汇总了Java中org.apache.lucene.index.TermDocs.seek方法的典型用法代码示例。如果您正苦于以下问题:Java TermDocs.seek方法的具体用法?Java TermDocs.seek怎么用?Java TermDocs.seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.index.TermDocs的用法示例。


在下文中一共展示了TermDocs.seek方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: queryFieldByUuid

import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
/**
 * Returns the field values associated with a document
 * @param context the operation context
 * @param fieldName the field name
 * @param uuid the document uuid
 * @return the field values (null if not found)
 * @throws CorruptIndexException if the index is corrupt
 * @throws IOException if an I/O exception occurs
 */
public String[] queryFieldByUuid(TocContext context, String fieldName, String uuid) 
  throws CorruptIndexException, IOException {
  TermDocs termDocs = null;
  try {
    uuid = Val.chkStr(uuid);
    if (uuid.length() > 0) {
      IndexSearcher searcher = this.getSearcher(context);
      IndexReader reader = searcher.getIndexReader();
      MapFieldSelector selector = new MapFieldSelector(new String[]{fieldName});
      termDocs = reader.termDocs();
      termDocs.seek(new Term(Storeables.FIELD_UUID,uuid));
      if (termDocs.next()) {
        Document document = reader.document(termDocs.doc(),selector);
        return document.getValues(fieldName);
      }
    }
  } finally {
    try {if (termDocs != null) termDocs.close();} catch (Exception ef) {}
  }
  return null;
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:31,代码来源:TocIndexAdapter.java

示例2: queryValues

import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
/**
 * Queries for documents that match one or more of the supplied values.
 * @param reader the index reader
 * @return the OpenBitSet (documents with matches are set to true)
 * @throws IOException if an exception is encountered while reading the index
 */
private OpenBitSet queryValues(IndexReader reader, String field, String[] values) throws IOException {
  OpenBitSet bitSet = new OpenBitSet(reader.maxDoc());
  if ((values != null) && (values.length > 0)) {
    TermDocs termDocs = null;
    try {      
      Term baseTerm = new Term(field);
      termDocs = reader.termDocs();
      for (String value: values) {
        termDocs.seek(baseTerm.createTerm(value.trim().toLowerCase()));
        while (termDocs.next()) {
          bitSet.set(termDocs.doc());
        }
      }
    } finally {
      try {if (termDocs != null) termDocs.close();} catch (Exception ef) {}
    }
  }
  return bitSet;
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:26,代码来源:AclFilter.java

示例3: queryValue

import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
/**
 * Queries for documents that match the supplied value.
 * @param reader the index reader
 * @return the OpenBitSet (documents with matches are set to true)
 * @throws IOException if an exception is encountered while reading the index
 */
private OpenBitSet queryValue(IndexReader reader, String field, String value) throws IOException {
  OpenBitSet bitSet = new OpenBitSet(reader.maxDoc());
  if ((value != null) && (value.length() > 0)) {
    TermDocs termDocs = null;
    try {      
      Term term = new Term(field,value);
      termDocs = reader.termDocs();
      termDocs.seek(term);
      while (termDocs.next()) {
        bitSet.set(termDocs.doc());
      }
    } finally {
      try {if (termDocs != null) termDocs.close();} catch (Exception ef) {}
    }
  }
  return bitSet;
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:24,代码来源:SchemaFilter.java

示例4: queryValue

import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
/**
 * Queries for documents that match the supplied value.
 * @param reader the index reader
 * @return the OpenBitSet (documents with matches are set to true)
 * @throws IOException if an exception is encountered while reading the index
 */
private OpenBitSet queryValue(IndexReader reader) throws IOException {
  OpenBitSet bitSet = new OpenBitSet(reader.maxDoc());
  if ((this.value != null) && (this.value.length() > 0)) {
    TermDocs termDocs = null;
    try {      
      Term term = new Term(this.fieldName,this.value);
      termDocs = reader.termDocs();
      termDocs.seek(term);
      while (termDocs.next()) {
        bitSet.set(termDocs.doc());
      }
    } finally {
      try {if (termDocs != null) termDocs.close();} catch (Exception ef) {}
    }
  }
  return bitSet;
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:24,代码来源:AsnFilter.java

示例5: queryAcls

import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
/**
 * Queries the ACL values indexed for a document.
 * @param uuid the document UUID
 * @return the ACL values (can be null)
 * @throws CatalogIndexException if an exception occurs
 */
@Override
public String[] queryAcls(String uuid)  throws CatalogIndexException {
  ArrayList<String> values = new ArrayList<String>();
  IndexSearcher searcher = null;
  TermDocs termDocs = null;
  try {
    uuid = Val.chkStr(uuid);
    if (uuid.length() > 0) {
      searcher = newSearcher();
      String[] aFields = new String[]{Storeables.FIELD_ACL};
      MapFieldSelector selector = new MapFieldSelector(aFields);
      searcher = newSearcher();
      IndexReader reader = searcher.getIndexReader();
      termDocs = reader.termDocs();
      termDocs.seek(new Term(Storeables.FIELD_UUID,uuid));
      if (termDocs.next()) {
        Document document = reader.document(termDocs.doc(),selector);
        Field[] fields = document.getFields(Storeables.FIELD_ACL);
        if ((fields != null) && (fields.length > 0)) {
          for (Field field: fields) {
            values.add(field.stringValue());
          }
        }
      } 
    }
  } catch (IOException e) {
    String sMsg = "Error accessing index:\n "+Val.chkStr(e.getMessage());
    throw new CatalogIndexException(sMsg,e);
  } finally {
    try {if (termDocs != null) termDocs.close();} catch (Exception ef) {}
    closeSearcher(searcher);
  }
  return values.toArray(new String[0]);
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:41,代码来源:LuceneIndexAdapter.java

示例6: queryModifiedDate

import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
/**
 * Queries the system modified date associated with an indexed document.
 * @param uuid the document UUID
 * @return the update date (null if none was found)
 * @throws CatalogIndexException if an exception occurs
 */
@Override
public Timestamp queryModifiedDate(String uuid) throws CatalogIndexException {
  Timestamp tsUpdate = null;
  IndexSearcher searcher = null;
  TermDocs termDocs = null;
  try {
    uuid = Val.chkStr(uuid);
    if (uuid.length() > 0) {
      String[] aFields = new String[]{Storeables.FIELD_DATEMODIFIED};
      MapFieldSelector selector = new MapFieldSelector(aFields);
      searcher = newSearcher();
      IndexReader reader = searcher.getIndexReader();
      termDocs = reader.termDocs();
      termDocs.seek(new Term(Storeables.FIELD_UUID,uuid));
      if (termDocs.next()) {
        Document document = reader.document(termDocs.doc(),selector);
        String sUpdate = document.get(Storeables.FIELD_DATEMODIFIED);
        tsUpdate = new Timestamp(Long.valueOf(sUpdate));
      }
    }
  } catch (IOException e) {
    String sMsg = "Error accessing index:\n "+Val.chkStr(e.getMessage());
    throw new CatalogIndexException(sMsg,e);
  } finally {
    try {if (termDocs != null) termDocs.close();} catch (Exception ef) {}
    closeSearcher(searcher);
  }
  return tsUpdate;
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:36,代码来源:LuceneIndexAdapter.java

示例7: loadAssertionById

import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
/**
 * Loads an assertion based upon the subject id of the active operation.
 * @param context the assertion operation context
 * @param mustExist <code>true</code> true if the assertion must exist
 * @return the assertion (null if not found)
 * @throws CorruptIndexException if the index is corrupt
 * @throws IOException if an I/O exception occurs
 * @throws AsnInvalidOperationException if mustExist and the assertion was not found
 */
public Assertion loadAssertionById(AsnContext context, boolean mustExist) 
  throws CorruptIndexException, IOException, AsnInvalidOperationException {
  TermDocs termDocs = null;
  IndexReader reader = null;
  AsnOperation operation = context.getOperation();
  try {
    String assertionId = Val.chkStr(operation.getSubject().getValuePart());
    if (assertionId.length() > 0) {
      reader = this.makeIndexReader();
      termDocs = reader.termDocs();
      termDocs.seek(new Term(AsnConstants.FIELD_SYS_ASSERTIONID,assertionId));
      if (termDocs.next()) {
        Document document = reader.document(termDocs.doc());
        Assertion assertion = operation.getAssertionSet().newAssertion(context,false);
        assertion.load(document);
        return assertion;
      }
    }
  } finally {
    try {if (termDocs != null) termDocs.close();} catch (Exception ef) {}
    this.closeReader(reader);
  }
  if (mustExist) {
    String msg = "This assertion id was not found - "+operation.getSubject().getURN();
    throw new AsnInvalidOperationException(msg);
  }
  return null;
}
 
开发者ID:GeoinformationSystems,项目名称:GeoprocessingAppstore,代码行数:38,代码来源:AsnIndexAdapter.java

示例8: getDocIdSet

import org.apache.lucene.index.TermDocs; //导入方法依赖的package包/类
@Override
public DocIdSet getDocIdSet(IndexReader reader) throws IOException
{
	OpenBitSet bits = new OpenBitSet(reader.maxDoc());

	Term startTerm = new Term(field, start);
	Term endTerm = new Term(field, end);

	TermEnum enumerator = reader.terms(startTerm);
	if( enumerator.term() == null )
	{
		return bits;
	}

	TermDocs termDocs = reader.termDocs();
	try
	{
		Term current = enumerator.term();
		while( current.compareTo(endTerm) <= 0 )
		{
			termDocs.seek(enumerator.term());
			while( termDocs.next() )
			{
				bits.set(termDocs.doc());
			}

			if( !enumerator.next() )
			{
				break;
			}

			current = enumerator.term();
		}
	}
	finally
	{
		enumerator.close();
		termDocs.close();
	}

	return bits;
}
 
开发者ID:equella,项目名称:Equella,代码行数:43,代码来源:ComparisonFilter.java

示例9: 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
}
 
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:74,代码来源:IndexDump.java


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