Plugin Directory

Changeset 599025


Ignore:
Timestamp:
09/14/2012 03:09:07 PM (13 years ago)
Author:
ekeller
Message:

Upgrade last OpenSearchServer PHP library

Location:
opensearchserver-search/trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • opensearchserver-search/trunk/index.php

    r598060 r599025  
    66 Author: Naveen.A.N
    77 Requires at least: 3.0.0
    8  Tested up to: 3.1.3
    9  Version:1.0.6
     8 Tested up to: 3.4.2
     9 Version:1.0.7
    1010 */
    1111require_once 'lib/oss_api.class.php';
     
    7373        $table_name =$wpdb->prefix ."opensearchserver";
    7474        $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');
    8484        $searchTemplate->createSearchTemplate("search",'    title:($$)^10 OR title:("$$")^10
    8585                OR
  • opensearchserver-search/trunk/lib/oss_api.class.php

    r466994 r599025  
    11<?php
    22/*
    3 *  This file is part of OpenSearchServer.
     3 *  This file is part of OpenSearchServer.
    44*
    5 *  Copyright (C) 2008-2011 Emmanuel Keller / Jaeksoft
     5*  Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft
    66*
    77*  http://www.open-search-server.com
     
    4747 */
    4848
    49 
    50 class OssApi {
     49require_once('oss_abstract.class.php');
     50
     51class OssApi extends OssAbstract {
    5152
    5253  const API_SELECT   = 'select';
     
    5455  const API_DELETE   = 'delete';
    5556  const API_OPTIMIZE = 'optimize';
    56   //const API_RELOAD   = 'reload';
     57  const API_RELOAD   = 'reload';
    5758  const API_INDEX    = 'index';
    5859  const API_ENGINE   = 'engine';
     
    8687   */
    8788  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"
    105106  );
    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;
    118107
    119108  /**
     
    124113  public function __construct($enginePath, $index = NULL, $login = NULL, $apiKey = NULL) {
    125114
    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
    136117  }
    137118
     
    148129  public function getIndex() {
    149130    return $this->index;
    150   }
    151 
    152   /**
    153    * Assign credential information for the next queries
    154    * @param $login string
    155    * @param $apiKey string
    156    * If $login is empty, credential is removed
    157    */
    158   public function credential($login, $apiKey) {
    159     // Remove credentials
    160     if (empty($login)) {
    161       $this->login  = NULL;
    162       $this->apiKey  = NULL;
    163       return;
    164     }
    165 
    166     // Else parse and affect new credentials
    167     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;
    177131  }
    178132
     
    184138   * It's expected to be in the same directory as OssApi.class.php.
    185139   */
    186   public function select($index = NULL) {
    187     $index = $index ? $index : $this->index;
     140  public function select() {
    188141    if (!class_exists('OssSearch')) {
    189142      require(dirname(__FILE__) . '/OssSearch.class.php');
    190143    }
    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);
    192145  }
    193146
    194147  /**
    195148   * 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 instance
    197149   * @return OssSearch
    198150   * @deprecated Use OssApi::select
    199151   */
    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();
    203154  }
    204155
    205156  /**
    206157   * Optimize the index
    207    * param string $index If provided, this index name is used in place of the one defined in the API instance
    208158   * return boolean True on success
    209159   * see OSS Wiki [Web API optimize] documentation before using this method
    210160   * FIXME Provide a link to the OSS WiKi
    211161   */
    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));
    215164    return ($return !== FALSE);
    216165  }
     
    223172   * FIXME See why API have been removed
    224173   */
    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));
    228176    return ($return !== FALSE);
    229   }
    230 
    231   /**
    232    * todo Next release
    233    * ignore
    234    * param string $file
    235    * return NULL
    236    * FIXME See with ekeller if this's api won't be deprecated soon
    237    */
    238   public function push($file) {
    239     // http://localhost:8080/oss/push?use=fileNiet&fileName=test.pdf&version=1
    240177  }
    241178
     
    244181   * param string|string[] $patterns
    245182   * 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 instance
    247183   * return boolean True on success
    248184   */
    249   public function pattern($patterns, $deleteAll = FALSE, $index = NULL) {
    250     $index = $index ? $index : $this->index;
     185  public function pattern($patterns, $deleteAll = FALSE) {
    251186    if (is_array($patterns)) {
    252187      $patterns = implode("\n", $patterns);
    253188    }
    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);
    255190    return ($return !== FALSE);
    256   }
    257 
    258   /**
    259    * Return the url to use with curl
    260    * 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 used
    262    * param string $command The optional command to send to the API call
    263    * param string[] $options Additional query parameters
    264    * return string
    265    * 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 url
    286     if (!empty($this->login)) {
    287       $chunks[] = "login=" . urlencode($this->login);
    288       $chunks[] = "key="  . urlencode($this->apiKey);
    289     }
    290 
    291     // Prepare additionnal parameters
    292     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;
    301191  }
    302192
     
    306196   *                   a DOMDocument or any object that implement the __toString
    307197   *                   magic method
    308    * @param string $index If provided, this index name is used in place of the one defined in the API instance
    309198   * @return boolean True on success
    310199   */
    311   public function update($xml, $index = NULL) {
    312 
    313     $index = $index ? $index : $this->index;
     200  public function update($xml) {
    314201
    315202    // Cast $xml to a string
     
    336223    }
    337224
    338     $return = $this->queryServer($this->getQueryURL(OssApi::API_UPDATE, $index), $xml);
     225    $return = $this->queryServer($this->getQueryURL(OssApi::API_UPDATE), $xml);
    339226    return ($return !== FALSE);
    340227
     
    349236  public function getEngineInformations() {
    350237    $infos = array(
    351       'engine_url'    => $this->enginePath,
    352       'engine_version'  => 'unknown',
    353       'login'        => $this->login,
    354       'apiKey'      => $this->apiKey
     238            'engine_url'    => $this->enginePath,
     239            'engine_version'  => 'unknown',
     240            'login'        => $this->login,
     241            'apiKey'      => $this->apiKey
    355242    );
    356243    return $infos;
     
    364251   * @return string[]
    365252   */
    366   public function getIndexInformations($index = NULL) {
    367     $index = $index ? $index : $this->index;
     253  public function getIndexInformations() {
    368254
    369255    $infos  = array(
    370       'name'  => $index,
    371       'size'  => NULL
     256            'name'  => $index,
     257            'size'  => NULL
    372258    );
    373259
    374260    set_error_handler('OssApi_Dummy_Function', E_ALL);
    375261    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');
    377263    }
    378264    catch (Exception $e) {
     
    395281
    396282    // 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');
    398284    curl_setopt($rcurl, CURLOPT_HTTP_VERSION, '1.0');
    399285    curl_setopt($rcurl, CURLOPT_RETURNTRANSFER, TRUE);
     
    420306   * @todo Recode this method once API is provided
    421307   */
    422   public function isIndexAvailable($index = NULL) {
     308  public function isIndexAvailable($index = NULL,$queryTemplate = NULL) {
    423309    $index = $index ? $index : $this->index;
    424310    // Check if the select api is answering
    425311    set_error_handler('OssApi_Dummy_Function', E_ALL);
    426312    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      }
    428319    }
    429320    catch (Exception $e) {
     
    439330   */
    440331  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));
    442334    $indexes = array();
    443335    foreach ($return->index as $index) {
     
    455347  public function createIndex($index, $template = FALSE) {
    456348
    457     $params = array("index.name" => $index);
     349    $params = array('index.name' => $index);
    458350    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));
    462355    if ($return === FALSE) {
    463356      return FALSE;
     
    468361  /**
    469362   * 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 instance
    471363   * @return SimpleXMLElement|OSS_Schema
    472364   * The schema is provided by the OSS engine as an xml. This xml is actualy the complete configuration of the schema.
    473365   * If you want to manipulate the schema, pass it to OSS_Schema::factoryFromXML(...) for easier access.
    474366   */
    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 
    480372  /**
    481373   * Create or alter a field
     
    485377   * @param string $indexed
    486378   * @param string $termVector
    487    * @param string $index If provided, this index name is used in place of the one defined in the API instance
    488379   * @return boolean
    489380   */
    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) {
    492382    $params = array("field.name" => $name);
    493383    if ($analyzer) {
     
    503393      $params["field.termVector"] = $termVector;
    504394    }
    505     if ($termVector) {
     395    if ($default) {
    506396      $params["field.default"] = $default;
    507397    }
    508     if ($termVector) {
     398    if ($unique) {
    509399      $params["field.unique"] = $unique;
    510400    }
    511401
    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));
    513404
    514405    if ($return === FALSE) {
     
    705596  public static function escape($string) {
    706597    static $escaping = array(
    707     array("+",   "-",   "&&",   "||",  "!",  "(",  ")",  "{",  "}",  "[",  "]",  "^", "\"",  "~",  "*",  "?",  ":", '\\'),
    708     array('\+', '\-', '\&\&', '\|\|', '\!', '\(', '\)', '\{', '\}', '\[', '\]', '\^', '\"', '\~', '\*', '\?', '\:', '\\\\')
     598            array("+",   "-",   "&&",   "||",  "!",  "(",  ")",  "{",  "}",  "[",  "]",  "^", "\"",  "~",  "*",  "?",  ":", '\\'),
     599            array('\+', '\-', '\&\&', '\|\|', '\!', '\(', '\)', '\{', '\}', '\[', '\]', '\^', '\"', '\~', '\*', '\?', '\:', '\\\\')
    709600    );
    710601    return str_replace($escaping[0], $escaping[1], $string);
     
    719610
    720611    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"
    725616    );
    726617    return str_replace($remove, $replacement, $string);
  • opensearchserver-search/trunk/lib/oss_delete.class.php

    r466994 r599025  
    22/*
    33 *  This file is part of OpenSearchServer.
    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  */
     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*/
    2222
    2323/**
     
    3030}
    3131
    32 class OssDelete {
     32require_once('oss_abstract.class.php');
    3333
    34   protected $enginePath;
    35   protected $index;
     34class OssDelete extends OssAbstract {
    3635
    3736  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);
    4238  }
    4339
    4440  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));
    4743    if ($return === FALSE) {
    4844      return FALSE;
     
    5147  }
    5248
    53   public function credential($login, $apiKey) {
    54     // Remove credentials
    55     if (empty($login)) {
    56       $this->login  = NULL;
    57       $this->apiKey  = NULL;
    58       return;
    59     }
    6049
    61     // Else parse and affect new credentials
    62     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 url
    88     if (!empty($this->login)) {
    89       $chunks[] = "login=" . urlencode($this->login);
    90       $chunks[] = "key="  . urlencode($this->apiKey);
    91     }
    92 
    93     // Prepare additionnal parameters
    94     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   }
    10450}
    10551?>
  • opensearchserver-search/trunk/lib/oss_indexdocument.class.php

    r466994 r599025  
    33*  This file is part of OpenSearchServer.
    44*
    5 *  Copyright (C) 2008-2011 Emmanuel Keller / Jaeksoft
     5*  Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft
    66*
    77*  http://www.open-search-server.com
  • opensearchserver-search/trunk/lib/oss_paging.class.php

    r466994 r599025  
    22/*
    33 *  This file is part of OpenSearchServer.
    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  */
     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*/
    2222
    2323/**
     
    103103    $this->resultStart   = (int) $this->oss_result->result['start'];
    104104
    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;
    107107
    108108    if ($this->resultTotal > 1) {
     
    120120      $this->resultPrev = max($this->resultCurrentPage - 1, 0);
    121121      if($this->resultCurrentPage + 1 < $this->resultHigh) {
    122       $this->resultNext = min($this->resultCurrentPage + 1, $this->resultTotal);
     122        $this->resultNext = min($this->resultCurrentPage + 1, $this->resultTotal);
    123123      }
    124124      $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  
    11<?php
    22/*
    3  *  This file is part of OpenSearchServer.
    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  */
     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*/
    2222
    2323if (!extension_loaded('SimpleXML')) {
     
    3939  protected $resultRows;
    4040  protected $resultStart;
    41 
     41  protected $resultCollapsedCount;
    4242
    4343  /**
     
    5252    $this->resultRows = (int)$this->result->result['rows'];
    5353    $this->resultStart = (int)$this->result->result['start'];
    54 
     54    $this->resultCollapsedCount = (int)$this->result->result['collapsedDocCount'];
    5555    if (!function_exists('OssApi_Dummy_Function')) {
    5656      function OssApi_Dummy_Function() {
    5757      }
    5858    }
     59  }
     60  public function getResultCollapsedCount() {
     61    return $this->resultCollapsedCount;
    5962  }
    6063
     
    152155  }
    153156
     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
    154180}
    155181?>
  • opensearchserver-search/trunk/lib/oss_search.class.php

    r466994 r599025  
    22/*
    33 *  This file is part of OpenSearchServer.
    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  */
     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*/
    2222
    2323
     
    3030  trigger_error("OssSearch won't work whitout OssApi", E_USER_ERROR); die();
    3131}
     32
     33require_once('oss_abstract.class.php');
     34
    3235
    3336/**
     
    3740 * FIXME Clean this class and use facilities provided by OssApi
    3841 */
    39 class OssSearch {
    40 
    41   protected $enginePath;
    42   protected $index;
     42class OssSearch extends OssAbstract {
     43
    4344  protected $query;
    4445  protected $template;
     
    5657  protected $log;
    5758  protected $customLogs;
    58 
    59   protected $login;
    60   protected $apiKey;
     59  protected $uniqueKeys;
     60  protected $docIds;
    6161
    6262  protected $lastQueryString;
     
    6969  public function __construct($enginePath, $index = NULL, $rows = NULL, $start = NULL, $login = NULL, $apiKey = NULL) {
    7070
    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);
    7772
    7873    $this->rows($rows);
     
    8580    $this->collapse  = array('field' => NULL, 'max' => NULL, 'mode' => NULL);
    8681    $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);
    8883    $this->log = FALSE;
    8984    $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();
    10087  }
    10188
     
    143130
    144131  /**
    145    * @param $login string
    146    * @param $apiKey string
    147    * If $login is empty, credential is removed
    148    */
    149   public function credential($login, $apiKey) {
    150     // Remove credentials
    151     if (empty($login)) {
    152       $this->login  = NULL;
    153       $this->apiKey  = NULL;
    154       return;
    155     }
    156 
    157     // Else parse and affect new credentials
    158     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   /**
    171132   * @return OssSearch
    172133   */
     
    197158  public function sort($fields) {
    198159    foreach ((array)$fields as $field)
    199     $this->sort[] = $field;
     160      $this->sort[] = $field;
    200161    return $this;
    201162  }
     
    228189   * @return OssSearch
    229190   */
     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   */
    230207  public function facet($field, $min = NULL, $multi = FALSE) {
    231208    $this->facet[$field] = array('min' => $min, 'multi' => $multi);
     
    238215
    239216  public function moreLikeThisDocQuery($docQuery) {
    240     $this->moreLikeThis['docquery'] = $active;
     217    $this->moreLikeThis['docquery'] = $docQuery;
    241218  }
    242219
     
    296273    $queryChunks = array();
    297274
    298     // If credential provided, include them in the query url
    299     if (!empty($this->login)) {
    300       $queryChunks[] = "login=" . $this->login;
    301       $queryChunks[] = "key="   . $this->apiKey;
    302     }
    303 
    304275    $queryChunks[] = 'q=' . urlencode((empty($this->query) ? "*:*" : $this->query));
    305276
    306     if (!empty($this->index)) {
    307       $queryChunks[] = 'use='  . $this->index;
    308     }
    309277    if (!empty($this->template)) {
    310278      $queryChunks[] = 'qt='   . $this->template;
    311279    }
     280
    312281    if (!empty($this->lang)) {
    313282      $queryChunks[] = 'lang=' . $this->lang;
     
    317286      $queryChunks[] = 'rows='  . (int) $this->rows;
    318287    }
     288
    319289    if ($this->start !== NULL) {
    320290      $queryChunks[] = 'start=' . (int) $this->start;
     
    398368      $queryChunks[] = 'log' . $pos . '=' . urlencode($customLog);
    399369    }
    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);
    402387  }
    403388}
  • opensearchserver-search/trunk/lib/oss_searchtemplate.class.php

    r466994 r599025  
    22/*
    33 *  This file is part of OpenSearchServer.
    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  */
     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*/
    2222
    2323
     
    3131}
    3232
    33 class OssSearchTemplate {
     33require_once('oss_abstract.class.php');
    3434
    35   protected $enginePath;
    36   protected $index;
     35
     36class OssSearchTemplate extends OssAbstract {
     37
    3738  protected $query;
    3839  protected $template;
    3940
    4041  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);
    4543  }
    4644
     
    6260      $params['qt.lang'] = $qtlang;
    6361    }
    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));
    6564    return $return === FALSE ? FALSE : TRUE;
    6665  }
     
    6968    $params = array("qt.name" => $qtname);
    7069    $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));
    7272    return $return === FALSE ? FALSE : TRUE;
    7373  }
     
    8888    }
    8989    $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));
    9192    return $return === FALSE ? FALSE : TRUE;
    9293  }
    9394
    94   public function credential($login, $apiKey) {
    95     // Remove credentials
    96     if (empty($login)) {
    97       $this->login  = NULL;
    98       $this->apiKey  = NULL;
    99       return;
    100     }
    101 
    102     // Else parse and affect new credentials
    103     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 url
    126     if (!empty($this->login)) {
    127       $chunks[] = "login=" . urlencode($this->login);
    128       $chunks[] = "key="  . urlencode($this->apiKey);
    129     }
    130 
    131     // Prepare additionnal parameters
    132     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   }
    14295}
    14396?>
Note: See TracChangeset for help on using the changeset viewer.