Changeset 599025
- Timestamp:
- 09/14/2012 03:09:07 PM (13 years ago)
- Location:
- opensearchserver-search/trunk
- Files:
-
- 2 added
- 8 edited
-
index.php (modified) (2 diffs)
-
lib/oss_abstract.class.php (added)
-
lib/oss_api.class.php (modified) (22 diffs)
-
lib/oss_autocompletion.class.php (added)
-
lib/oss_delete.class.php (modified) (3 diffs)
-
lib/oss_indexdocument.class.php (modified) (1 diff)
-
lib/oss_paging.class.php (modified) (3 diffs)
-
lib/oss_results.class.php (modified) (4 diffs)
-
lib/oss_search.class.php (modified) (13 diffs)
-
lib/oss_searchtemplate.class.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
opensearchserver-search/trunk/index.php
r598060 r599025 6 6 Author: Naveen.A.N 7 7 Requires at least: 3.0.0 8 Tested up to: 3. 1.39 Version:1.0. 68 Tested up to: 3.4.2 9 Version:1.0.7 10 10 */ 11 11 require_once 'lib/oss_api.class.php'; … … 73 73 $table_name =$wpdb->prefix ."opensearchserver"; 74 74 $result = $wpdb->get_results('SELECT * FROM '.$table_name); 75 $ossAPI->setField('id','','NO','YES','YES',' ','NO','YES');76 $ossAPI->setField('type','','NO','YES','YES',' ','NO','NO');77 $ossAPI->setField('url','','NO','YES','YES',' ','NO','NO');78 $ossAPI->setField('title','TextAnalyzer','compress','YES','positions_offsets',' ','NO','NO');79 $ossAPI->setField('content','TextAnalyzer','compress','YES','positions_offsets',' ','YES','NO');80 $ossAPI->setField('timestamp','','NO','YES','YES',' ','NO','NO');81 $ossAPI->setField('user_name','','compress','YES','YES',' ','NO','NO');82 $ossAPI->setField('user_email','','compress','YES','YES',' ','NO','NO');83 $ossAPI->setField('user_url','','NO','YES','YES',' ','NO','NO');75 $ossAPI->setField('id','','NO','YES','YES','NO','YES'); 76 $ossAPI->setField('type','','NO','YES','YES','NO','NO'); 77 $ossAPI->setField('url','','NO','YES','YES','NO','NO'); 78 $ossAPI->setField('title','TextAnalyzer','compress','YES','positions_offsets','NO','NO'); 79 $ossAPI->setField('content','TextAnalyzer','compress','YES','positions_offsets','YES','NO'); 80 $ossAPI->setField('timestamp','','NO','YES','YES','NO','NO'); 81 $ossAPI->setField('user_name','','compress','YES','YES','NO','NO'); 82 $ossAPI->setField('user_email','','compress','YES','YES','NO','NO'); 83 $ossAPI->setField('user_url','','NO','YES','YES','NO','NO'); 84 84 $searchTemplate->createSearchTemplate("search",' title:($$)^10 OR title:("$$")^10 85 85 OR -
opensearchserver-search/trunk/lib/oss_api.class.php
r466994 r599025 1 1 <?php 2 2 /* 3 * This file is part of OpenSearchServer.3 * This file is part of OpenSearchServer. 4 4 * 5 * Copyright (C) 2008-201 1Emmanuel Keller / Jaeksoft5 * Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft 6 6 * 7 7 * http://www.open-search-server.com … … 47 47 */ 48 48 49 50 class OssApi { 49 require_once('oss_abstract.class.php'); 50 51 class OssApi extends OssAbstract { 51 52 52 53 const API_SELECT = 'select'; … … 54 55 const API_DELETE = 'delete'; 55 56 const API_OPTIMIZE = 'optimize'; 56 //const API_RELOAD = 'reload';57 const API_RELOAD = 'reload'; 57 58 const API_INDEX = 'index'; 58 59 const API_ENGINE = 'engine'; … … 86 87 */ 87 88 protected static $supportedLanguages = array( 88 "" => "Undefined",89 "zh" => "Chinese",90 "da" => "Danish",91 "nl" => "Dutch",92 "en" => "English",93 "fi" => "Finnish",94 "fr" => "French",95 "de" => "German",96 "hu" => "Hungarian",97 "it" => "Italian",98 "no" => "Norwegian",99 "pt" => "Portuguese",100 "ro" => "Romanian",101 "ru" => "Russian",102 "es" => "Spanish",103 "sv" => "Swedish",104 "tr" => "Turkish"89 "" => "Undefined", 90 "zh" => "Chinese", 91 "da" => "Danish", 92 "nl" => "Dutch", 93 "en" => "English", 94 "fi" => "Finnish", 95 "fr" => "French", 96 "de" => "German", 97 "hu" => "Hungarian", 98 "it" => "Italian", 99 "no" => "Norwegian", 100 "pt" => "Portuguese", 101 "ro" => "Romanian", 102 "ru" => "Russian", 103 "es" => "Spanish", 104 "sv" => "Swedish", 105 "tr" => "Turkish" 105 106 ); 106 107 /* @var string */108 protected $enginePath;109 110 /* @var string */111 protected $index;112 113 /* @var string */114 protected $login;115 116 /* @var string */117 protected $apiKey;118 107 119 108 /** … … 124 113 public function __construct($enginePath, $index = NULL, $login = NULL, $apiKey = NULL) { 125 114 126 $parsedPath = OssApi::parseEnginePath($enginePath, $index); 127 $this->enginePath = $parsedPath['enginePath']; 128 $this->index = $parsedPath['index']; 129 130 $this->credential($login, $apiKey); 131 132 if (!function_exists('OssApi_Dummy_Function')) { 133 function OssApi_Dummy_Function() { 134 } 135 } 115 $this->init($enginePath, $index, $login, $apiKey); 116 136 117 } 137 118 … … 148 129 public function getIndex() { 149 130 return $this->index; 150 }151 152 /**153 * Assign credential information for the next queries154 * @param $login string155 * @param $apiKey string156 * If $login is empty, credential is removed157 */158 public function credential($login, $apiKey) {159 // Remove credentials160 if (empty($login)) {161 $this->login = NULL;162 $this->apiKey = NULL;163 return;164 }165 166 // Else parse and affect new credentials167 if (empty($login) || empty($apiKey)) {168 if (class_exists('OssException')) {169 throw new UnexpectedValueException('You must provide a login and an api key to use credential.');170 }171 trigger_error(__CLASS__ . '::' . __METHOD__ . ': You must provide a login and an api key to use credential.', E_USER_ERROR);172 return FALSE;173 }174 175 $this->login = $login;176 $this->apiKey = $apiKey;177 131 } 178 132 … … 184 138 * It's expected to be in the same directory as OssApi.class.php. 185 139 */ 186 public function select($index = NULL) { 187 $index = $index ? $index : $this->index; 140 public function select() { 188 141 if (!class_exists('OssSearch')) { 189 142 require(dirname(__FILE__) . '/OssSearch.class.php'); 190 143 } 191 return new OssSearch($this->enginePath, $index,NULL, NULL, $this->login, $this->apiKey);144 return new OssSearch($this->enginePath, NULL, NULL, $this->login, $this->apiKey); 192 145 } 193 146 194 147 /** 195 148 * Return an OssSearch using the current engine path and index 196 * @param string $index If provided, this index name is used in place of the one defined in the API instance197 149 * @return OssSearch 198 150 * @deprecated Use OssApi::select 199 151 */ 200 public function search($index = NULL) { 201 $index = $index ? $index : $this->index; 202 return $this->select($index); 152 public function search() { 153 return $this->select(); 203 154 } 204 155 205 156 /** 206 157 * Optimize the index 207 * param string $index If provided, this index name is used in place of the one defined in the API instance208 158 * return boolean True on success 209 159 * see OSS Wiki [Web API optimize] documentation before using this method 210 160 * FIXME Provide a link to the OSS WiKi 211 161 */ 212 public function optimize($index = NULL) { 213 $index = $index ? $index : $this->index; 214 $return = $this->queryServer($this->getQueryURL(OssApi::API_OPTIMIZE, $index)); 162 public function optimize() { 163 $return = $this->queryServer($this->getQueryURL(OssApi::API_OPTIMIZE)); 215 164 return ($return !== FALSE); 216 165 } … … 223 172 * FIXME See why API have been removed 224 173 */ 225 public function reload($index = NULL) { 226 $index = $index ? $index : $this->index; 227 $return = $this->queryServer($this->getQueryURL(OssApi::API_RELOAD, $index)); 174 public function reload() { 175 $return = $this->queryServer($this->getQueryURL(OssApi::API_RELOAD)); 228 176 return ($return !== FALSE); 229 }230 231 /**232 * todo Next release233 * ignore234 * param string $file235 * return NULL236 * FIXME See with ekeller if this's api won't be deprecated soon237 */238 public function push($file) {239 // http://localhost:8080/oss/push?use=fileNiet&fileName=test.pdf&version=1240 177 } 241 178 … … 244 181 * param string|string[] $patterns 245 182 * param boolean $deleteAll The provided patterns will replace the patterns already in the search engine 246 * param string $index If provided, this index name is used in place of the one defined in the API instance247 183 * return boolean True on success 248 184 */ 249 public function pattern($patterns, $deleteAll = FALSE, $index = NULL) { 250 $index = $index ? $index : $this->index; 185 public function pattern($patterns, $deleteAll = FALSE) { 251 186 if (is_array($patterns)) { 252 187 $patterns = implode("\n", $patterns); 253 188 } 254 $return = $this->queryServer($this->getQueryURL(OssApi::API_PATTERN , $index) . ($deleteAll?'&deleteAll=yes':'&deleteAll=no'), $patterns);189 $return = $this->queryServer($this->getQueryURL(OssApi::API_PATTERN) . ($deleteAll?'&deleteAll=yes':'&deleteAll=no'), $patterns); 255 190 return ($return !== FALSE); 256 }257 258 /**259 * Return the url to use with curl260 * param string $apiCall The Web API to call. Refer to the OSS Wiki documentation of [Web API]261 * param string $index The index to query. If none given, index of the current object will be used262 * param string $command The optional command to send to the API call263 * param string[] $options Additional query parameters264 * return string265 * Use OssApi::API_* constants for $apiCall.266 * Optionals query parameters are provided as a named list:267 * array(268 * "arg1" => "value1",269 * "arg2" => "value2"270 * )271 */272 protected function getQueryURL($apiCall, $index = NULL, $cmd = NULL, $options = NULL) {273 274 $path = $this->enginePath . '/' . $apiCall;275 $chunks = array();276 277 if (!empty($index)) {278 $chunks[] = 'use=' . urlencode($index);279 }280 281 if (!empty($cmd)) {282 $chunks[] = 'cmd=' . urlencode($cmd);283 }284 285 // If credential provided, include them in the query url286 if (!empty($this->login)) {287 $chunks[] = "login=" . urlencode($this->login);288 $chunks[] = "key=" . urlencode($this->apiKey);289 }290 291 // Prepare additionnal parameters292 if (is_array($options)) {293 foreach ($options as $argName => $argValue) {294 $chunks[] = $argName . "=" . urlencode($argValue);295 }296 }297 298 $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . implode("&", $chunks);299 300 return $path;301 191 } 302 192 … … 306 196 * a DOMDocument or any object that implement the __toString 307 197 * magic method 308 * @param string $index If provided, this index name is used in place of the one defined in the API instance309 198 * @return boolean True on success 310 199 */ 311 public function update($xml, $index = NULL) { 312 313 $index = $index ? $index : $this->index; 200 public function update($xml) { 314 201 315 202 // Cast $xml to a string … … 336 223 } 337 224 338 $return = $this->queryServer($this->getQueryURL(OssApi::API_UPDATE , $index), $xml);225 $return = $this->queryServer($this->getQueryURL(OssApi::API_UPDATE), $xml); 339 226 return ($return !== FALSE); 340 227 … … 349 236 public function getEngineInformations() { 350 237 $infos = array( 351 'engine_url' => $this->enginePath,352 'engine_version' => 'unknown',353 'login' => $this->login,354 'apiKey' => $this->apiKey238 'engine_url' => $this->enginePath, 239 'engine_version' => 'unknown', 240 'login' => $this->login, 241 'apiKey' => $this->apiKey 355 242 ); 356 243 return $infos; … … 364 251 * @return string[] 365 252 */ 366 public function getIndexInformations($index = NULL) { 367 $index = $index ? $index : $this->index; 253 public function getIndexInformations() { 368 254 369 255 $infos = array( 370 'name' => $index,371 'size' => NULL256 'name' => $index, 257 'size' => NULL 372 258 ); 373 259 374 260 set_error_handler('OssApi_Dummy_Function', E_ALL); 375 261 try { 376 $result = $this->queryServerXML($this->getQueryURL(OssApi::API_SELECT , $index) . '&q=*:*&rows=0');262 $result = $this->queryServerXML($this->getQueryURL(OssApi::API_SELECT) . '&q=*:*&rows=0'); 377 263 } 378 264 catch (Exception $e) { … … 395 281 396 282 // Check if the select api is answering 397 $rcurl = curl_init($this->getQueryURL(OssApi::API_SELECT , $index) . '&q=!*:*&rows=0');283 $rcurl = curl_init($this->getQueryURL(OssApi::API_SELECT) . '&q=!*:*&rows=0'); 398 284 curl_setopt($rcurl, CURLOPT_HTTP_VERSION, '1.0'); 399 285 curl_setopt($rcurl, CURLOPT_RETURNTRANSFER, TRUE); … … 420 306 * @todo Recode this method once API is provided 421 307 */ 422 public function isIndexAvailable($index = NULL ) {308 public function isIndexAvailable($index = NULL,$queryTemplate = NULL) { 423 309 $index = $index ? $index : $this->index; 424 310 // Check if the select api is answering 425 311 set_error_handler('OssApi_Dummy_Function', E_ALL); 426 312 try { 427 $result = $this->queryServerXML($this->getQueryURL(OssApi::API_SELECT, $index) . '&q=!*:*&rows=0'); 313 if($queryTemplate != NULL) { 314 $result = $this->queryServerXML($this->getQueryURL(OssApi::API_SELECT) . '&q=!*:*&rows=0&qt=' . $queryTemplate); 315 } 316 else { 317 $result = $this->queryServerXML($this->getQueryURL(OssApi::API_SELECT) . '&q=!*:*&rows=0'); 318 } 428 319 } 429 320 catch (Exception $e) { … … 439 330 */ 440 331 public function indexList() { 441 $return = $this->queryServerXML($this->getQueryURL(OssApi::API_SCHEMA, NULL, OssApi::API_SCHEMA_INDEX_LIST)); 332 $params = array('cmd' => OssApi::API_SCHEMA_INDEX_LIST); 333 $return = $this->queryServerXML($this->getQueryURL(OssApi::API_SCHEMA, $params)); 442 334 $indexes = array(); 443 335 foreach ($return->index as $index) { … … 455 347 public function createIndex($index, $template = FALSE) { 456 348 457 $params = array( "index.name"=> $index);349 $params = array('index.name' => $index); 458 350 if ($template) { 459 $params["index.template"] = $template; 460 } 461 $return = $this->queryServerXML($this->getQueryURL(OssApi::API_SCHEMA, NULL, OssApi::API_SCHEMA_CREATE_INDEX, $params)); 351 $params['index.template'] = $template; 352 } 353 $params['cmd'] = OssApi::API_SCHEMA_CREATE_INDEX; 354 $return = $this->queryServerXML($this->getQueryURL(OssApi::API_SCHEMA, $params)); 462 355 if ($return === FALSE) { 463 356 return FALSE; … … 468 361 /** 469 362 * Retreive the complete schema of the index 470 * @param string $index If provided, this index name is used in place of the one defined in the API instance471 363 * @return SimpleXMLElement|OSS_Schema 472 364 * The schema is provided by the OSS engine as an xml. This xml is actualy the complete configuration of the schema. 473 365 * If you want to manipulate the schema, pass it to OSS_Schema::factoryFromXML(...) for easier access. 474 366 */ 475 public function getSchema( $index = NULL) {476 $ index = $index ? $index : $this->index;477 return $this->queryServerXML($this->getQueryURL(OssApi::API_SCHEMA, $ index, OssApi::API_SCHEMA_GET_SCHEMA));478 } 479 367 public function getSchema() { 368 $params = array('cmd' => OssApi::API_SCHEMA_GET_SCHEMA); 369 return $this->queryServerXML($this->getQueryURL(OssApi::API_SCHEMA, $params)); 370 } 371 480 372 /** 481 373 * Create or alter a field … … 485 377 * @param string $indexed 486 378 * @param string $termVector 487 * @param string $index If provided, this index name is used in place of the one defined in the API instance488 379 * @return boolean 489 380 */ 490 public function setField($name, $analyzer = NULL, $stored = NULL, $indexed = NULL, $termVector = NULL, $index = NULL, $default = NULL, $unique = NULL) { 491 $index = $index ? $index : $this->index; 381 public function setField($name, $analyzer = NULL, $stored = NULL, $indexed = NULL, $termVector = NULL, $default = NULL, $unique = NULL) { 492 382 $params = array("field.name" => $name); 493 383 if ($analyzer) { … … 503 393 $params["field.termVector"] = $termVector; 504 394 } 505 if ($ termVector) {395 if ($default) { 506 396 $params["field.default"] = $default; 507 397 } 508 if ($ termVector) {398 if ($unique) { 509 399 $params["field.unique"] = $unique; 510 400 } 511 401 512 $return = $this->queryServerXML($this->getQueryURL(OssApi::API_SCHEMA, $index, OssApi::API_SCHEMA_SET_FIELD, $params)); 402 $params['cmd'] = OssApi::API_SCHEMA_SET_FIELD; 403 $return = $this->queryServerXML($this->getQueryURL(OssApi::API_SCHEMA, $params)); 513 404 514 405 if ($return === FALSE) { … … 705 596 public static function escape($string) { 706 597 static $escaping = array( 707 array("+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^", "\"", "~", "*", "?", ":", '\\'),708 array('\+', '\-', '\&\&', '\|\|', '\!', '\(', '\)', '\{', '\}', '\[', '\]', '\^', '\"', '\~', '\*', '\?', '\:', '\\\\')598 array("+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^", "\"", "~", "*", "?", ":", '\\'), 599 array('\+', '\-', '\&\&', '\|\|', '\!', '\(', '\)', '\{', '\}', '\[', '\]', '\^', '\"', '\~', '\*', '\?', '\:', '\\\\') 709 600 ); 710 601 return str_replace($escaping[0], $escaping[1], $string); … … 719 610 720 611 static $remove = array( 721 "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",722 "\x08", "\x0B", "\x0C", "0x0E", "\x0F",723 "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",724 "\x18", "\x19", "\x1A", "\x1B", "\x1C", "\x1D", "\x1E", "\x1F"612 "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", 613 "\x08", "\x0B", "\x0C", "0x0E", "\x0F", 614 "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", 615 "\x18", "\x19", "\x1A", "\x1B", "\x1C", "\x1D", "\x1E", "\x1F" 725 616 ); 726 617 return str_replace($remove, $replacement, $string); -
opensearchserver-search/trunk/lib/oss_delete.class.php
r466994 r599025 2 2 /* 3 3 * This file is part of OpenSearchServer. 4 *5 * Copyright (C)2011 Emmanuel Keller / Jaeksoft6 *7 * http://www.open-search-server.com8 *9 * OpenSearchServer is free software: you can redistribute it and/or modify10 * it under the terms of the GNU General Public License as published by11 * the Free Software Foundation, either version 3 of the License, or12 * (at your option) any later version.13 *14 * OpenSearchServer is distributed in the hope that it will be useful,15 * but WITHOUT ANY WARRANTY; without even the implied warranty of16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17 * GNU General Public License for more details.18 *19 * You should have received a copy of the GNU General Public License20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>.21 */4 * 5 * Copyright (C)2011 Emmanuel Keller / Jaeksoft 6 * 7 * http://www.open-search-server.com 8 * 9 * OpenSearchServer is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * OpenSearchServer is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 22 23 23 /** … … 30 30 } 31 31 32 class OssDelete { 32 require_once('oss_abstract.class.php'); 33 33 34 protected $enginePath; 35 protected $index; 34 class OssDelete extends OssAbstract { 36 35 37 36 public function __construct($enginePath, $index = NULL, $login = NULL, $apiKey = NULL) { 38 $ossAPI = new OssApi($enginePath, $index); 39 $this->enginePath = $ossAPI->getEnginePath(); 40 $this->index = $ossAPI->getIndex(); 41 $this->credential($login, $apiKey); 37 $this->init($enginePath, $index, $login, $apiKey); 42 38 } 43 39 44 40 public function delete($query) { 45 $params = array( "q"=> $query);46 $return = OssApi::queryServerXML($this->getQueryURL(OssApi::API_DELETE, $ this->index , OssApi::API_SCHEMA_DELETE_FIELD, $params));41 $params = array('q' => $query); 42 $return = OssApi::queryServerXML($this->getQueryURL(OssApi::API_DELETE, $params)); 47 43 if ($return === FALSE) { 48 44 return FALSE; … … 51 47 } 52 48 53 public function credential($login, $apiKey) {54 // Remove credentials55 if (empty($login)) {56 $this->login = NULL;57 $this->apiKey = NULL;58 return;59 }60 49 61 // Else parse and affect new credentials62 if (empty($login) || empty($apiKey)) {63 if (class_exists('OssException')) {64 throw new UnexpectedValueException('You must provide a login and an api key to use credential.');65 }66 trigger_error(__CLASS__ . '::' . __METHOD__ . ': You must provide a login and an api key to use credential.', E_USER_ERROR);67 return FALSE;68 }69 70 $this->login = $login;71 $this->apiKey = $apiKey;72 }73 74 protected function getQueryURL($apiCall, $index = NULL, $cmd = NULL, $options = NULL) {75 76 $path = $this->enginePath . '/' . $apiCall;77 $chunks = array();78 79 if (!empty($index)) {80 $chunks[] = 'use=' . urlencode($index);81 }82 83 if (!empty($cmd)) {84 $chunks[] = 'cmd=' . urlencode($cmd);85 }86 87 // If credential provided, include them in the query url88 if (!empty($this->login)) {89 $chunks[] = "login=" . urlencode($this->login);90 $chunks[] = "key=" . urlencode($this->apiKey);91 }92 93 // Prepare additionnal parameters94 if (is_array($options)) {95 foreach ($options as $argName => $argValue) {96 $chunks[] = $argName . "=" . urlencode($argValue);97 }98 }99 100 $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . implode("&", $chunks);101 102 return $path;103 }104 50 } 105 51 ?> -
opensearchserver-search/trunk/lib/oss_indexdocument.class.php
r466994 r599025 3 3 * This file is part of OpenSearchServer. 4 4 * 5 * Copyright (C) 2008-201 1Emmanuel Keller / Jaeksoft5 * Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft 6 6 * 7 7 * http://www.open-search-server.com -
opensearchserver-search/trunk/lib/oss_paging.class.php
r466994 r599025 2 2 /* 3 3 * This file is part of OpenSearchServer. 4 *5 * Copyright (C) 2008-2011 Emmanuel Keller / Jaeksoft6 *7 * http://www.open-search-server.com8 *9 * OpenSearchServer is free software: you can redistribute it and/or modify10 * it under the terms of the GNU General Public License as published by11 * the Free Software Foundation, either version 3 of the License, or12 * (at your option) any later version.13 *14 * OpenSearchServer is distributed in the hope that it will be useful,15 * but WITHOUT ANY WARRANTY; without even the implied warranty of16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17 * GNU General Public License for more details.18 *19 * You should have received a copy of the GNU General Public License20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>.21 */4 * 5 * Copyright (C) 2008-2011 Emmanuel Keller / Jaeksoft 6 * 7 * http://www.open-search-server.com 8 * 9 * OpenSearchServer is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * OpenSearchServer is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 22 23 23 /** … … 103 103 $this->resultStart = (int) $this->oss_result->result['start']; 104 104 105 $this->resultCurrentPage = floor($this->resultStart / $this->resultRows);106 $this->resultTotal = ceil($this->resultFound / $this->resultRows);105 $this->resultCurrentPage = ($this->resultRows > 0) ? floor($this->resultStart / $this->resultRows) : 0; 106 $this->resultTotal = ($this->resultRows > 0) ? ceil($this->resultFound / $this->resultRows) : 0; 107 107 108 108 if ($this->resultTotal > 1) { … … 120 120 $this->resultPrev = max($this->resultCurrentPage - 1, 0); 121 121 if($this->resultCurrentPage + 1 < $this->resultHigh) { 122 $this->resultNext = min($this->resultCurrentPage + 1, $this->resultTotal);122 $this->resultNext = min($this->resultCurrentPage + 1, $this->resultTotal); 123 123 } 124 124 $this->pageBaseURI = preg_replace('/&(?:' . $this->pageParameter . '|' . $this->rowsParameter . ')=[\d]+/', '', $_SERVER['REQUEST_URI']) . '&' . $this->rowsParameter . '=' . $this->resultRows . '&' . $this->pageParameter . '='; -
opensearchserver-search/trunk/lib/oss_results.class.php
r466994 r599025 1 1 <?php 2 2 /* 3 * This file is part of OpenSearchServer.4 *5 * Copyright (C) 2008-2011Emmanuel Keller / Jaeksoft6 *7 * http://www.open-search-server.com8 *9 * OpenSearchServer is free software: you can redistribute it and/or modify10 * it under the terms of the GNU General Public License as published by11 * the Free Software Foundation, either version 3 of the License, or12 * (at your option) any later version.13 *14 * OpenSearchServer is distributed in the hope that it will be useful,15 * but WITHOUT ANY WARRANTY; without even the implied warranty of16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17 * GNU General Public License for more details.18 *19 * You should have received a copy of the GNU General Public License20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>.21 */3 * This file is part of OpenSearchServer. 4 * 5 * Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft 6 * 7 * http://www.open-search-server.com 8 * 9 * OpenSearchServer is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * OpenSearchServer is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 22 23 23 if (!extension_loaded('SimpleXML')) { … … 39 39 protected $resultRows; 40 40 protected $resultStart; 41 41 protected $resultCollapsedCount; 42 42 43 43 /** … … 52 52 $this->resultRows = (int)$this->result->result['rows']; 53 53 $this->resultStart = (int)$this->result->result['start']; 54 54 $this->resultCollapsedCount = (int)$this->result->result['collapsedDocCount']; 55 55 if (!function_exists('OssApi_Dummy_Function')) { 56 56 function OssApi_Dummy_Function() { 57 57 } 58 58 } 59 } 60 public function getResultCollapsedCount() { 61 return $this->resultCollapsedCount; 59 62 } 60 63 … … 152 155 } 153 156 157 /** 158 * 159 * @return Return the spellsuggest array. 160 */ 161 public function getSpellSuggestions($fieldName) { 162 $currentSpellCheck = isset($fieldName)? $this->result->xpath('spellcheck/field[@name="' . $fieldName . '"]/word/suggest'):NULL; 163 if (!isset($currentSpellCheck) || ( isset($currentSpellCheck) && $currentSpellCheck === FALSE)) { 164 $currentSpellCheck = array(); 165 } 166 return $currentSpellCheck; 167 } 168 /** 169 * 170 * @return Return the spellsuggest terms. 171 */ 172 public function getSpellSuggest($fieldName) { 173 $spellCheckWord = isset($fieldName)? $this->result->xpath('spellcheck/field[@name="' . $fieldName . '"]/word'):NULL; 174 foreach ($spellCheckWord as $each) { 175 $queryExact .= $each[0]->suggest.' '; 176 } 177 return $queryExact; 178 } 179 154 180 } 155 181 ?> -
opensearchserver-search/trunk/lib/oss_search.class.php
r466994 r599025 2 2 /* 3 3 * This file is part of OpenSearchServer. 4 *5 * Copyright (C) 2008-2011Emmanuel Keller / Jaeksoft6 *7 * http://www.open-search-server.com8 *9 * OpenSearchServer is free software: you can redistribute it and/or modify10 * it under the terms of the GNU General Public License as published by11 * the Free Software Foundation, either version 3 of the License, or12 * (at your option) any later version.13 *14 * OpenSearchServer is distributed in the hope that it will be useful,15 * but WITHOUT ANY WARRANTY; without even the implied warranty of16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17 * GNU General Public License for more details.18 *19 * You should have received a copy of the GNU General Public License20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>.21 */4 * 5 * Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft 6 * 7 * http://www.open-search-server.com 8 * 9 * OpenSearchServer is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * OpenSearchServer is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 22 23 23 … … 30 30 trigger_error("OssSearch won't work whitout OssApi", E_USER_ERROR); die(); 31 31 } 32 33 require_once('oss_abstract.class.php'); 34 32 35 33 36 /** … … 37 40 * FIXME Clean this class and use facilities provided by OssApi 38 41 */ 39 class OssSearch { 40 41 protected $enginePath; 42 protected $index; 42 class OssSearch extends OssAbstract { 43 43 44 protected $query; 44 45 protected $template; … … 56 57 protected $log; 57 58 protected $customLogs; 58 59 protected $login; 60 protected $apiKey; 59 protected $uniqueKeys; 60 protected $docIds; 61 61 62 62 protected $lastQueryString; … … 69 69 public function __construct($enginePath, $index = NULL, $rows = NULL, $start = NULL, $login = NULL, $apiKey = NULL) { 70 70 71 $ossAPI = new OssApi($enginePath, $index); 72 73 $this->enginePath = $ossAPI->getEnginePath(); 74 $this->index = $ossAPI->getIndex(); 75 76 $this->credential($login, $apiKey); 71 $this->init($enginePath, $index, $login, $apiKey); 77 72 78 73 $this->rows($rows); … … 85 80 $this->collapse = array('field' => NULL, 'max' => NULL, 'mode' => NULL); 86 81 $this->moreLikeThis = array('active' => NULL, 'docquery' => NULL, 'minwordlen' => NULL, 87 'maxwordlen' => NULL, 'mindocfreq' => NULL, 'mintermfreq' => NULL, 'stopwords' => NULL);82 'maxwordlen' => NULL, 'mindocfreq' => NULL, 'mintermfreq' => NULL, 'stopwords' => NULL); 88 83 $this->log = FALSE; 89 84 $this->customLogs = array(); 90 } 91 92 /** 93 * Specify the index name to query 94 * @param $index string 95 * @return OssSearch 96 */ 97 public function index($index = NULL) { 98 $this->index = $index; 99 return $this; 85 $this->uniqueKey = array(); 86 $this->docIds = array(); 100 87 } 101 88 … … 143 130 144 131 /** 145 * @param $login string146 * @param $apiKey string147 * If $login is empty, credential is removed148 */149 public function credential($login, $apiKey) {150 // Remove credentials151 if (empty($login)) {152 $this->login = NULL;153 $this->apiKey = NULL;154 return;155 }156 157 // Else parse and affect new credentials158 if (empty($login) || empty($apiKey)) {159 if (class_exists('OssException')) {160 throw new UnexpectedValueException('You must provide a login and an api key to use credential.');161 }162 trigger_error(__CLASS__ . '::' . __METHOD__ . ': You must provide a login and an api key to use credential.', E_USER_ERROR);163 return FALSE;164 }165 166 $this->login = $login;167 $this->apiKey = $apiKey;168 }169 170 /**171 132 * @return OssSearch 172 133 */ … … 197 158 public function sort($fields) { 198 159 foreach ((array)$fields as $field) 199 $this->sort[] = $field;160 $this->sort[] = $field; 200 161 return $this; 201 162 } … … 228 189 * @return OssSearch 229 190 */ 191 public function uniqueKey($uniqueKey = NULL) { 192 $this->uniqueKeys[] = $uniqueKey; 193 return $this; 194 } 195 196 /** 197 * @return OssSearch 198 */ 199 public function docId($docId = NULL) { 200 $this->docIds[] = $docId; 201 return $this; 202 } 203 204 /** 205 * @return OssSearch 206 */ 230 207 public function facet($field, $min = NULL, $multi = FALSE) { 231 208 $this->facet[$field] = array('min' => $min, 'multi' => $multi); … … 238 215 239 216 public function moreLikeThisDocQuery($docQuery) { 240 $this->moreLikeThis['docquery'] = $ active;217 $this->moreLikeThis['docquery'] = $docQuery; 241 218 } 242 219 … … 296 273 $queryChunks = array(); 297 274 298 // If credential provided, include them in the query url299 if (!empty($this->login)) {300 $queryChunks[] = "login=" . $this->login;301 $queryChunks[] = "key=" . $this->apiKey;302 }303 304 275 $queryChunks[] = 'q=' . urlencode((empty($this->query) ? "*:*" : $this->query)); 305 276 306 if (!empty($this->index)) {307 $queryChunks[] = 'use=' . $this->index;308 }309 277 if (!empty($this->template)) { 310 278 $queryChunks[] = 'qt=' . $this->template; 311 279 } 280 312 281 if (!empty($this->lang)) { 313 282 $queryChunks[] = 'lang=' . $this->lang; … … 317 286 $queryChunks[] = 'rows=' . (int) $this->rows; 318 287 } 288 319 289 if ($this->start !== NULL) { 320 290 $queryChunks[] = 'start=' . (int) $this->start; … … 398 368 $queryChunks[] = 'log' . $pos . '=' . urlencode($customLog); 399 369 } 400 return $this->enginePath . '/' . OssApi::API_SELECT . '?' . implode('&', $queryChunks); 401 370 371 // DocID 372 foreach ((array) $this->docIds as $docId) { 373 if (empty($docId)) { 374 continue; 375 } 376 $queryChunks[] = 'id=' . urlencode($docId); 377 } 378 379 // UniqueKey 380 foreach ((array) $this->uniqueKeys as $uniqueKey) { 381 if (empty($uniqueKey)) { 382 continue; 383 } 384 $queryChunks[] = 'uk=' . urlencode($uniqueKey); 385 } 386 return $this->getQueryURL(OssApi::API_SELECT) . '&' . implode('&', $queryChunks); 402 387 } 403 388 } -
opensearchserver-search/trunk/lib/oss_searchtemplate.class.php
r466994 r599025 2 2 /* 3 3 * This file is part of OpenSearchServer. 4 *5 * Copyright (C) 2008-2011 Emmanuel Keller / Jaeksoft6 *7 * http://www.open-search-server.com8 *9 * OpenSearchServer is free software: you can redistribute it and/or modify10 * it under the terms of the GNU General Public License as published by11 * the Free Software Foundation, either version 3 of the License, or12 * (at your option) any later version.13 *14 * OpenSearchServer is distributed in the hope that it will be useful,15 * but WITHOUT ANY WARRANTY; without even the implied warranty of16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17 * GNU General Public License for more details.18 *19 * You should have received a copy of the GNU General Public License20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>.21 */4 * 5 * Copyright (C) 2008-2011 Emmanuel Keller / Jaeksoft 6 * 7 * http://www.open-search-server.com 8 * 9 * OpenSearchServer is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * OpenSearchServer is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with OpenSearchServer. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 22 23 23 … … 31 31 } 32 32 33 class OssSearchTemplate { 33 require_once('oss_abstract.class.php'); 34 34 35 protected $enginePath; 36 protected $index; 35 36 class OssSearchTemplate extends OssAbstract { 37 37 38 protected $query; 38 39 protected $template; 39 40 40 41 public function __construct($enginePath, $index = NULL, $login = NULL, $apiKey = NULL) { 41 $ossAPI = new OssApi($enginePath, $index); 42 $this->enginePath = $ossAPI->getEnginePath(); 43 $this->index = $ossAPI->getIndex(); 44 $this->credential($login, $apiKey); 42 $this->init($enginePath, $index, $login, $apiKey); 45 43 } 46 44 … … 62 60 $params['qt.lang'] = $qtlang; 63 61 } 64 $return = OssApi::queryServerXML($this->getQueryURL(OssApi::API_SEARCH_TEMPLATE, $this->index , OssApi::API_SEARCH_TEMPLATE_CREATE, $params)); 62 $params['cmd'] = OssApi::API_SEARCH_TEMPLATE_CREATE; 63 $return = OssApi::queryServerXML($this->getQueryURL(OssApi::API_SEARCH_TEMPLATE, $params)); 65 64 return $return === FALSE ? FALSE : TRUE; 66 65 } … … 69 68 $params = array("qt.name" => $qtname); 70 69 $params['returnfield']=$returnField; 71 $return = OssApi::queryServerXML($this->getQueryURL(OssApi::API_SEARCH_TEMPLATE, $this->index , OssApi::API_SEARCH_TEMPLATE_SETRETURNFIELD, $params)); 70 $params['cmd'] = OssApi::API_SEARCH_TEMPLATE_SETRETURNFIELD; 71 $return = OssApi::queryServerXML($this->getQueryURL(OssApi::API_SEARCH_TEMPLATE, $params)); 72 72 return $return === FALSE ? FALSE : TRUE; 73 73 } … … 88 88 } 89 89 $params['snippetfield'] = $snippetField; 90 $return = OssApi::queryServerXML($this->getQueryURL(OssApi::API_SEARCH_TEMPLATE, $this->index , OssApi::API_SEARCH_TEMPLATE_SETSNIPPETFIELD, $params)); 90 $params['cmd'] = OssApi::API_SEARCH_TEMPLATE_SETSNIPPETFIELD; 91 $return = OssApi::queryServerXML($this->getQueryURL(OssApi::API_SEARCH_TEMPLATE, $params)); 91 92 return $return === FALSE ? FALSE : TRUE; 92 93 } 93 94 94 public function credential($login, $apiKey) {95 // Remove credentials96 if (empty($login)) {97 $this->login = NULL;98 $this->apiKey = NULL;99 return;100 }101 102 // Else parse and affect new credentials103 if (empty($login) || empty($apiKey)) {104 if (class_exists('OssException')) {105 throw new UnexpectedValueException('You must provide a login and an api key to use credential.');106 }107 trigger_error(__CLASS__ . '::' . __METHOD__ . ': You must provide a login and an api key to use credential.', E_USER_ERROR);108 return FALSE;109 }110 111 $this->login = $login;112 $this->apiKey = $apiKey;113 }114 115 protected function getQueryURL($apiCall, $index = NULL, $cmd = NULL, $options = NULL) {116 117 $path = $this->enginePath . '/' . $apiCall;118 $chunks = array();119 if (!empty($index)) {120 $chunks[] = 'use=' . urlencode($index);121 }122 if (!empty($cmd)) {123 $chunks[] = 'cmd=' . urlencode($cmd);124 }125 // If credential provided, include them in the query url126 if (!empty($this->login)) {127 $chunks[] = "login=" . urlencode($this->login);128 $chunks[] = "key=" . urlencode($this->apiKey);129 }130 131 // Prepare additionnal parameters132 if (is_array($options)) {133 foreach ($options as $argName => $argValue) {134 $chunks[] = $argName . "=" . urlencode($argValue);135 }136 }137 138 $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . implode("&", $chunks);139 140 return $path;141 }142 95 } 143 96 ?>
Note: See TracChangeset
for help on using the changeset viewer.