NuGet API v3 検索系 API
NuGet API v3 のまともなドキュメントが見当たらないのでソース読みながらメモしていきたいと思います。
一応仕様書はあるみたいだけど、 API を利用する側には一切役にたたなさそう。
API v3 Specification · NuGet/NuGetGallery Wiki · GitHub
というわけで第一発目(続きはあるのだろうか)は検索 API。サーバーサイドのソースコードはこれっぽいです。 OWIN で動いています。
公開されている API リスト
https://api.nuget.org/v3/index.json で利用できる API の一覧が取得できます。このように公開されているということは、将来 URI が変わる可能性もあるということでしょうか?
今回対象にする NuGet.Services.Search のサーバーはこれらのようです。
両方とも index.json に表記されているバージョンは同じようなので負担分散用でしょうか。
また検索 API ではすべてのリクエストで callback パラメータを指定することで JSONP として取得することができます。
/find
5日前にコミットされたばかりで、まだサーバーのほうでは動いていないようですが、これから利用可能になると思われる API です。
/find?id=PackageId
で
{"registration": "https://az320820.vo.msecnd.net/registrations-1/packageid/index.json"}
か、存在しないパッケージなら 404 が返ります。この URI にアクセスするとそのパッケージのすべてのバージョンのパッケージ情報が取得できます。 registration まわりについては次回あたり書くかもしれないし、書かないかもしれません。
書きました
/query
メインの検索 API です。
パラメータ
- skip
- 検索結果から指定した件数を飛ばします。ページみたいに使えばいいと思う。デフォルト 0
- take
- 取得する件数を指定します。デフォルト 20
- countOnly
- 未使用。デフォルト false
- prerelease
- true を指定すると pre-release のパッケージも検索結果に含まれるようになります。またレスポンスの version フィールドの値も最新の pre-release がある場合、そちらが使われます。デフォルト false
- explanation
- true を指定するとレスポンスに explanation フィールドが追加されて、 Lucene.Net 内でのランクなどの情報が取得できるようになります。デフォルト false
- projectType
- 未使用。
- supportedFramework
- 挙動不明。というかバグってる気がする
- q
- クエリ。指定しないと適当(人気順?)なのが返ってきます。
例
https://api-v3search-0.nuget.org/query?q=json&take=1&explanation=true
{ "@context": { "@vocab": "http://schema.nuget.org/schema#" }, "totalHits": 616, "lastReopen": "2015-03-01T13:59:05.2920090Z", "index": "v3-lucene0", "data": [ { "@id": "https://api.nuget.org/v3/registration0/newtonsoft.json/6.0.8.json", "@type": "Package", "registration": "https://api.nuget.org/v3/registration0/newtonsoft.json/index.json", "id": "Newtonsoft.Json", "description": "Json.NET is a popular high-performance JSON framework for .NET", "tags": [ "json" ], "authors": [ "" ], "version": "6.0.8", "versions": [ { "version": "7.0.1-beta1", "downloads": 5519, "@id": "https://api.nuget.org/v3/registration0/newtonsoft.json/7.0.1-beta1.json" }, /* バージョン多すぎるので省略 */ ], "explanation": "8.427921 = (MATCH) rank(Id:json Version:json TokenizedId:json ShingledId:json Title:json^2.0 Tags:json Description:json Authors:json Owners:json), product of:\n 8.427921 = (MATCH) product of:\n 15.17026 = (MATCH) sum of:\n 2.567175 = (MATCH) weight(TokenizedId:json in 95325), product of:\n 0.1995539 = queryWeight(TokenizedId:json), product of:\n 6.432285 = idf(docFreq=1456, maxDocs=333174)\n 0.03102379 = queryNorm\n 12.86457 = (MATCH) fieldWeight(TokenizedId:json in 95325), product of:\n 1 = tf(termFreq(TokenizedId:json)=1)\n 6.432285 = idf(docFreq=1456, maxDocs=333174)\n 2 = fieldNorm(field=TokenizedId, doc=95325)\n 3.319667 = (MATCH) weight(ShingledId:json in 95325), product of:\n 0.2269236 = queryWeight(ShingledId:json), product of:\n 7.314503 = idf(docFreq=602, maxDocs=333174)\n 0.03102379 = queryNorm\n 14.62901 = (MATCH) fieldWeight(ShingledId:json in 95325), product of:\n 1 = tf(termFreq(ShingledId:json)=1)\n 7.314503 = idf(docFreq=602, maxDocs=333174)\n 2 = fieldNorm(field=ShingledId, doc=95325)\n 7.416509 = (MATCH) weight(Title:json^2.0 in 95325), product of:\n 0.3916531 = queryWeight(Title:json^2.0), product of:\n 2 = boost\n 6.312141 = idf(docFreq=1642, maxDocs=333174)\n 0.03102379 = queryNorm\n 18.93642 = (MATCH) fieldWeight(Title:json in 95325), product of:\n 1 = tf(termFreq(Title:json)=1)\n 6.312141 = idf(docFreq=1642, maxDocs=333174)\n 3 = fieldNorm(field=Title, doc=95325)\n 1.458894 = (MATCH) weight(Tags:json in 95325), product of:\n 0.1737056 = queryWeight(Tags:json), product of:\n 5.599108 = idf(docFreq=3351, maxDocs=333174)\n 0.03102379 = queryNorm\n 8.398662 = (MATCH) fieldWeight(Tags:json in 95325), product of:\n 1 = tf(termFreq(Tags:json)=1)\n 5.599108 = idf(docFreq=3351, maxDocs=333174)\n 1.5 = fieldNorm(field=Tags, doc=95325)\n 0.4080127 = (MATCH) weight(Description:json in 95325), product of:\n 0.1692395 = queryWeight(Description:json), product of:\n 5.455152 = idf(docFreq=3870, maxDocs=333174)\n 0.03102379 = queryNorm\n 2.410859 = (MATCH) fieldWeight(Description:json in 95325), product of:\n 1.414214 = tf(termFreq(Description:json)=2)\n 5.455152 = idf(docFreq=3870, maxDocs=333174)\n 0.3125 = fieldNorm(field=Description, doc=95325)\n 0.5555556 = coord(5/9)\n 1 = queryBoost\n" } ] }
/autocomplete
query のパッケージ ID だけ返すバージョンです。
パラメータ
- skip
- 検索結果から指定した件数を飛ばします。デフォルト 0
- take
- 取得する件数を指定します。デフォルト 20
- prerelease
- true を指定すると pre-release のパッケージも検索結果に含まれるようになります。デフォルト false
- explanation
- true を指定するとレスポンスに explanations フィールドが追加されて、 Lucene.Net 内でのランクなどの情報が取得できるようになります。デフォルト false
- supportedFramework
- 挙動不明。
- q
- クエリ。指定しないと適当(ID 順?)なのが返ってきます。
- id
- パッケージ ID。これを指定するとそのパッケージのバージョン一覧が返ってきます。 q を同時に指定すると q が優先されます。また他のパラメータは(prerelease も含めて)無視されます。
例1
https://api-v3search-0.nuget.org/autocomplete?q=twitter&explanation=true&take=2
{ "@context": { "@vocab": "http://schema.nuget.org/schema#" }, "totalHits": 108, "indexName": "v3-lucene0", "data": [ "Twitter.Bootstrap", "Microsoft.Owin.Security.Twitter" ], "explanations": [ "10.67276 = (MATCH) rank(IdAutocomplete:\"t tw twi twit twitt twitte twitter\"), product of:\n 10.67276 = weight(IdAutocomplete:\"t tw twi twit twitt twitte twitter\" in 29089), product of:\n 0.9999999 = queryWeight(IdAutocomplete:\"t tw twi twit twitt twitte twitter\"), product of:\n 42.69106 = idf(IdAutocomplete: t=55981 tw=1558 twi=1247 twit=1081 twitt=1068 twitte=1068 twitter=1068)\n 0.02342411 = queryNorm\n 10.67276 = fieldWeight(IdAutocomplete:\"t tw twi twit twitt twitte twitter\" in 29089), product of:\n 1 = tf(phraseFreq=1)\n 42.69106 = idf(IdAutocomplete: t=55981 tw=1558 twi=1247 twit=1081 twitt=1068 twitte=1068 twitter=1068)\n 0.25 = fieldNorm(field=IdAutocomplete, doc=29089)\n 1 = queryBoost\n", "8.004572 = (MATCH) rank(IdAutocomplete:\"t tw twi twit twitt twitte twitter\"), product of:\n 8.004572 = weight(IdAutocomplete:\"t tw twi twit twitt twitte twitter\" in 155), product of:\n 0.9999999 = queryWeight(IdAutocomplete:\"t tw twi twit twitt twitte twitter\"), product of:\n 42.69106 = idf(IdAutocomplete: t=55981 tw=1558 twi=1247 twit=1081 twitt=1068 twitte=1068 twitter=1068)\n 0.02342411 = queryNorm\n 8.004573 = fieldWeight(IdAutocomplete:\"t tw twi twit twitt twitte twitter\" in 155), product of:\n 1 = tf(phraseFreq=1)\n 42.69106 = idf(IdAutocomplete: t=55981 tw=1558 twi=1247 twit=1081 twitt=1068 twitte=1068 twitter=1068)\n 0.1875 = fieldNorm(field=IdAutocomplete, doc=155)\n 1 = queryBoost\n" ] }
例2
https://api-v3search-0.nuget.org/autocomplete?id=newtonsoft.json
{ "@context": { "@vocab": "http://schema.nuget.org/schema#" }, "indexName": "v3-lucene0", "totalHits": 37, "data": [ "7.0.1-beta1", "6.0.8", "6.0.7", "6.0.6", "6.0.5", "6.0.4", "6.0.3", "6.0.2", "6.0.1", "5.0.8", "5.0.7", "5.0.6", "5.0.5", "5.0.4", "5.0.3", "5.0.2", "5.0.1", "4.5.11", "4.5.10", "4.5.9", "4.5.8", "4.5.7", "4.5.6", "4.5.5", "4.5.4", "4.5.3", "4.5.2", "4.5.1", "4.0.8", "4.0.7", "4.0.6", "4.0.5", "4.0.4", "4.0.3", "4.0.2", "4.0.1", "3.5.8" ] }
/targetframeworks
未実装っぽい。
https://api-v3search-0.nuget.org/targetframeworks
[]
/segments
Lucene のセグメントを取得します。どうみてもデバッグ用。
https://api-v3search-0.nuget.org/segments
[ { "segment": "_65t", "documents": 98164 }, { "segment": "_bem", "documents": 96790 }, { "segment": "_g8s", "documents": 96087 }, { "segment": "_goo", "documents": 9121 }, { "segment": "_h53", "documents": 8237 }, { "segment": "_h6h", "documents": 730 }, { "segment": "_h7w", "documents": 729 }, { "segment": "_h9v", "documents": 670 }, { "segment": "_i3n", "documents": 1178 }, { "segment": "_i97", "documents": 1740 }, { "segment": "_ji8", "documents": 1403 }, { "segment": "_l23", "documents": 1760 }, { "segment": "_lvk", "documents": 944 }, { "segment": "_mo7", "documents": 1087 }, { "segment": "_nvl", "documents": 1464 }, { "segment": "_on3", "documents": 920 }, { "segment": "_pew", "documents": 903 }, { "segment": "_pmp", "documents": 240 }, { "segment": "_pmq", "documents": 1 }, { "segment": "_pmr", "documents": 1 } ]
/stats
Lucene の実行状況を取得します。
https://api-v3search-0.nuget.org/stats
{ "numDocs": 322169, "indexName": "v3-lucene0", "lastReopen": "2015-03-01T14:40:54.9314634Z" }