Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,12 @@ Have a look at the [API documentation](http://api.archives-ouvertes.fr/docs/sear
<td>fl / fields</td>
<td>Fields to return. Ex: "*", "docid, country_s", ["docid", "country_s"]</td>
</tr>
<tr>
<td>host</td>
<td>Host of the API (optional default to public API: http://api.archives-ouvertes.fr)</td>
</tr>
<tr>
<td>core</td>
<td>API core: `search`, `ref/instance`, `hal` (hal team internal use). Default to `search`.</td>
</tr>
</table>
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ exports.findOne = function (search, options, callback) {
exports.query(search, options, function (err, result) {
if (err) { return callback(err); }

if (result.response && Array.isArray(result.response.docs)) {
if (result.response && Array.isArray(result.response.docs) && result.response.docs.length === 1) {
callback(null, result.response.docs[0]);
} else {
callback(new Error('unexpected result, documents not found'));
Expand Down Expand Up @@ -130,9 +130,13 @@ exports.query = function (search, options, callback) {
}

// query link
let url = options.core
? `http://ccsdsolrvip.in2p3.fr:8080/solr/${options.core}/select?&wt=json&q=${encodeURIComponent(query)}`
: `http://api.archives-ouvertes.fr/search/?wt=json&q=${encodeURIComponent(query)}`;
const host = options.host || "http://api.archives-ouvertes.fr";
let url =
options.core === "hal"
? `${host}/solr/hal/api/selectall?wt=json&q=${encodeURIComponent(query)}`
: `${host}/${options.core || "search"}/?wt=json&q=${encodeURIComponent(
query
)}`;

// for convenience, add fields as an alias for fl
if (options.fields) {
Expand All @@ -146,7 +150,8 @@ exports.query = function (search, options, callback) {

// append options to the query (ex: start=1, rows=10)
for (const p in options) {
url += `&${p}=${options[p]}`;
if (p !== "core")
url += `&${p}=${options[p]}`;
}
axios.get(url, requestOptions).then(response => {
if (response.status !== 200) {
Expand Down
Loading