Changeset 6685
- Timestamp:
- 12/23/07 22:05:32 (1 year ago)
- Files:
-
- plugins/sfLucenePlugin/branches/1.1/lib/results/sfLuceneModelResult.class.php (modified) (6 diffs)
- plugins/sfLucenePlugin/branches/1.1/lib/results/sfLuceneResult.class.php (modified) (6 diffs)
- plugins/sfLucenePlugin/branches/1.1/lib/results/sfLuceneResults.class.php (modified) (1 diff)
- plugins/sfLucenePlugin/branches/1.1/test/data/config/search.yml (modified) (1 diff)
- plugins/sfLucenePlugin/branches/1.1/test/unit/results/sfLuceneActionResultTest.php (added)
- plugins/sfLucenePlugin/branches/1.1/test/unit/results/sfLuceneModelResultTest.php (added)
- plugins/sfLucenePlugin/branches/1.1/test/unit/results/sfLuceneResultTest.php (added)
- plugins/sfLucenePlugin/branches/1.1/test/unit/results/sfLuceneResultsTest.php (added)
- plugins/sfLucenePlugin/branches/1.1/test/unit/sfLuceneTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfLucenePlugin/branches/1.1/lib/results/sfLuceneModelResult.class.php
r6581 r6685 24 24 $model = $this->retrieveModel(); 25 25 26 if ( is_string($model->get('title')))26 if ($model->has('title')) 27 27 { 28 $getter = 'get' . $model->get('title'); 29 return $this->$getter(); 28 return $this->result->getDocument()->getFieldValue($model->get('title')); 30 29 } 31 30 else … … 35 34 if ($model->get('fields')->has($check)) 36 35 { 37 $getter = 'get' . $check; 38 39 return $this->$getter(); 36 return strip_tags($this->result->getDocument()->getFieldValue($check)); 40 37 } 41 38 } 42 39 } 43 40 44 return $this->getInternalModel();41 return 'No title available.'; 45 42 } 46 43 … … 54 51 if (!$model->has('route')) 55 52 { 56 throw new sfLuceneIndexerException(sprintf('A route for model "%s" was not defined in the search.yml file. Did you define one for this application?', $this->getInternalModel()));53 throw new sfLuceneIndexerException(sprintf('A route for model "%s" was not defined in the search.yml file.', $this->getInternalModel())); 57 54 } 58 55 59 return preg_replace_callback('/%(\w+ )%/', array($this, 'internalUriCallback'), $model->get('route'));56 return preg_replace_callback('/%(\w+?)%/', array($this, 'internalUriCallback'), $model->get('route')); 60 57 } 61 58 … … 65 62 protected function internalUriCallback($matches) 66 63 { 67 $getter = 'get' . $matches[1]; 68 69 return $this->$getter(); 64 return $this->result->getDocument()->getFieldValue($matches[1]); 70 65 } 71 66 … … 89 84 $model = $this->retrieveModel(); 90 85 91 if ( is_string($model->get('description')))86 if ($model->has('description')) 92 87 { 93 $getter = 'get' . $model->get('description'); 94 return strip_tags($this->$getter()); 88 return strip_tags($this->result->getDocument()->getFieldValue($model->get('description'))); 95 89 } 96 90 … … 99 93 if ($model->get('fields')->has($check)) 100 94 { 101 $getter = 'get' . $check; 102 return strip_tags($this->$getter()); 95 return strip_tags($this->result->getDocument()->getFieldValue($check)); 103 96 } 104 97 } 105 98 106 return parent::getInternalDescription();99 return 'No description available.'; 107 100 } 108 101 plugins/sfLucenePlugin/branches/1.1/lib/results/sfLuceneResult.class.php
r6652 r6685 30 30 } 31 31 32 p rotectedfunction getSearch()32 public function getSearch() 33 33 { 34 34 return $this->search; 35 } 36 37 public function getResult() 38 { 39 return $this->result; 35 40 } 36 41 … … 46 51 * Gets the partial 47 52 */ 48 public function getInternalPartial( )53 public function getInternalPartial($module = 'sfLucene') 49 54 { 50 return 'sfLucene/' . $this->getInternalType() . 'Result';55 return $module . '/' . $this->getInternalType() . 'Result'; 51 56 } 52 57 … … 55 60 try 56 61 { 57 return strip_tags($this-> sfl_description);62 return strip_tags($this->result->getDocument()->getFieldValue('sfl_description')); 58 63 } 59 64 catch (Exception $e) 60 65 { 61 $responses = array('Click for more information', 'No description available', 'Open this item for more information'); 62 63 return $responses[array_rand($responses)]; 66 return 'No description available.'; 64 67 } 65 68 } 66 69 67 /** 68 * To be implemented later 69 */ 70 public function valid() 70 public function getInternalTitle() 71 71 { 72 return true; 72 try 73 { 74 return $this->result->getDocument()->getFieldValue('sfl_title'); 75 } 76 catch (Exception $e) 77 { 78 return 'No title available.'; 79 } 73 80 } 74 81 … … 78 85 static public function getInstance($result, $search) 79 86 { 80 switch ($result-> sfl_type)87 switch ($result->getDocument()->getFieldValue('sfl_type')) 81 88 { 82 89 case 'action': … … 116 123 } 117 124 118 $call = array($this->results, $method); 119 120 if (is_callable($call)) 125 $event = $this->getSearch()->getContext()->getEventDispatcher()->notifyUntil(new sfEvent($this, 'lucene.result.method_not_found', array('method' => $method, 'arguments' => $args))); 126 if (!$event->isProcessed()) 121 127 { 122 return call_user_func_array($call, $args);128 throw new sfException(sprintf('Call to undefined method %s::%s.', __CLASS__, $method)); 123 129 } 124 130 125 return sfMixer::callMixins();131 return $event->getReturnValue(); 126 132 } 127 133 … … 141 147 return $property; 142 148 } 143 144 /**145 * Wrapper for lucene's __get()146 */147 public function __get($property)148 {149 return $this->result->$property;150 }151 149 } plugins/sfLucenePlugin/branches/1.1/lib/results/sfLuceneResults.class.php
r6298 r6685 100 100 public function offsetGet($offset) 101 101 { 102 return $this-> results[$offset];102 return $this->getInstance($this->results[$offset]); 103 103 } 104 104 plugins/sfLucenePlugin/branches/1.1/test/data/config/search.yml
r6678 r6685 19 19 rebuild_limit: 5 20 20 peer: FakeForumPeer 21 partial: modelResult21 partial: forumResult 22 22 index: 23 23 encoding: UTF-8 plugins/sfLucenePlugin/branches/1.1/test/unit/sfLuceneTest.php
r6679 r6685 128 128 $t->is($m->get('peer'), 'FakeForumPeer', 'model property "peer" is the correct peer'); 129 129 $t->is($m->get('rebuild_limit'), 5, 'model property "rebuild_limit" is the correct rebuild limit'); 130 $t->is($m->get('partial'), ' modelResult', 'model property "partial" is the correct partial');130 $t->is($m->get('partial'), 'forumResult', 'model property "partial" is the correct partial'); 131 131 132 132 $f = $m->get('fields');