Changeset 610356
- Timestamp:
- 10/10/2012 12:58:56 PM (13 years ago)
- Location:
- opensearchserver-search/trunk
- Files:
-
- 4 added
- 7 edited
-
index.php (modified) (1 diff)
-
lib/oss_abstract.class.php (modified) (5 diffs)
-
lib/oss_paging.class.php (modified) (3 diffs)
-
lib/oss_search.class.php (modified) (12 diffs)
-
lib/oss_search_abstract.class.php (added)
-
lib/oss_search_document.php (added)
-
lib/oss_search_mlt.class.php (added)
-
lib/oss_search_spellcheck.class.php (added)
-
lib/oss_searchtemplate.class.php (modified) (2 diffs)
-
opensearchserver_search_functions.php (modified) (1 diff)
-
template/opensearchserver_search.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
opensearchserver-search/trunk/index.php
r603172 r610356 3 3 Plugin Name: OpenSearchServer 4 4 Plugin URI: http://wordpress.org/extend/plugins/opensearchserver-search/ 5 Description: This Plugin will integrate OpenSearchServer as search engine for Wordpress.Go to <a href="plugins.php?page=opensearchserver /index.php">OpenSearchServer Settings</a> for OpenSearchServer Settings,5 Description: This Plugin will integrate OpenSearchServer as search engine for Wordpress.Go to <a href="plugins.php?page=opensearchserver-search/index.php">OpenSearchServer Settings</a> for OpenSearchServer Settings, 6 6 Author: Emmanuel Keller - Naveen.A.N 7 7 Author URI: http://open-search-server.com 8 8 Tested up to: 3.4.2 9 Version:1.1. 19 Version:1.1.2 10 10 */ 11 11 require_once 'lib/oss_api.class.php'; -
opensearchserver-search/trunk/lib/oss_abstract.class.php
r602348 r610356 27 27 protected $login; 28 28 protected $apiKey; 29 protected $lastQueryString; 29 30 30 31 public function init($enginePath, $index = NULL, $login = NULL, $apiKey = NULL) { … … 33 34 } 34 35 } 36 $this->lastQueryString = null; 35 37 $this->enginePath = $enginePath; 36 38 $this->index = $index; … … 131 133 protected function queryServer($url, $data = NULL, $connexionTimeout = OssApi::DEFAULT_CONNEXION_TIMEOUT, $timeout = OssApi::DEFAULT_QUERY_TIMEOUT) { 132 134 135 $this->lastQueryString = $url; 133 136 // Use CURL to post the data 134 137 … … 139 142 curl_setopt($rcurl, CURLOPT_FOLLOWLOCATION, TRUE); 140 143 curl_setopt($rcurl, CURLOPT_MAXREDIRS, 16); 141 curl_setopt($rcurl, CURLOPT_VERBOSE, TRUE);144 curl_setopt($rcurl, CURLOPT_VERBOSE, FALSE); 142 145 143 146 if (is_integer($connexionTimeout) && $connexionTimeout >= 0) { … … 189 192 190 193 return $content; 194 } 195 196 public function getLastQueryString() { 197 return $this->lastQueryString; 191 198 } 192 199 -
opensearchserver-search/trunk/lib/oss_paging.class.php
r601998 r610356 46 46 protected $rowsParameter; 47 47 protected $pageParameter; 48 protected $paramSeparator; 48 49 const MAX_PAGE_TO_LINK = 10; 49 50 … … 53 54 * @return OssApi 54 55 */ 55 public function __construct(SimpleXMLElement $result, $rowsParam = 'rows', $pageParam = 'p' ) {56 public function __construct(SimpleXMLElement $result, $rowsParam = 'rows', $pageParam = 'p', $paramSeparator = '&') { 56 57 $this->oss_result = $result; 57 58 $this->rowsParameter = $rowsParam; 58 59 $this->pageParameter = $pageParam; 60 $this->paramSeparator = $paramSeparator; 59 61 self::compute(); 60 62 … … 122 124 $this->resultNext = min($this->resultCurrentPage + 1, $this->resultTotal); 123 125 } 124 $this->pageBaseURI = preg_replace('/&(?:' . $this->pageParameter . '|' . $this->rowsParameter . ')=[\d]+/', '', $_SERVER['REQUEST_URI']) . '&' . $this->rowsParameter . '=' . $this->resultRows . '&' . $this->pageParameter . '='; 126 $this->pageBaseURI = preg_replace('/&(?:' . $this->pageParameter . '|' . $this->rowsParameter . ')=[\d]+/', '', $_SERVER['REQUEST_URI']) 127 . $this->paramSeparator . $this->rowsParameter . '=' . $this->resultRows . $this->paramSeparator . $this->pageParameter . '='; 125 128 } 126 129 } -
opensearchserver-search/trunk/lib/oss_search.class.php
r603172 r610356 28 28 29 29 require_once(dirname(__FILE__).'/oss_abstract.class.php'); 30 require_once(dirname(__FILE__).'/oss_search_abstract.class.php'); 30 31 31 32 32 33 /** 33 * @author pmercier <[email protected]>34 34 * @package OpenSearchServer 35 * FIXME Complete this documentations36 * FIXME Clean this class and use facilities provided by OssApi37 35 */ 38 class OssSearch extends OssAbstract { 39 40 const API_SELECT = 'select'; 36 class OssSearch extends OssSearchAbstract { 41 37 42 38 protected $query; 43 protected $template;44 39 protected $start; 45 40 protected $rows; 46 41 protected $lang; 47 42 protected $filter; 48 protected $delete;49 43 protected $field; 50 44 protected $sort; … … 52 46 protected $collapse; 53 47 protected $facet; 54 protected $sortBy;55 protected $moreLikeThis;56 protected $log;57 protected $customLogs;58 protected $uniqueKeys;59 protected $docIds;60 48 61 49 /** … … 65 53 */ 66 54 public function __construct($enginePath, $index = NULL, $rows = NULL, $start = NULL, $login = NULL, $apiKey = NULL) { 67 68 $this->init($enginePath, $index, $login, $apiKey); 55 parent::__construct($enginePath, $index, $login, $apiKey); 69 56 70 57 $this->rows($rows); … … 75 62 $this->sort = array(); 76 63 $this->facets = array(); 64 $this->query = NULL; 65 $this->lang = NULL; 77 66 $this->operator = NULL; 78 $this->collapse = array('field' => NULL, 'max' => NULL, 'mode' => NULL); 79 $this->moreLikeThis = array('active' => NULL, 'docquery' => NULL, 'minwordlen' => NULL, 80 'maxwordlen' => NULL, 'mindocfreq' => NULL, 'mintermfreq' => NULL, 'stopwords' => NULL); 81 $this->log = FALSE; 82 $this->customLogs = array(); 83 $this->uniqueKey = array(); 84 $this->docIds = array(); 67 $this->collapse = array('field' => NULL, 'max' => NULL, 'mode' => NULL, 'type' => NULL); 85 68 } 86 69 … … 98 81 * @return OssSearch 99 82 */ 100 public function template($template = NULL) {101 $this->template = $template;102 return $this;103 }104 105 /**106 * @return OssSearch107 */108 83 public function start($start = NULL) { 109 84 $this->start = $start; … … 142 117 public function lang($lang = NULL) { 143 118 $this->lang = $lang; 144 return $this;145 }146 147 /**148 * @return OssSearch149 */150 public function delete($delete = TRUE) {151 $this->delete = (bool)$delete;152 119 return $this; 153 120 } … … 185 152 return $this; 186 153 } 154 155 /** 156 * @return OssSearch 157 */ 158 public function collapseType($type) { 159 $this->collapse['type'] = $type; 160 return $this; 161 } 162 187 163 188 164 /** … … 197 173 * @return OssSearch 198 174 */ 199 public function uniqueKey($uniqueKey = NULL) { 200 $this->uniqueKeys[] = $uniqueKey; 201 return $this; 202 } 203 204 /** 205 * @return OssSearch 206 */ 207 public function docId($docId = NULL) { 208 $this->docIds[] = $docId; 209 return $this; 210 } 211 212 /** 213 * @return OssSearch 214 */ 215 public function facet($field, $min = NULL, $multi = FALSE) { 216 $this->facet[$field] = array('min' => $min, 'multi' => $multi); 217 return $this; 218 } 219 220 public function moreLikeThisActive($active) { 221 $this->moreLikeThis['active'] = $active; 222 } 223 224 public function moreLikeThisDocQuery($docQuery) { 225 $this->moreLikeThis['docquery'] = $docQuery; 226 } 227 228 public function moreLikeThisMinWordLen($minwordlen) { 229 $this->moreLikeThis['minwordlen'] = $minwordlen; 230 } 231 232 public function moreLikeThisMaxWordLen($maxwordlen) { 233 $this->moreLikeThis['maxwordlen'] = $maxwordlen; 234 } 235 236 public function moreLikeThisMinDocFreq($mindocfreq) { 237 $this->moreLikeThis['mindocfreq'] = $mindocfreq; 238 } 239 240 public function moreLikeThisMinTermFreq($mintermfreq) { 241 $this->moreLikeThis['mintermfreq'] = $mintermfreq; 242 } 243 244 public function moreLikeThisMinStopWords($stopwords) { 245 $this->moreLikeThis['stopwords'] = $stopwords; 246 } 247 248 public function setLog($log = FALSE) { 249 $this->log = $log; 250 } 251 252 public function setCustomLog($pos, $log) { 253 $this->customLogs[(int)$pos] = $log; 254 } 255 256 257 /** 258 * @return SimpleXMLElement False if the query produced an error 259 * FIXME Must think about OssApi inteegration inside OssSearch 260 */ 261 public function execute($connectTimeOut = NULL, $timeOut = NULL) { 262 $result = $this->queryServerXML(OssSearch::API_SELECT, $this->getParamsString(), $connectTimeOut, $timeOut); 263 if ($result === FALSE) { 264 return FALSE; 265 } 266 return $result; 267 } 268 269 protected function getParamsString() { 270 271 $queryChunks = array(); 272 175 public function facet($field, $min = NULL, $multi = FALSE, $multi_collapse = FALSE) { 176 $this->facet[$field] = array('min' => $min, 'multi' => $multi, 'multi_collapse' => $multi_collapse); 177 return $this; 178 } 179 180 181 protected function addParams($queryChunks) { 182 183 $queryChunks = parent::addParams($queryChunks); 184 273 185 $queryChunks[] = 'q=' . urlencode((empty($this->query) ? "*:*" : $this->query)); 274 275 if (!empty($this->template)) {276 $queryChunks[] = 'qt=' . $this->template;277 }278 186 279 187 if (!empty($this->lang)) { … … 291 199 if ($this->operator !== NULL) { 292 200 $queryChunks[] = 'operator=' . $this->operator; 293 }294 295 if ($this->delete) {296 $queryChunks[] = 'delete';297 201 } 298 202 … … 321 225 // Facets 322 226 foreach ((array)$this->facet as $field => $options) { 323 $facet = $options['multi'] ? 'facet.multi=' : 'facet='; 324 $facet .= $field; 325 if ($options['min'] !== NULL) { 326 $facet .= '(' . $options['min'] . ')'; 327 } 328 $queryChunks[] = $facet; 227 if($options['multi']) { 228 $facet = 'facet.multi='; 229 } 230 else if($options['multi_collapse']) { 231 $facet = 'facet.multi.collapse='; 232 }else { 233 $facet = 'facet='; 234 } 235 $facet .= $field; 236 if ($options['min'] !== NULL) { 237 $facet .= '(' . $options['min'] . ')'; 238 } 239 $queryChunks[] = $facet; 329 240 } 330 241 … … 333 244 $queryChunks[] = 'collapse.field=' . $this->collapse['field']; 334 245 } 246 if ($this->collapse['type']) { 247 $queryChunks[] = 'collapse.type=' . $this->collapse['type']; 248 } 335 249 if ($this->collapse['mode'] !== NULL) { 336 250 $queryChunks[] = 'collapse.mode=' . $this->collapse['mode']; … … 340 254 } 341 255 342 // MoreLikeThis 343 if ($this->moreLikeThis['active']) { 344 $queryChunks[] = 'mlt=yes'; 345 } 346 if ($this->moreLikeThis['docquery']) { 347 $queryChunks[] = 'mlt.docquery=' . urlencode($this->moreLikeThis['docquery']); 348 } 349 if ($this->moreLikeThis['minwordlen']) { 350 $queryChunks[] = 'mlt.minwordlen=' . (int)$this->moreLikeThis['minwordlen']; 351 } 352 if ($this->moreLikeThis['maxwordlen']) { 353 $queryChunks[] = 'mlt.maxwordlen=' . (int)$this->moreLikeThis['maxwordlen']; 354 } 355 if ($this->moreLikeThis['mindocfreq']) { 356 $queryChunks[] = 'mlt.mindocfreq=' . (int)$this->moreLikeThis['mindocfreq']; 357 } 358 if ($this->moreLikeThis['mintermfreq']) { 359 $queryChunks[] = 'mlt.mintermfreq=' . (int)$this->moreLikeThis['mintermfreq']; 360 } 361 if ($this->moreLikeThis['stopwords']) { 362 $queryChunks[] = 'mlt.stopwords=' . urlencode($this->moreLikeThis['stopwords']); 363 } 364 365 // Logs and customLogs 366 if ($this->log) { 367 $queryChunks[] = 'log=' . $this->log; 368 } 369 foreach ($this->customLogs as $pos => $customLog) { 370 $queryChunks[] = 'log' . $pos . '=' . urlencode($customLog); 371 } 372 373 // DocID 374 foreach ((array) $this->docIds as $docId) { 375 if (empty($docId)) { 376 continue; 377 } 378 $queryChunks[] = 'id=' . urlencode($docId); 379 } 380 381 // UniqueKey 382 foreach ((array) $this->uniqueKeys as $uniqueKey) { 383 if (empty($uniqueKey)) { 384 continue; 385 } 386 $queryChunks[] = 'uk=' . urlencode($uniqueKey); 387 } 388 return implode('&', $queryChunks); 256 return $queryChunks; 389 257 } 390 258 } -
opensearchserver-search/trunk/lib/oss_searchtemplate.class.php
r603172 r610356 76 76 return $return === FALSE ? FALSE : TRUE; 77 77 } 78 /* 78 79 /** 79 80 * Function to create spell check Query Template 80 * $qtsuggestions - No of suggestions to be returned81 * $qtfield - The field that is used for spell checking.82 * $qtscore - The minimum score of Spellcheck match.83 * $qtalgorithm -The alorithm used for spellcheck.OpenSearchServer has below alogrithms for spellcheck.84 * 1)LevensteinDistance85 * 2)NGramDistance86 * 3)JaroWinklerDistance87 */81 * @param string $qtname 82 * @param string $qtquery 83 * @param int $qtsuggestions 84 * @param stringarray $qtfield 85 * @param float $qtscore 86 * @param string $qtlang 87 * @param string $qtalgorithm LevensteinDistance, NGramDistance or JaroWinklerDistance 88 */ 88 89 public function createSpellCheckTemplate($qtname, $qtquery = NULL, $qtsuggestions = NULL, $qtfield = NULL, $qtscore = NULL, $qtlang = NULL, $qtalgorithm = NULL) { 89 90 $params = array("qt.name" => $qtname); … … 141 142 } 142 143 144 public function createMoreLikeThisTemplate( 145 $qtname, $qtquery = NULL, $qtLike = NULL, $qtAnalyzer = NULL, $qtLang = NULL, $qtMinwordlen = NULL, 146 $qtMaxwordlen = NULL, $qtMindocfreq = NULL, $qtMintermfreq = NULL, $qtMaxqueryTerms = NULL, 147 $qtMaxnumtokensparsed = NULL, $qtStopwords = NULL, $qtRows = NULL, $qtStart = NULL, $qtFields = NULL) { 148 149 $params = array("qt.name" => $qtname); 150 $params['qt.type'] = 'MoreLikeThisRequest'; 151 if ($qtquery) { 152 $params['qt.query'] = $qtquery; 153 } 154 if ($qtLike) { 155 $params['qt.like'] = $qtLike; 156 } 157 if ($qtAnalyzer) { 158 $params['qt.analyzer'] = $qtAnalyzer; 159 } 160 if ($qtLang) { 161 $params['qt.lang'] = $qtLang; 162 } 163 if ($qtMinwordlen) { 164 $params['qt.minwordlen'] = $qtMinwordlen; 165 } 166 if ($qtMaxwordlen) { 167 $params['qt.maxwordlen'] = $qtMaxwordlen; 168 } 169 if ($qtMindocfreq) { 170 $params['qt.mindocfreq'] = $qtMindocfreq; 171 } 172 if ($qtMintermfreq) { 173 $params['qt.mintermfreq'] = $qtMintermfreq; 174 } 175 if ($qtMaxqueryTerms) { 176 $params['qt.maxqueryTerms'] = $qtMaxqueryTerms; 177 } 178 if ($qtMaxnumtokensparsed) { 179 $params['qt.maxnumtokensparsed'] = $qtMaxnumtokensparsed; 180 } 181 if ($qtStopwords) { 182 $params['qt.stopwords'] = $qtStopwords; 183 } 184 if ($qtRows) { 185 $params['qt.rows'] = $qtRows; 186 } 187 if ($qtStart) { 188 $params['qt.start'] = $qtStart; 189 } 190 if ($qtFields) { 191 $params['qt.fields'] = $qtFields; 192 } 193 $params['cmd'] = OssSearchTemplate::API_SEARCH_TEMPLATE_CREATE; 194 $return = $this->queryServerXML(OssSearchTemplate::API_SEARCH_TEMPLATE, $params); 195 return $return === FALSE ? FALSE : TRUE; 196 } 197 143 198 } 144 199 ?> -
opensearchserver-search/trunk/opensearchserver_search_functions.php
r603172 r610356 99 99 function opensearchserver_add_facets_search($search) { 100 100 $facets = get_option('oss_facet'); 101 foreach ($facets as $facet) { 102 $search->facet($facet,1); 101 if (isset($facet) && $facet != null) { 102 foreach ($facets as $facet) { 103 $search->facet($facet,1); 104 } 103 105 } 104 106 return $search; -
opensearchserver-search/trunk/template/opensearchserver_search.php
r602348 r610356 55 55 <div id="oss-filter"> 56 56 <?php $facets = get_option('oss_facet'); 57 if (isset($facet) && $facet != null) { 57 58 foreach ($facets as $facet) { 58 59 $facet_results = $oss_result_facets->getFacet($facet); … … 83 84 </ul> 84 85 <?php 86 } 85 87 }?> 86 88 </div>
Note: See TracChangeset
for help on using the changeset viewer.