PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/GoblinClient/goblinclient.php

https://github.com/tehsis/Goblin
PHP | 70 lines | 37 code | 7 blank | 26 comment | 3 complexity | 8bd535f7986988cfe6a52d649a0efd3c MD5 | raw file
  1. <?php
  2. /*
  3. * Name: The Goblin Search Client
  4. * Author: Pablo E. Terradillos <tehsis@gmail.com>
  5. * Description: This is (or try to be) an API Client for The Goblin Search Engine.
  6. * It relies on the SOAP interface.
  7. *
  8. * Copyright 2010 Pablo Terradillos <tehsis@gmail.com>
  9. *
  10. * This file is part of "The Goblin search engine".
  11. *
  12. * "The Goblin search engine" is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * "The Goblin Search Engine" is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with "The Goblin Search Engine". If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. class GoblinClient {
  27. private $client;
  28. private $found;
  29. private $time;
  30. // To make a new Client object, you need to provide the uri and proxy of
  31. // the Soap server
  32. public function __construct($uri,$proxy) {
  33. $this->client = new SoapClient(null,array("location"=>$proxy,"uri"=>$uri));
  34. }
  35. public function search($tags) {
  36. $timeBefore = microtime(true);
  37. $this->found = $this->client->hsearch(explode(" ",$tags));
  38. $timeAfter = microtime(true);
  39. $this->time = $timeAfter - $timeBefore;
  40. return $this->found;
  41. }
  42. public function search_memcache($tags) {
  43. $timeBefore = microtime(true);
  44. $memcache_obj = new Memcache;
  45. $memcache_obj->connect('localhost',11211);
  46. if(strcmp($memcache_obj->get('LastTag'),$tags) == 0) {
  47. $this->found = $memcache_obj->get('search');
  48. } else {
  49. $memcache_obj->replace('LastTag', $tags,0,0);
  50. $this->found = $this->client->hsearch(explode(" ",$tags));
  51. $memcache_obj->set('search',$this->found,0,0);
  52. }
  53. $timeAfter = microtime(true);
  54. $this->time = $timeAfter - $timeBefore;
  55. return $this->found;
  56. }
  57. public function found() {
  58. return $this->found;
  59. }
  60. public function time() {
  61. return $this->time;
  62. }
  63. }