當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.getField方法代碼示例

本文整理匯總了Java中org.apache.lucene.document.Document.getField方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.getField方法的具體用法?Java Document.getField怎麽用?Java Document.getField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.document.Document的用法示例。


在下文中一共展示了Document.getField方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSimpleNumericOps

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
public void testSimpleNumericOps() throws Exception {
    Directory dir = new RAMDirectory();
    IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER));

    Document document = new Document();
    document.add(new TextField("_id", "1", Field.Store.YES));
    document.add(new LegacyIntField("test", 2, LegacyIntField.TYPE_STORED));
    indexWriter.addDocument(document);

    IndexReader reader = DirectoryReader.open(indexWriter);
    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs topDocs = searcher.search(new TermQuery(new Term("_id", "1")), 1);
    Document doc = searcher.doc(topDocs.scoreDocs[0].doc);
    IndexableField f = doc.getField("test");
    assertThat(f.stringValue(), equalTo("2"));

    BytesRefBuilder bytes = new BytesRefBuilder();
    LegacyNumericUtils.intToPrefixCoded(2, 0, bytes);
    topDocs = searcher.search(new TermQuery(new Term("test", bytes.get())), 1);
    doc = searcher.doc(topDocs.scoreDocs[0].doc);
    f = doc.getField("test");
    assertThat(f.stringValue(), equalTo("2"));

    indexWriter.close();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:SimpleLuceneTests.java

示例2: locateContainer

import org.apache.lucene.document.Document; //導入方法依賴的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;        
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:25,代碼來源:AbstractLuceneIndexerImpl.java

示例3: toDocs

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
private List<Doc> toDocs(ScoreDoc[] hits, Searcher searcher) throws IOException{
  List<Doc> documentList = new ArrayList<>();
  for (int i = 0; i < hits.length; ++i) {
    ScoreDoc scoreDoc = hits[i];
    Document doc = searcher.doc(scoreDoc.doc);
    IndexableField idField = doc.getField("_id");
    if(idField == null){
      // deleted between index hit and retrieval.
      continue;
    }
    final BytesRef ref = idField.binaryValue();
    final byte[] bytes = new byte[ref.length];
    System.arraycopy(ref.bytes, ref.offset, bytes, 0, ref.length);
    Doc outputDoc = new Doc(scoreDoc, bytes, 0);
    documentList.add(outputDoc);
  }
  return documentList;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:19,代碼來源:LuceneSearchIndex.java

示例4: getPath

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
public String getPath(int n) throws IOException
{
    // return getStringValue(n, "PATH");
    Document d = document(n, new SingleFieldSelector("PATH", true));
    Field f = d.getField("PATH");
    return f == null ? null : f.stringValue();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:8,代碼來源:ReferenceCountingReadOnlyIndexReaderFactory.java

示例5: getType

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
public String getType(int n) throws IOException
{
    // return getStringValue(n, "TYPE");
    Document d = document(n, new SingleFieldSelector("TYPE", true));
    Field f = d.getField("TYPE");
    return f == null ? null : f.stringValue();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:8,代碼來源:ReferenceCountingReadOnlyIndexReaderFactory.java

示例6: get

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
@Override
public Object get(final String name,
                  final Document document) {
    final IndexableField stringDateTime = document.getField(name);

    if (stringDateTime != null) {
        return DateTime.parse(stringDateTime.stringValue(), DateTimeFormat.forPattern(DATETIME_FORMAT));
    } else {
        return null;
    }
}
 
開發者ID:mhaddon,項目名稱:Sound.je,代碼行數:12,代碼來源:JodaDateTimeSplitBridge.java

示例7: get

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
@Override
public Object get(final String name, final Document document) {
    final IndexableField stringPeriod = document.getField(name);
    if (stringPeriod != null) {
        return Period.seconds((Integer) stringPeriod.numericValue());
    } else {
        return null;
    }
}
 
開發者ID:mhaddon,項目名稱:Sound.je,代碼行數:10,代碼來源:JodaPeriodSplitBridge.java

示例8: convert

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
@Override
public String convert(Document doc) {
    Field field = doc.getField(FIELD_SOURCE);
    return field == null ? null : field.stringValue();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:6,代碼來源:DocumentUtil.java

示例9: getIsCategory

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
public String getIsCategory(int n) throws IOException
{
    Document d = document(n, new SingleFieldSelector("ISCATEGORY", true));
    Field f = d.getField("ISCATEGORY");
    return f == null ? null : f.stringValue();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:7,代碼來源:ReferenceCountingReadOnlyIndexReaderFactory.java

示例10: getStringValue

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
private String getStringValue(int n, String fieldName) throws IOException
{
    Document document = document(n);
    Field field = document.getField(fieldName);
    return (field == null) ? null : field.stringValue();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:7,代碼來源:ReferenceCountingReadOnlyIndexReaderFactory.java

示例11: detectNodeChanges

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
public void detectNodeChanges(NodeRef nodeRef, SearchService searcher,
        Collection<ChildAssociationRef> addedParents, Collection<ChildAssociationRef> deletedParents,
        Collection<ChildAssociationRef> createdNodes, Collection<NodeRef> updatedNodes) throws LuceneIndexException
{
    boolean nodeExisted = false;
    boolean relationshipsChanged = false;
    
    ResultSet results = null;
    SearchParameters sp = new SearchParameters();
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.addStore(nodeRef.getStoreRef());
    try
    {
        sp.setQuery("ID:" + SearchLanguageConversion.escapeLuceneQuery(nodeRef.toString()));
        results = searcher.query(sp);
        for (ResultSetRow row : results)
        {
            nodeExisted = true;
            Document document = ((LuceneResultSetRow) row).getDocument();
            Field qname = document.getField("QNAME");
            if (qname == null)
            {
                continue;
            }
            Collection<Pair<ChildAssociationRef, QName>> allParents = getAllParents(nodeRef, nodeService.getProperties(nodeRef));
            Set<ChildAssociationRef> dbParents = new HashSet<ChildAssociationRef>(allParents.size() * 2);
            for (Pair<ChildAssociationRef, QName> pair : allParents)
            {
                ChildAssociationRef qNameRef = tenantService.getName(pair.getFirst());
                if ((qNameRef != null) && (qNameRef.getParentRef() != null) && (qNameRef.getQName() != null))
                {
                    dbParents.add(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, qNameRef.getParentRef(), qNameRef.getQName(), qNameRef.getChildRef()));
                }
            }
                           
            Field[] parents = document.getFields("PARENT");
            String[] qnames = qname.stringValue().split(";/");
            Set<ChildAssociationRef> addedParentsSet = new HashSet<ChildAssociationRef>(dbParents);
            for (int i=0; i<Math.min(parents.length, qnames.length); i++)
            {
                QName parentQname = QName.createQName(qnames[i]);
                parentQname = QName.createQName(parentQname.getNamespaceURI(), ISO9075.decode(parentQname.getLocalName()));
                NodeRef parentRef = new NodeRef(parents[i].stringValue());
                ChildAssociationRef indexedParent = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, parentRef, parentQname, nodeRef);
                if (!addedParentsSet.remove(indexedParent))
                {
                    deletedParents.add(indexedParent);                        
                    relationshipsChanged = true;
                }
            }
            if (addedParents.addAll(addedParentsSet))
            {
                relationshipsChanged = true;
            }

            break;
        }

        if (!nodeExisted)
        {
            createdNodes.add(nodeService.getPrimaryParent(nodeRef));
        }
        else if (!relationshipsChanged)
        {
            updatedNodes.add(nodeRef);
        }
    }
    finally
    {
        if (results != null) { results.close(); }
    }
    
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:74,代碼來源:ADMLuceneIndexerImpl.java

示例12: value

import org.apache.lucene.document.Document; //導入方法依賴的package包/類
public String value(Document document) {
    Field field = (Field) document.getField(fieldType().names().indexName());
    return field == null ? null : (String)fieldType().value(field);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:5,代碼來源:IndexFieldMapper.java


注:本文中的org.apache.lucene.document.Document.getField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。