PHPackages                             ritterg/sru-ao - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ritterg/sru-ao

ActiveLibrary[API Development](/categories/api)

ritterg/sru-ao
==============

Helper package to implement the SRU interface used by archivesonline.org

v1.0.1(4y ago)0170MITPHPPHP ^7.2.5CI passing

Since Jun 8Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/ritterg/sru-ao)[ Packagist](https://packagist.org/packages/ritterg/sru-ao)[ RSS](/packages/ritterg-sru-ao/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

SRU Implementation for Archives Online
======================================

[](#sru-implementation-for-archives-online)

[![Latest Stable Version](https://camo.githubusercontent.com/928d796d3b22716de65c42bbf02597cbccf9fe43e0d8ddd6b717137be1094059/68747470733a2f2f706f7365722e707567782e6f72672f726974746572672f7372752d616f2f762f737461626c65)](https://packagist.org/packages/ritterg/sru-ao)[![License](https://camo.githubusercontent.com/3aa80119908146dc632b5ff4244286c40ea03d5f872f62cba9c13cebc07757e1/68747470733a2f2f706f7365722e707567782e6f72672f726974746572672f7372752d616f2f6c6963656e7365)](https://packagist.org/packages/ritterg/sru-ao)[![Gerold Ritter](https://camo.githubusercontent.com/9775b5c97d8eb8dd2d0e5a3f9bd8901c7ebe16f747d9761c02a9cfa60df75403/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f417574686f722d4765726f6c642532305269747465722d6f72616e67652e737667)](http://www.e-hist.ch)

**SRU-AO** is a PHP &amp; Laravel package to facilitate the implementation of an archives-online.org compatible SRU interfaces to your archival database.

- Feed the archives-online.org query to the SruQuery::getQueryParams function and it will parse the query and return an array of fields and operators.
- Provide an array with query results to the SruResponse::composeSruResponse function and it will return a formatted an valid XML-Response you can serve to the archives-online.org query.

Software Requirement
--------------------

[](#software-requirement)

- Composer

Installation Steps
------------------

[](#installation-steps)

Just require ritterg/sru-ao within your project

1. `composer require ritterg/sru-ao`
2. make sure everything is OK by running the tests `phpunit`

Usage
-----

[](#usage)

### SruQuery

[](#sruquery)

archives-online.org SRU queries come in a special format like `https://server.tld/SRU?operation=searchretrieve&version=1.2&query=Serverchoice%20all%20%22Switzerland%20Germany%22%20AND%20isad.date%20WITHIN%20%221000%202000%22&maximumRecords=50`The SruQuery class helps you to parse this query.

```
use Ritterg\SruAo\SruQuery;

$sruquery = new SruQuery;
$searchparams = $sruquery->getQueryParams($request, $allowedfields = null, $allowedoperators = null);
```

`$searchparams` will be an array with all the sanitized and renamed query parameters from the sru query.

#### Parameters

[](#parameters)

`$request` is the array of input parameters from the query (i.e. $\_GET).

`$allowedfields` is an array of allowed query fields and the string they should be renamed to. Default values are

```
$allowedfields = [
	'Serverchoice' => 'fulltext',
	'isad.reference' => 'reference',
	'isad.title' => 'title',
	'isad.date' => 'date',
];
```

`$allowedoperators` is an array of allowed operators and the string they should be rewritten to. Default values are

```
$allowedoperators = [
	'all' => 'AND',
	'any' => 'OR',
	'adj' => 'ADJ',
	'=' => 'LIKE',
	'==' => 'LIKE',
	'===' => '=',
	'WITHIN' => '='
];
```

You can override these defaults with walues that best fit your database

#### Result

[](#result)

The result is an array with all query parameters. For each parameter, there is another array with the value and the operator.

For the query above the result would be

```
$searchparams = [
  "fulltext" => [
    "value" => "Switzerland Germany"
    "operator" => "AND"
  ]
  "date_start" => [
    "value" => "1000-01-01"
    "operator" => ">="
  ]
  "date_end" => [
    "value" => "2000-12-31"
    "operator" => "
