ritterg/sru-ao 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ritterg/sru-ao

Composer 安装命令:

composer require ritterg/sru-ao

包简介

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

README 文档

README

Latest Stable Version License Gerold Ritter

SRU-AO is a PHP & 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

  • Composer

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

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

$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

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" => "<="
  ]
  "limit" => 50
]

Take these parameters and build the query for your database.

SruResponse

use Ritterg\SruAo\SruQuery;

$sruresponse = new SruResponse;
$xml = $sruresponse->composeSruResponse($results, $totalcount, $keys);

$xml will be an XML string suitable to return to archives-online.org.

Parameters

$results is the array of records that you want to send to archives-online.org.

archives-online.org has 13 fields per record

  • reference: the reference/signature of the archival unit
  • title: the title of the archival unit
  • date: the date string of the archival unit
  • descriptionlevel: the level of description of the archival unit
  • extent: the extent/size/count of the archival unit
  • creator: the creator/author of the archival unit
  • score: the relevance of the record regarding the search query (0 - 1)
  • link: a direct link to the detail page for the archival unit
  • beginDateISO: the start date of the archival unit in ISO format YYYY-MM-DD
  • beginApprox: true if the start date is approximate, false if the date is exact
  • endDateISO: the end date of the archival unit in ISO format YYYY-MM-DD
  • endApprox: true if the start date is approximate, false if the date is exact
  • hasDigitizedItems: true if the archival unit has digitized items attached, false otherwise (this field is optional)

$totalcount is the number of total results in your database.
An SRU query contains a parameter "maximumRecords" to indicate how many results should be returned. If your query has more results, you can return the number of total results in $totalcount.

$keys is an array of alternative array keys. If your results have different keys than the standard SRU keys, you can add an array of keys to match your keys with the standard keys.

If you have e.g. German keys in your results array, a $keys array could look like this:

$keys = [
'reference' => 'signatur',
'title' => 'titel',
'date' => 'datum',
'descriptionlevel' => 'stufe',
'extend' => 'umfang',
'creator' => 'autor',
'score' => 'relevanz',
'link' => 'url',
'beginDateISO' => 'anfangsdatum',
'beginApprox' => 'anfangca',
'endDateISO' => 'enddatum',
'endApprox' => 'endca',
'hasDigitizedItems' => 'digitalisate',
];

Check your XML-response with https://archives-online.org/srutest

Test

To run the tests, run the following command from the project folder.

$ ./vendor/bin/phpunit

Links

Credits

License

The MIT License (MIT). See the License File for more information.

ritterg/sru-ao 适用场景与选型建议

ritterg/sru-ao 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 172 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「sru」 「Archives Online」 「archivesonline.org」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ritterg/sru-ao 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ritterg/sru-ao 我们能提供哪些服务?
定制开发 / 二次开发

基于 ritterg/sru-ao 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 172
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-21