当前位置: 首页>>代码示例>>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;未经允许,请勿转载。