Java 类org.apache.lucene.document.MapFieldSelector 实例源码

项目:Equella    文件:AbstractCompareDateCollector.java   
@SuppressWarnings("nls")
@Override
public void collect(int docNum) throws IOException
{
    Document doc = reader.document(docNum, new MapFieldSelector(FreeTextQuery.FIELD_UNIQUE, FreeTextQuery.FIELD_ID,
        FreeTextQuery.FIELD_INDEXEDTIME, FreeTextQuery.FIELD_INSTITUTION));
    String unique = doc.get(FreeTextQuery.FIELD_UNIQUE);
    long itemId = Long.parseLong(doc.get(FreeTextQuery.FIELD_ID));
    long instId = Long.parseLong(doc.get(FreeTextQuery.FIELD_INSTITUTION));
    String timeStr = doc.get(FreeTextQuery.FIELD_INDEXEDTIME);

    if( unique == null || timeStr == null )
    {
        LOGGER.warn("Corrupt document '" + docNum + "' in index. {unique:" + unique + ", time:" + timeStr + "}");
    }
    else
    {
        compareDate(itemId, instId, Long.parseLong(timeStr));
    }
}
项目:GeoprocessingAppstore    文件:TocIndexAdapter.java   
/**
 * 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;
}
项目:usgin-geoportal    文件:TocIndexAdapter.java   
/**
 * 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;
}
项目:GeoprocessingAppstore    文件:LuceneIndexAdapter.java   
/**
 * 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]);
}
项目:GeoprocessingAppstore    文件:LuceneIndexAdapter.java   
/**
 * 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;
}
项目:mulgara    文件:FullTextStringIndexTuples.java   
public SearchHitsTuples(final String subject, final String predicate, final String object) throws TuplesException {
  if (logger.isDebugEnabled()) {
    logger.debug("Searching for " + subject + " : " + predicate + " : " + object);
  }

  // run the query
  try {
    hits = fullTextStringIndex.find(subject, predicate, object);
  } catch (FullTextStringIndexException e) {
    throw new TuplesException("Couldn't generate answer from text index: subject='" + subject +
                              "', predicate='" + predicate + "', object='" + object + "'", e);
  }

  // sort the result in doc-id order for faster document retrieval
  hits.sort();

  // make sure we only load those fields we need (=> faster document retrieval)
  List<String> load = new ArrayList<String>(3);
  if (subject == null) load.add(FullTextStringIndex.SUBJECT_KEY);
  if (predicate == null) load.add(FullTextStringIndex.PREDICATE_KEY);
  if (object == null) load.add(FullTextStringIndex.LITERAL_KEY);
  fieldSelector = new MapFieldSelector(load);

  // prepare for iterating
  document = null;
  nextDocumentIndex = 0;

  variableList.addAll(constrVariableList);
  luceneKeyList.addAll(constrLuceneKeyList);

  setVariables(variableList);
}
项目:usgin-geoportal    文件:LuceneIndexAdapter.java   
/**
 * 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]);
}
项目:usgin-geoportal    文件:LuceneIndexAdapter.java   
/**
 * 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;
}