Changeset 6525
- Timestamp:
- 12/16/07 21:28:44 (1 year ago)
- Files:
-
- plugins/sfLucenePlugin/trunk/CHANGELOG (modified) (1 diff)
- plugins/sfLucenePlugin/trunk/lib/category/sfLuceneCategory.class.php (modified) (1 diff)
- plugins/sfLucenePlugin/trunk/lib/form (added)
- plugins/sfLucenePlugin/trunk/lib/form/sfLuceneAdvancedForm.class.php (added)
- plugins/sfLucenePlugin/trunk/lib/form/sfLuceneAdvancedFormBase.class.php (added)
- plugins/sfLucenePlugin/trunk/lib/form/sfLuceneForm.class.php (added)
- plugins/sfLucenePlugin/trunk/lib/form/sfLuceneSimpleForm.class.php (added)
- plugins/sfLucenePlugin/trunk/lib/form/sfLuceneSimpleFormBase.class.php (added)
- plugins/sfLucenePlugin/trunk/lib/helper (added)
- plugins/sfLucenePlugin/trunk/lib/helper/sfLuceneHelper.php (copied) (copied from plugins/sfLucenePlugin/trunk/modules/sfLucene/lib/helper/sfLuceneHelper.php) (2 diffs)
- plugins/sfLucenePlugin/trunk/lib/widget (added)
- plugins/sfLucenePlugin/trunk/lib/widget/sfLuceneWidgetFormatter.class.php (added)
- plugins/sfLucenePlugin/trunk/lib/widget/sfLuceneWidgetFormatterAdvanced.class.php (added)
- plugins/sfLucenePlugin/trunk/lib/widget/sfLuceneWidgetFormatterSimple.class.php (added)
- plugins/sfLucenePlugin/trunk/modules/sfLucene/lib/BasesfLuceneActions.class.php (modified) (10 diffs)
- plugins/sfLucenePlugin/trunk/modules/sfLucene/lib/BasesfLuceneComponents.class.php (modified) (1 diff)
- plugins/sfLucenePlugin/trunk/modules/sfLucene/lib/helper (deleted)
- plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/_controls.php (modified) (1 diff)
- plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/advancedSearchControls.php (modified) (1 diff)
- plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/searchControls.php (modified) (1 diff)
- plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/searchNoResults.php (modified) (1 diff)
- plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/searchResults.php (modified) (1 diff)
- plugins/sfLucenePlugin/trunk/test/unit/category/sfLuceneCategoryTest.php (modified) (2 diffs)
- plugins/sfLucenePlugin/trunk/test/unit/form (added)
- plugins/sfLucenePlugin/trunk/test/unit/form/sfLuceneAdvancedFormTest.php (added)
- plugins/sfLucenePlugin/trunk/test/unit/form/sfLuceneFormTest.php (added)
- plugins/sfLucenePlugin/trunk/test/unit/form/sfLuceneSimpleFormTest.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfLucenePlugin/trunk/CHANGELOG
r6489 r6525 12 12 * Refactored category support 13 13 * Minor refactoring of sfLucene class to move to sfParameterHolder 14 * Upgraded forms to sfForm 14 15 15 16 Version 0.1.1 Beta plugins/sfLucenePlugin/trunk/lib/category/sfLuceneCategory.class.php
r6392 r6525 32 32 $this->name = $name; 33 33 $this->count = $count; 34 } 35 36 public function __toString() 37 { 38 return $this->name; 34 39 } 35 40 plugins/sfLucenePlugin/trunk/lib/helper/sfLuceneHelper.php
r6247 r6525 20 20 } 21 21 22 function include_search_controls($ query = null)22 function include_search_controls($form) 23 23 { 24 include_ component(sfContext::getInstance()->getModuleName(), 'controls', array('query' => $query));24 include_partial(sfContext::getInstance()->getModuleName() . '/controls', array('form' => $form)); 25 25 } 26 26 … … 28 28 { 29 29 include_component('sfLucene', 'pagerNavigation', array('pager' => $pager, 'radius' => $radius)); 30 }31 32 function include_search_categories($multiple = false)33 {34 include_component('sfLucene', 'categories', array('multiple' => $multiple));35 }36 37 function has_search_categories()38 {39 return (sfConfig::get('app_lucene_categories', true) ? true : false) && (count(sfLuceneToolkit::getApplicationInstance()->getCategories()) > 0);40 30 } 41 31 plugins/sfLucenePlugin/trunk/modules/sfLucene/lib/BasesfLuceneActions.class.php
r6247 r6525 21 21 * For compatiability with default routing rules. 22 22 */ 23 public function executeIndex( )23 public function executeIndex($request) 24 24 { 25 25 $this->forward($this->getModuleName(), 'search'); … … 31 31 * the search box is displayed to prompt the user to enter controls. 32 32 */ 33 public function executeSearch( )33 public function executeSearch($request) 34 34 { 35 35 // determine if the user pressed the "Advanced" button 36 if ($ this->getRequestParameter('commit') == $this->translate('Advanced'))36 if ($request->getParameter('commit') == $this->translate('Advanced')) 37 37 { 38 38 // user did, so redirect to advanced search … … 40 40 } 41 41 42 $this->advanced_enabled = sfConfig::get('sf_lucene_interface_advanced', true); 43 $this->categories_enabled = sfConfig::get('sf_lucene_interface_categories', true); 44 45 $query = $this->getRequestParameter('query'); 46 47 // did user enter a query? 48 if ($query) 49 { 50 $category = $this->getRequestParameter('category', null); 42 $form = new sfLuceneSimpleForm(); 43 $this->configureCategories($form); 44 $form->bind($request->getParameter('form')); 45 46 // do we have a query? 47 if ($form->isValid()) 48 { 49 $values = $form->getValues(); 51 50 52 51 // get results 53 $pager = $this->getResults($ query, $category);52 $pager = $this->getResults($form); 54 53 55 54 $num = $pager->getNbResults(); … … 59 58 { 60 59 // display results 61 $ this->configurePager($pager);60 $pager = $this->configurePager($pager, $request); 62 61 63 62 $this->num = $num; 64 63 $this->pager = $pager; 65 $this->query = $query; 64 $this->query = $values['query']; 65 $this->form = $form; 66 66 67 67 $this->setTitleNumResults($pager); … … 72 72 { 73 73 // display error 74 $this->form = $form; 74 75 $this->setTitleI18n('No Results Found'); 75 76 … … 80 81 { 81 82 // display search controls 83 $this->form = $form; 82 84 $this->setTitleI18n('Search'); 83 85 … … 90 92 * user use a form to control some of the advanced query syntaxes. 91 93 */ 92 public function executeAdvancedSearch( )94 public function executeAdvancedSearch($request) 93 95 { 94 96 // disable this action if advanced searching is disabled. … … 96 98 97 99 // determine if the "Basic" button was clicked 98 if ($ this->getRequestParameter('commit') == $this->translate('Basic'))100 if ($request->getParameter('commit') == $this->translate('Basic')) 99 101 { 100 102 $this->redirect($this->getModuleName() . '/search'); 101 103 } 102 104 103 // did the user submit the form? 104 if ($this->getRequestParameter('mode') == 'search') 105 { 106 // base quey 107 $query = $this->getRequestParameter('keywords'); 108 109 // build the must have part 110 $musthave = preg_split('/ +/', $this->getRequestParameter('musthave'), -1, PREG_SPLIT_NO_EMPTY); 111 112 if (count($musthave)) 113 { 114 $query .= ' +' . implode($musthave, ' +'); 115 } 116 117 // build the must not have 118 $mustnothave = preg_split('/ +/', $this->getRequestParameter('mustnothave'), -1, PREG_SPLIT_NO_EMPTY); 119 120 if (count($mustnothave)) 121 { 122 $query .= ' -' . implode($mustnothave, ' -'); 123 } 124 125 // build the has pharse part 126 if ($this->getRequestParameter('hasphrase') != '') 127 { 128 $query .= ' "' . str_replace('"', '', $this->getRequestParameter('hasphrase')) . '"'; 129 } 130 131 $query = trim($query); 132 133 // is there a query? 134 if ($query) 135 { 136 // yes, so search 137 138 $this->getRequest()->setParameter('query', $query); 139 140 $this->forward($this->getModuleName(), 'search'); 141 } 142 } 105 $form = new sfLuceneAdvancedForm(); 106 $this->configureCategories($form); 107 108 // continue only if there was a submit 109 if ($request->getParameter('commit')) 110 { 111 $form->bind($request->getParameter('form')); 112 113 // is the form valid? 114 if ($form->isValid()) 115 { 116 $values = $form->getValues(); 117 118 // base quey 119 $query = $values['keywords']; 120 121 // build the must have part 122 $musthave = preg_split('/ +/', $values['musthave'], -1, PREG_SPLIT_NO_EMPTY); 123 124 if (count($musthave)) 125 { 126 $query .= ' +' . implode($musthave, ' +'); 127 } 128 129 // build the must not have 130 $mustnothave = preg_split('/ +/', $values['mustnothave'], -1, PREG_SPLIT_NO_EMPTY); 131 132 if (count($mustnothave)) 133 { 134 $query .= ' -' . implode($mustnothave, ' -'); 135 } 136 137 // build the has pharse part 138 if ($values['hasphrase'] != '') 139 { 140 $query .= ' "' . str_replace('"', '', $values['hasphrase']) . '"'; 141 } 142 143 $query = trim($query); 144 145 // is there a query? 146 if ($query) 147 { 148 // yes, so search 149 150 $requestParam = array('query' => $query); 151 152 if (isset($values['category'])) 153 { 154 $requestParam['category'] = $values['category']; 155 } 156 157 $request->setParameter('form', $requestParam); 158 159 $this->forward($this->getModuleName(), 'search'); 160 } 161 } 162 } 163 164 $this->form = $form; 143 165 144 166 $this->setTitleI18n('Advanced Search'); … … 150 172 * Wrapper function for getting the results. 151 173 */ 152 protected function getResults($querystring, $category = null) 153 { 174 protected function getResults($form) 175 { 176 $data = $form->getValues(); 177 154 178 $query = new sfLuceneCriteria(); 155 $query->addSane($ querystring);156 157 if (sfConfig::get('app_lucene_categories', true) && $category)158 { 159 $query->add('sfl_category: ' . $ category);179 $query->addSane($data['query']); 180 181 if (sfConfig::get('app_lucene_categories', true) && isset($data['category']) && $data['category'] != $this->translate('All')) 182 { 183 $query->add('sfl_category: ' . $data['category']); 160 184 } 161 185 … … 172 196 173 197 /** 198 * Configures the form for categories 199 */ 200 protected function configureCategories($form) 201 { 202 $categories = $this->getLuceneInstance()->getCategories()->getAllCategories(); 203 204 if (!sfConfig::get('app_lucene_categories', true) || count($categories) == 0) 205 { 206 return; 207 } 208 209 $categories = array_merge(array($this->translate('All')), $categories); 210 211 $categories = array_combine($categories, $categories); 212 213 $form->setCategories($categories); 214 215 return $form; 216 } 217 218 /** 174 219 * Configures the pager according to the request parameters. 175 220 */ 176 protected function configurePager($pager )177 { 178 $page = (int) ($ this->getRequestParameter('page', 1));221 protected function configurePager($pager, $request) 222 { 223 $page = (int) ($request->getParameter('page', 1)); 179 224 180 225 $pager->setMaxPerPage(sfConfig::get('app_lucene_per_page', 10)); plugins/sfLucenePlugin/trunk/modules/sfLucene/lib/BasesfLuceneComponents.class.php
r6489 r6525 16 16 abstract class BasesfLuceneComponents extends sfComponents 17 17 { 18 public function executeControls()19 {20 $this->query = $this->getRequestParameter('query');21 }22 23 18 public function executePublicControls() 24 19 { plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/_controls.php
r6247 r6525 8 8 ?> 9 9 10 <?php use_helper('sfLucene') ?> 11 12 <?php echo form_tag('sfLucene/search', 'method=get class=search-controls') ?> 10 <form action="<?php echo url_for('sfLucene/search') ?>" method="get" class="search-controls"> 13 11 14 12 <label for="query"><?php echo __('What are you looking for?') ?></label> 15 <?php echo input_tag('query', $query, 'accesskey=q') ?> 16 <?php if (has_search_categories()): ?> 17 <?php include_search_categories() ?> 13 <?php echo $form['query'] ?> 14 15 <?php if ($form->hasCategories()): ?> 16 <?php echo $form['category'] ?> 18 17 <?php endif ?> 19 <?php echo submit_tag(__('Search'), 'accesskey=s') ?> 18 19 <input type="submit" name="commit" accesskey="s" value="<?php echo __('Search') ?>" /> 20 20 21 <?php if (sfConfig::get('app_lucene_advanced', true)): ?> 21 < ?php echo submit_tag(__('Advanced'), 'accesskey=a') ?>22 <input type="submit" name="commit" accesskey="a" value="<?php echo __('Advanced') ?>" /> 22 23 <?php endif ?> 23 24 plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/advancedSearchControls.php
r6247 r6525 8 8 ?> 9 9 10 <?php use_helper('I18N' , 'sfLucene') ?>10 <?php use_helper('I18N') ?> 11 11 12 12 <h2><?php echo __('Advanced Search') ?></h2> 13 13 14 < ?php echo form_tag('sfLucene/advancedSearch', 'method=get') ?>14 <form action="<?php echo url_for('sfLucene/advancedSearch') ?>" method="get"> 15 15 <fieldset> 16 16 <legend><?php echo __('Search Terms') ?></legend> 17 17 18 18 <table> 19 <tbody> 20 <tr> 21 <td><label for="sfl_keywords"><?php echo __('May contain keywords') ?></label></td> 22 <td><?php echo input_tag('keywords', '', 'id=sfl_keywords') ?></td> 23 </tr> 24 <tr> 25 <td><label for="sfl_musthave"><?php echo __('Must contain keywords') ?></label></td> 26 <td><?php echo input_tag('musthave', '', 'id=sfl_musthave') ?></td> 27 </tr> 28 <tr> 29 <td><label for="sfl_mustnothave"><?php echo __('Must exclude keywords') ?></label></td> 30 <td><?php echo input_tag('mustnothave', '', 'id=sfl_mustnothave') ?></td> 31 </tr> 32 <tr> 33 <td><label for="sfl_hasphrase"><?php echo __('Contains exact phrase') ?></label></td> 34 <td><?php echo input_tag('hasphrase', '', 'id=sfl_hasphrase') ?></label></td> 35 </tr> 36 <?php if (has_search_categories()): ?> 37 <tr> 38 <td><label for="sfl_category"><?php echo __('Must be in category') ?></label></td> 39 <td><?php include_search_categories() ?></td> 40 </tr> 41 <?php endif ?> 19 <?php echo $form ?> 42 20 </table> 43 21 </fieldset> 44 22 45 <?php echo submit_tag(__('Search'), 'accesskey=s') ?> 46 <?php echo submit_tag(__('Basic'), 'accesskey=b') ?> 47 48 <?php echo input_hidden_tag('mode', 'search') ?> 23 <input type="submit" value="<?php echo __('Search') ?>" name="commit" accesskey="s" /> 24 <input type="submit" value="<?php echo __('Basic') ?>" name="commit" accesskey="b" /> 49 25 </form> plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/searchControls.php
r6247 r6525 8 8 ?> 9 9 10 <?php use_helper(' I18N') ?>10 <?php use_helper('sfLucene', 'I18N') ?> 11 11 12 12 <h2><?php echo __('Search') ?></h2> 13 13 <p><?php echo __('Use our search engine to pinpoint exactly what you need on our site.') ?></p> 14 14 15 <?php include_ component($sf_context->getModuleName(), 'controls') ?>15 <?php include_search_controls($form) ?> plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/searchNoResults.php
r6247 r6525 8 8 ?> 9 9 10 <?php use_helper(' I18N') ?>10 <?php use_helper('sfLucene', 'I18N') ?> 11 11 12 12 <h2><?php echo __('No Results Found') ?></h2> 13 13 <p><?php echo __('We could not find any results with the search term you provided.') ?></p> 14 14 15 <?php include_ component($sf_context->getModuleName(), 'controls') ?>15 <?php include_search_controls($form) ?> plugins/sfLucenePlugin/trunk/modules/sfLucene/templates/searchResults.php
r6247 r6525 20 20 </ol> 21 21 22 <?php include_search_pager($pager, sfConfig::get('app_lucene_pager_radius' )) ?>22 <?php include_search_pager($pager, sfConfig::get('app_lucene_pager_radius', 5)) ?> 23 23 24 <?php include_search_controls($ query) ?>24 <?php include_search_controls($form) ?> plugins/sfLucenePlugin/trunk/test/unit/category/sfLuceneCategoryTest.php
r6489 r6525 17 17 require dirname(__FILE__) . '/../../bootstrap/unit.php'; 18 18 19 $t = new lime_test(1 4, new lime_output_color());19 $t = new lime_test(15, new lime_output_color()); 20 20 21 21 $lucene = sfLucene::getInstance('testLucene', 'en'); … … 59 59 60 60 $t->is($c->getPhp(), '$categories[\'bar\'] = 8;', '->getPhp() returns valid PHP to save'); 61 62 $t->diag('testing magic methods'); 63 $t->is($c->__toString(), 'bar', '__toString() returns the name');