Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 03-04-2008, 04:13 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default

Hello,
if your index is already created with multiple fields per name(like the example), you can change the functions getField and addField (and create the new function getFields) in the Document.php of the Framework like this:
PHP Code:
    public function addField(Zend_Search_Lucene_Field $field)
    {
        
//$this->_fields[$field->name] = $field;

        
if ($this->_fields[$field->name] === null) {
          
$this->_fields[$field->name] = $field;
        } else if (
$this->_fields[$field->name] instanceof Zend_Search_Lucene_Field ) {
          
$_newArray = array();
          
array_push($_newArray$this->_fields[$field->name]);
          
array_push($_newArray$field);
          
$this->_fields[$field->name] = $_newArray;
        } else if (
is_array($this->_fields[$field->name])) {
          
array_push($this->_fields[$field->name],  $field);
        } else {
          throw new 
Zend_Search_Lucene_Exception("unknown fieldType : " getType($field));
        }
    }
    public function 
getField($fieldName)
    {
        
//return $this->_fields[$fieldName];

        
if (!array_key_exists($fieldName$this->_fields)) {
            throw new 
Zend_Search_Lucene_Exception("Field name \"$fieldName\" not found in document.");
        } else if (
$this->_fields[$fieldName] instanceof Zend_Search_Lucene_Field ) {
          return 
$this->_fields[$fieldName];
        } else if (
is_array($this->_fields[$fieldName])) {
          return 
$this->_fields[$fieldName][0];
        } else  {
          throw new 
Zend_Search_Lucene_Exception("unknown fieldType : " getType($field));
        }
    }
    public function 
getFields($fieldName)
    {
        if (!
array_key_exists($fieldName$this->_fields)) {
            throw new 
Zend_Search_Lucene_Exception("Field name \"$fieldName\" not found in document.");
        } else if (
$this->_fields[$fieldName] instanceof Zend_Search_Lucene_Field ) {
          return array(
$this->_fields[$fieldName]);
        } else if (
is_array($this->_fields[$fieldName])) {
          return 
$this->_fields[$fieldName];
        } else  {
          throw new 
Zend_Search_Lucene_Exception("unknown fieldType : " getType($field));
        }
    } 

Last edited by rahy : 03-04-2008 at 04:17 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:32 PM.