diff --git a/config/vufind/LibGuides.ini b/config/vufind/LibGuides.ini index 54198755ff02ddc0d4ac03353a3ad2c5cc2a0179..7259b38f9df73d078309134eaf4c4f4558fd27d3 100644 --- a/config/vufind/LibGuides.ini +++ b/config/vufind/LibGuides.ini @@ -3,9 +3,12 @@ ; HTTP timeout timeout = 30 -; Your institution id +; Your institution id (called site id in api version 2; may have changed w/ upgrade) iid = my-id +; API version to use (1 or 2) +version = 1 + ; This section controls the result limit options for search results. default_limit ; sets the default number of results per page. limit_options is a comma-separated ; list of numbers to be presented to the end-user. If only one limit is required, diff --git a/module/VuFind/src/VuFind/Search/Factory/LibGuidesBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/LibGuidesBackendFactory.php index 64fe2b83d52c4c533e3fde6a8ae4e86105082e0a..9050ca8512206010eb5e2fe058d1f8e06a0f8d95 100644 --- a/module/VuFind/src/VuFind/Search/Factory/LibGuidesBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/LibGuidesBackendFactory.php @@ -120,12 +120,16 @@ class LibGuidesBackendFactory implements FactoryInterface $iid = isset($this->libGuidesConfig->General->iid) ? $this->libGuidesConfig->General->iid : null; + // Pick version: + $ver = isset($this->libGuidesConfig->General->version) + ? $this->libGuidesConfig->General->version : 1; + // Build HTTP client: $client = $this->serviceLocator->get('VuFind\Http')->createClient(); $timeout = isset($this->libGuidesConfig->General->timeout) ? $this->libGuidesConfig->General->timeout : 30; $client->setOptions(array('timeout' => $timeout)); - $connector = new Connector($iid, $client); + $connector = new Connector($iid, $client, $ver); $connector->setLogger($this->logger); return $connector; } diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/LibGuides/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/LibGuides/Connector.php index 79b3560d81881433c4a172c16765609eb604d18d..74a15a60decaf155b53eabb08421306ce87e134e 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/LibGuides/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/LibGuides/Connector.php @@ -71,17 +71,30 @@ class Connector */ protected $host; + /** + * API version number + * + * @var float + */ + protected $apiVersion; + /** * Constructor * * Sets up the LibGuides Client * - * @param string $iid Institution ID - * @param HttpClient $client HTTP client + * @param string $iid Institution ID + * @param HttpClient $client HTTP client + * @param float $apiVersion API version number */ - public function __construct($iid, $client) + public function __construct($iid, $client, $apiVersion = 1) { - $this->host = "http://api.libguides.com/api_search.php?"; + $this->apiVersion = $apiVersion; + if ($this->apiVersion < 2) { + $this->host = "http://api.libguides.com/api_search.php?"; + } else { + $this->host = "http://lgapi.libapps.com/widgets.php?"; + } $this->iid = $iid; $this->client = $client; } @@ -113,14 +126,7 @@ class Connector */ public function query(array $params, $offset = 0, $limit = 20, $returnErr = true) { - // defaults for params - $args = array( - 'iid' => $this->iid, - 'type' => 'guides', - 'more' => 'false', - 'sortby' => 'relevance', - ); - $args = array_merge($args, $params); + $args = $this->prepareParams($params); // run search, deal with exceptions try { @@ -210,4 +216,46 @@ class Connector return $results; } + + /** + * Prepare API parameters + * + * @param array $params Incoming parameters + * + * @return array + */ + protected function prepareParams(array $params) + { + // defaults for params (vary by version) + if ($this->apiVersion < 2) { + $args = array( + 'iid' => $this->iid, + 'type' => 'guides', + 'more' => 'false', + 'sortby' => 'relevance', + ); + } else { + $args = array( + 'site_id' => $this->iid, + 'sort_by' => 'relevance', + 'widget_type' => 1, + 'search_match' => 2, + 'search_type' => 0, + 'sort_by' => 'relevance', + 'list_format' => 1, + 'output_format' => 1, + 'load_type' => 2, + 'enable_description' => 0, + 'enable_group_search_limit' => 0, + 'enable_subject_search_limit' => 0, + 'widget_embed_type' => 2, + ); + // remap v1 --> v2 params: + if (isset($params['search'])) { + $params['search_terms'] = $params['search']; + unset($params['search']); + } + } + return array_merge($args, $params); + } }