Plugin Directory

Changeset 610356


Ignore:
Timestamp:
10/10/2012 12:58:56 PM (13 years ago)
Author:
ekeller
Message:
  • Upgrade OpenSearchServer PHP library
  • Fix: A warning log were displayed when no facet was selected
Location:
opensearchserver-search/trunk
Files:
4 added
7 edited

Legend:

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

    r603172 r610356  
    33 Plugin Name: OpenSearchServer
    44 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,
    66 Author: Emmanuel Keller - Naveen.A.N
    77 Author URI: http://open-search-server.com
    88 Tested up to: 3.4.2
    9  Version:1.1.1
     9 Version:1.1.2
    1010 */
    1111require_once 'lib/oss_api.class.php';
  • opensearchserver-search/trunk/lib/oss_abstract.class.php

    r602348 r610356  
    2727  protected $login;
    2828  protected $apiKey;
     29  protected $lastQueryString;
    2930
    3031  public function init($enginePath, $index = NULL, $login = NULL, $apiKey = NULL) {
     
    3334      }
    3435    }
     36    $this->lastQueryString = null;
    3537    $this->enginePath = $enginePath;
    3638    $this->index = $index;
     
    131133  protected function queryServer($url, $data = NULL, $connexionTimeout = OssApi::DEFAULT_CONNEXION_TIMEOUT, $timeout = OssApi::DEFAULT_QUERY_TIMEOUT) {
    132134
     135    $this->lastQueryString = $url;
    133136    // Use CURL to post the data
    134137
     
    139142    curl_setopt($rcurl, CURLOPT_FOLLOWLOCATION, TRUE);
    140143    curl_setopt($rcurl, CURLOPT_MAXREDIRS, 16);
    141     curl_setopt($rcurl, CURLOPT_VERBOSE, TRUE);
     144    curl_setopt($rcurl, CURLOPT_VERBOSE, FALSE);
    142145
    143146    if (is_integer($connexionTimeout) && $connexionTimeout >= 0) {
     
    189192
    190193    return $content;
     194  }
     195
     196  public function getLastQueryString() {
     197    return $this->lastQueryString;
    191198  }
    192199
  • opensearchserver-search/trunk/lib/oss_paging.class.php

    r601998 r610356  
    4646  protected $rowsParameter;
    4747  protected $pageParameter;
     48  protected $paramSeparator;
    4849  const MAX_PAGE_TO_LINK = 10;
    4950
     
    5354   * @return OssApi
    5455   */
    55   public function __construct(SimpleXMLElement $result, $rowsParam = 'rows', $pageParam = 'p') {
     56  public function __construct(SimpleXMLElement $result, $rowsParam = 'rows', $pageParam = 'p', $paramSeparator = '&amp;') {
    5657    $this->oss_result  = $result;
    5758    $this->rowsParameter = $rowsParam;
    5859    $this->pageParameter = $pageParam;
     60    $this->paramSeparator = $paramSeparator;
    5961    self::compute();
    6062
     
    122124        $this->resultNext = min($this->resultCurrentPage + 1, $this->resultTotal);
    123125      }
    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 . '=';
    125128    }
    126129  }
  • opensearchserver-search/trunk/lib/oss_search.class.php

    r603172 r610356  
    2828
    2929require_once(dirname(__FILE__).'/oss_abstract.class.php');
     30require_once(dirname(__FILE__).'/oss_search_abstract.class.php');
    3031
    3132
    3233/**
    33  * @author pmercier <[email protected]>
    3434 * @package OpenSearchServer
    35  * FIXME Complete this documentations
    36  * FIXME Clean this class and use facilities provided by OssApi
    3735 */
    38 class OssSearch extends OssAbstract {
    39 
    40   const API_SELECT   = 'select';
     36class OssSearch extends OssSearchAbstract {
    4137
    4238  protected $query;
    43   protected $template;
    4439  protected $start;
    4540  protected $rows;
    4641  protected $lang;
    4742  protected $filter;
    48   protected $delete;
    4943  protected $field;
    5044  protected $sort;
     
    5246  protected $collapse;
    5347  protected $facet;
    54   protected $sortBy;
    55   protected $moreLikeThis;
    56   protected $log;
    57   protected $customLogs;
    58   protected $uniqueKeys;
    59   protected $docIds;
    6048
    6149  /**
     
    6553   */
    6654  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);
    6956
    7057    $this->rows($rows);
     
    7562    $this->sort    = array();
    7663    $this->facets  = array();
     64    $this->query = NULL;
     65    $this->lang = NULL;
    7766    $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);
    8568  }
    8669
     
    9881   * @return OssSearch
    9982   */
    100   public function template($template = NULL) {
    101     $this->template = $template;
    102     return $this;
    103   }
    104 
    105   /**
    106    * @return OssSearch
    107    */
    10883  public function start($start = NULL) {
    10984    $this->start = $start;
     
    142117  public function lang($lang = NULL) {
    143118    $this->lang = $lang;
    144     return $this;
    145   }
    146 
    147   /**
    148    * @return OssSearch
    149    */
    150   public function delete($delete = TRUE) {
    151     $this->delete = (bool)$delete;
    152119    return $this;
    153120  }
     
    185152    return $this;
    186153  }
     154 
     155  /**
     156   * @return OssSearch
     157   */
     158  public function collapseType($type) {
     159    $this->collapse['type'] = $type;
     160    return $this;
     161  }
     162 
    187163
    188164  /**
     
    197173   * @return OssSearch
    198174   */
    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     
    273185    $queryChunks[] = 'q=' . urlencode((empty($this->query) ? "*:*" : $this->query));
    274 
    275     if (!empty($this->template)) {
    276       $queryChunks[] = 'qt='   . $this->template;
    277     }
    278186
    279187    if (!empty($this->lang)) {
     
    291199    if ($this->operator !== NULL) {
    292200      $queryChunks[] = 'operator=' . $this->operator;
    293     }
    294 
    295     if ($this->delete) {
    296       $queryChunks[] = 'delete';
    297201    }
    298202
     
    321225    // Facets
    322226    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;
    329240    }
    330241
     
    333244      $queryChunks[] = 'collapse.field=' . $this->collapse['field'];
    334245    }
     246    if ($this->collapse['type']) {
     247        $queryChunks[] = 'collapse.type=' . $this->collapse['type'];
     248    }
    335249    if ($this->collapse['mode'] !== NULL) {
    336250      $queryChunks[] = 'collapse.mode=' . $this->collapse['mode'];
     
    340254    }
    341255
    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;
    389257  }
    390258}
  • opensearchserver-search/trunk/lib/oss_searchtemplate.class.php

    r603172 r610356  
    7676    return $return === FALSE ? FALSE : TRUE;
    7777  }
    78   /*
     78
     79  /**
    7980   * Function to create spell check Query Template
    80   * $qtsuggestions - No of suggestions to be returned
    81   * $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)LevensteinDistance
    85   *               2)NGramDistance
    86   *               3)JaroWinklerDistance
    87   */
     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   */
    8889  public function createSpellCheckTemplate($qtname, $qtquery = NULL, $qtsuggestions = NULL, $qtfield = NULL, $qtscore = NULL, $qtlang = NULL, $qtalgorithm = NULL) {
    8990    $params = array("qt.name" => $qtname);
     
    141142  }
    142143
     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
    143198}
    144199?>
  • opensearchserver-search/trunk/opensearchserver_search_functions.php

    r603172 r610356  
    9999function opensearchserver_add_facets_search($search) {
    100100  $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    }
    103105  }
    104106  return $search;
  • opensearchserver-search/trunk/template/opensearchserver_search.php

    r602348 r610356  
    5555    <div id="oss-filter">
    5656        <?php $facets = get_option('oss_facet');
     57        if (isset($facet) && $facet != null) {
    5758        foreach ($facets as $facet) {
    5859          $facet_results = $oss_result_facets->getFacet($facet);
     
    8384        </ul>
    8485        <?php
     86    }
    8587}?>
    8688    </div>
Note: See TracChangeset for help on using the changeset viewer.