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


PHP Zend_Search_Lucene_Document::getFieldnames方法代码示例

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


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

示例1: addDocument

 /**
  * Adds a document to this index.
  *
  * @param Zend_Search_Lucene_Document $document
  */
 public function addDocument(Zend_Search_Lucene_Document $document)
 {
     $this->_documents[$this->_docID] = $document;
     // parse document
     $analyzer = Zend_Search_Lucene_Analysis_Analyzer::getDefault();
     $fieldNames = $document->getFieldnames();
     foreach ($fieldNames as $fieldName) {
         $field = $document->getField($fieldName);
         // tokenize if requested
         if ($field->isTokenized) {
             $tokens = $analyzer->tokenize($field->getUtf8Value(), 'UTF-8');
         } else {
             $tokens = array(new Zend_Search_Lucene_Analysis_Token($field->getUtf8Value(), 0, strlen(utf8_decode($field->getUtf8Value()))));
         }
         // store tokens in "index"
         $position = -1;
         foreach ($tokens as $token) {
             $text = $token->getTermText();
             $term = new Zend_Search_Lucene_Index_Term($text, $fieldName);
             $position += $token->getPositionIncrement();
             // build an ordered array (list) of terms for each field
             if (isset($this->_terms[$fieldName])) {
                 // if the term is not set already, sort it in
                 if (!isset($this->_terms[$fieldName][$text])) {
                     $new = array();
                     while (($current = array_shift($this->_terms[$fieldName])) && $text > $current->text) {
                         $new[$current->text] = $current;
                     }
                     $new[$text] = $term;
                     if ($current) {
                         $new[$current->text] = $current;
                     }
                     $this->_terms[$fieldName] = array_merge($new, $this->_terms[$fieldName]);
                 }
             } else {
                 // first terms in each field are just stored
                 $this->_terms[$fieldName][$text] = $term;
             }
             // store termPosition for this term
             $this->_termPositions[$fieldName][$text][$this->_docID][] = $position;
             // store or increase term freq for this document
             if (!isset($this->_termDocs[$fieldName][$text][$this->_docID])) {
                 $this->_termDocs[$fieldName][$text][$this->_docID] = 1;
             } else {
                 $this->_termDocs[$fieldName][$text][$this->_docID]++;
             }
         }
         // remember fieldname and document
         $this->_fields[$fieldName][$this->_docID] = 1;
         // calculate and store normalisation vector
         $this->_norms[$fieldName][$this->_docID] = $this->getSimilarity()->lengthNorm($fieldName, sizeof($tokens)) * $document->boost * $field->boost;
     }
     // increase docID
     $this->_docID++;
 }
开发者ID:GerDner,项目名称:TYPO3-ext-tw_lucenesearch,代码行数:60,代码来源:TempIndex.php


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