Changeset 7
- Timestamp:
- 09/30/07 12:46:41 (11 months ago)
- Files:
-
- trunk/Intermentis/Search/Indexable.php (modified) (1 diff)
- trunk/Intermentis/Search/Lucene/Indexer.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Intermentis/Search/Indexable.php
r6 r7 26 26 { 27 27 /** 28 * Get an array with the following construction: 29 * 30 * array( 31 * 'fieldname' => array( 32 * 'type' => Intermentis_Search_Lucene_Indexer::FIELD_TEXT, 33 * 'value' => 'foo' 34 * ), 35 * ... 36 * ) 37 * 38 * @return array 28 * Gets a complete search document used for indexing. 29 * 30 * @return Zend_Search_Lucene_Document 39 31 */ 40 public function get IndexFields();32 public function getSearchDocument(); 41 33 } trunk/Intermentis/Search/Lucene/Indexer.php
r6 r7 25 25 class Intermentis_Search_Lucene_Indexer 26 26 { 27 /**28 * Keyword field type29 *30 * Stored, Indexed31 *32 */33 const FIELD_KEYWORD = 'keyword';34 35 /**36 * Unindexed field type37 *38 * Stored39 *40 */41 const FIELD_UNINDEXED = 'unindexed';42 43 /**44 * Binary field type45 *46 * Stored, Binary47 *48 */49 const FIELD_BINARY = 'binary';50 51 /**52 * Text field type53 *54 * Stored, Indexed, Tokenized55 *56 */57 const FIELD_TEXT = 'text';58 59 /**60 * Unstored field type61 *62 * Indexed, Tokenized63 *64 */65 const FIELD_UNSTORED = 'unstored';66 67 27 /** 68 28 * The search index … … 85 45 * Remove a record from the search index 86 46 * 87 * @param int $id 47 * @param string $searchField 48 * @param string $value 88 49 * @return Intermentis_Search_Lucene_Indexer 89 50 */ 90 public function delete($ id)51 public function delete($searchField, $value) 91 52 { 92 $hits = $this->_index->find( 'id:' . $id);53 $hits = $this->_index->find($searchField . ':' . $value); 93 54 94 55 foreach ($hits as $hit) { … … 100 61 101 62 /** 102 * Index an Intermentis_Search_Indexable. 103 * The $fields array specifies which fields need to be indexed as what. 104 * 105 * Format: 106 * 107 * array( 108 * 'fieldname' => array( 109 * 'type' => Intermentis_Search_Lucene_Indexer::FIELD_TEXT, 110 * 'value' => 'foo' 111 * ), 112 * ... 113 * ) 63 * First deletes and then re-adds the model. 114 64 * 115 65 * @param Intermentis_Search_Indexable $model 116 * @param array $fields 66 * @param string $searchField 67 * @param string $value 117 68 * @return Intermentis_Search_Lucene_Indexer 118 69 */ 119 public function index(Intermentis_Search_Indexable $model, array $fields = null) 70 public function update(Intermentis_Search_Indexable $model, $searchField, $value) 71 { 72 return $this->delete($searchField, $value) 73 ->index($model); 74 } 75 76 /** 77 * Index an Intermentis_Search_Indexable. 78 * 79 * @param Intermentis_Search_Indexable $model 80 * @return Intermentis_Search_Lucene_Indexer 81 */ 82 public function index(Intermentis_Search_Indexable $model) 120 83 { 121 $document = new Zend_Search_Lucene_Document(); 122 123 if ($fields == null) { 124 $fields = $model->getIndexFields(); 125 } 126 127 foreach ($fields as $fieldName => $fieldData) { 128 if ($fieldName == 'id') { 129 $fieldName = 'primaryKeyID'; 130 } 131 132 switch ($fieldData['type']) { 133 case Intermentis_Search_Lucene_Indexer::FIELD_BINARY: 134 $field = Zend_Search_Lucene_Field::Binary($fieldName, $fieldData['value']); 135 break; 136 137 case Intermentis_Search_Lucene_Indexer::FIELD_KEYWORD: 138 $field = Zend_Search_Lucene_Field::Keyword($fieldName, $fieldData['value']); 139 break; 140 141 case Intermentis_Search_Lucene_Indexer::FIELD_TEXT: 142 $field = Zend_Search_Lucene_Field::Text($fieldName, $fieldData['value']); 143 break; 144 145 case Intermentis_Search_Lucene_Indexer::FIELD_UNINDEXED: 146 $field = Zend_Search_Lucene_Field::UnIndexed($fieldName, $fieldData['value']); 147 break; 148 149 case Intermentis_Search_Lucene_Indexer::FIELD_UNSTORED: 150 $field = Zend_Search_Lucene_Field::UnStored($fieldName, $fieldData['value']); 151 break; 152 153 default: 154 throw new Intermentis_Exception('Field type not recognized'); 155 break; 156 } 157 158 $document->addField($field); 159 } 160 161 $this->_index->addDocument($document); 84 $this->_index->addDocument($model->getSearchDocument()); 162 85 163 86 return $this;