ASIS(高级社交图像搜索)索引Flickr和Instagram图像,并在两个索引之间提供搜索API。
您正在阅读ASIS API v1的文档。
运行图像搜索组件 Search.gov 的服务器代码在Github上。 使用此repo 来添加其他数据集等功能,或修复错误。
此代码目前已针对 Ruby 2.3 进行了测试。
instagram.yml.example
instagram.yml
flickr.yml.example
flickr.yml
我们使用bundler来管理gem。您可以安装bundler和其他所需的宝石,如下所示:
gem install bundler bundle install
我们正在使用 Elasticsearch (> = 5.6.5)进行全文搜索。在Mac上,使用 Homebrew 可以轻松安装。
$ brew install elasticsearch@5.6
否则,请按照说明下载并运行它。
您通常可以保留elasticsearch.yml中的默认值,但以下情况除外:
Elasticsearch 5.6中默认禁用脚本。将script.inline和script.stored都设置为true:
script.inline
script.stored
true
script: inline: true stored: true
如果尚未安装Docker,请安装Docker。按照说明此处在计算机上安装Docker后,从项目根目录运行以下命令
$ .docker/bin/elasticsearch-docker
这将从docker.elastic.co下载包含elasticsearch = 5.6的docker镜像,运行它,并暴露端口9200& 9300到你的机器。您可以使用以下命令验证您的设置。
$ curl localhost:9200 { "name" : ...random string..., "cluster_name" : "elasticsearch", "cluster_uuid" : ...uuid... "version" : { "number" : "5.6.5", "build_hash" : "6a37571", "build_timestamp" : "2017-12-04T07:50:10.466Z", "build_snapshot" : false, "lucene_version" : "6.6.1" }, "tagline" : "You Know, for Search" }
Sidekiq(见下文)使用 Redis ,因此请确保已安装并运行。
您可以使用某些政府Flickr / Instagram配置文件和MRSS源来引导系统,以查看系统是否正常工作。样本列表在config/instagram_profiles.csv和config/flickr_profiles.csv以及config/mrss_profiles.csv中。
config/instagram_profiles.csv
config/flickr_profiles.csv
config/mrss_profiles.csv
bundle exec rake oasis:seed_profiles
通过定期刷新最后一天的图像,可以使索引保持最新。要通过Rails控制台手动执行此操作:
FlickrPhotosImporter.refresh InstagramPhotosImporter.refresh MrssPhotosImporter.refresh
只要挂钩,Capistrano部署脚本就有,因此这个刷新会在生产环境中通过cron自动进行。
启动服务器并尝试全部。
bundle exec rails s
以下是您刚刚引导的配置文件。注意:Chrome可以很好地打印JSON响应。
http:// localhost:3000 / api / v1 / instagram_profiles.json
http:// localhost:3000 / api / v1 / flickr_profiles.json
http:// localhost:3000 / api / v1 / mrss_profiles.json
您可以通过REST API手动添加新配置文件:
curl -XPOST "http://localhost:3000/api/v1/instagram_profiles.json?username=deptofdefense&id=542835249" curl -XPOST "http://localhost:3000/api/v1/flickr_profiles.json?name=commercegov&id=61913304@N07&profile_type=user" curl -XPOST "http://localhost:3000/api/v1/mrss_profiles.json?url=http%3A%2F%2Fremotesensing.usgs.gov%2Fgallery%2Frss.php%3Fcat%3Dall"
MRSS配置文件与Flickr和Instagram配置文件的工作方式略有不同。创建MRSS配置文件时,Oasis会为其分配一个短名称,您将在执行搜索时使用该名称。 POST请求的JSON结果如下所示:
{ "created_at": "2014-10-26T18:25:21.167+00:00", "updated_at": "2014-10-26T18:25:21.173+00:00", "name": "72", "id": "http:\/\/remotesensing.usgs.gov\/gallery\/rss.php?cat=all" }
我们使用 Sidekiq 进行工作处理。您可以在此处查看排队的所有Flickr和Instagram作业:
http:// localhost:3000 / sidekiq
启动索引编制过程:
bundle exec sidekiq
在Rails控制台中,您可以使用Elasticsearch 查询DSL 手动查询每个索引:
bin/rails c InstagramPhoto.count FlickrPhoto.count MrssPhoto.count InstagramPhoto.all(query:{term:{username:'usinterior'}}) FlickrPhoto.all(query:{term:{owner:'41555360@n03'}}) MrssPhoto.all(query:{term:{mrss_url:'http://remotesensing.usgs.gov/gallery/rss.php?cat=all'}})
混合搜索API接受以下参数:
顶级JSON包含以下字段:
total
offset
suggestion
results
每个结果都包含以下字段:
type
title
url
thumbnail_url
taken_at
我们支持使用JSON格式的API版本控制。当前版本是v1。您可以指定特定的JSON API版本,如下所示:
curl "http://localhost:3000/api/v1/image.json?flickr_groups=1058319@N21&flickr_users=35067687@n04,24662369@n07&instagram_profiles=nasa&mrss_names=72,73&query=earth"
这些服务器需要运行 Elasticsearch 服务器和 Redis 服务器。
bundle exec rspec
我们跟踪代码库的测试覆盖率,以帮助确定我们可以编写更好的测试的区域,以及查看引入测试不良的代码的时间。
运行测试后,打开coverage/index.html查看报告。
coverage/index.html
点击有<的文件100%覆盖率,以查看未行使的线路。
我们“吃自己的狗粮”并使用此ASIS API在使用 Search.gov 的政府网站上显示图像结果。
在DOI.gov 上查看搜索 moon 的搜索结果。
您可以通过 Github Issues 发送反馈。
Loren Siebert 和贡献者。