Skip to content

Commit

Permalink
QBuilder: added/tested all sensible fields
Browse files Browse the repository at this point in the history
  • Loading branch information
romanchyla authored and aholachek committed Sep 24, 2015
1 parent e648b71 commit 38aa478
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 15 deletions.
2 changes: 1 addition & 1 deletion local-config.json.default
Expand Up @@ -2,7 +2,7 @@
"port_development": 8000,
"port_production": 8000,
"api_endpoint": "http://localhost:3000/api/1",
"solr_endpoint": "http://adswhy.cfa.harvard.edu:9000/solr/select",
"solr_endpoint": "http://localhost:8984/solr/select",
"orcid_oauth_cliend_id": "APP-P5ANJTQRRTMA6GXZ",
"orcid_oauth_client_secret": "989e54c8-7093-4128-935f-30c19ed9158c",
"orcid_api_endpoint": "https://api.sandbox.orcid.org",
Expand Down
4 changes: 2 additions & 2 deletions server.js
Expand Up @@ -14,7 +14,7 @@ var url = require('url');
var needle = require('needle');
var querystring = require('querystring');

var search_re = /\/v?1\/search$/;
var search_re = /\/v?1\/search\/query$/;
var qtree_re = /\/v?1\/qtree$/;
var bootstrap_re = /\/v?1\/bumblebee\/bootstrap$/;

Expand Down Expand Up @@ -100,7 +100,7 @@ app.use('/api', function (req, res, next) {
r.pathname = r.pathname.replace(/\/\/+/, '/');

if (r.pathname.match(search_re)) {
// optionally swith endpoints
end.pathname = '/solr/select';
}
else if(r.pathname.match(qtree_re)) {
end.pathname = '/solr/qtree';
Expand Down
98 changes: 94 additions & 4 deletions src/js/components/query_builder/plugin.js
Expand Up @@ -207,7 +207,7 @@ define([
]);
}
},
{id: 'instructive()', label: 'instructive()', type: 'string', placeholder: '(any valid query)',
{id: 'reviews()', label: 'reviews()', type: 'string', placeholder: '(any valid query)',
operators: functionOperators,
input: function($rule, filter) {
return this.createFunctionInputs([
Expand Down Expand Up @@ -241,7 +241,91 @@ define([
},
{id: 'black_hole', label: 'literal', type: 'string',
operators: functionOperators, createOperatorIfNecessary: true
}
},

{id: '_version_', label: 'Version', type: 'string', placeholder: 'xxx',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'ack', label: 'Acknowledgements', type: 'string', placeholder: 'ADS',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'aff', label: 'Affiliation', type: 'string', placeholder: 'Harvard',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'alternate_bibcode', label: 'Alternate Bibcode', type: 'string', placeholder: '# secondary identifier of a paper',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'alternate_title', label: 'Alternate Title', type: 'string', placeholder: '# title automatically searches both fields',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'arxiv_class', label: 'Arxiv category', type: 'string', placeholder: 'phys',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'author_facet', label: 'Author Facet', type: 'string', placeholder: '1/Einstein, A./Einstein, Albert',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'bibgroup', label: 'Bibgroup', type: 'string', placeholder: '# bibliographic group',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'body', label: 'Body', type: 'string', placeholder: '# the main text (body) of the article, no acknowledgements/references',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'citation', label: 'Citation', type: 'string', placeholder: '# for special cases, use citations() instead',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'citation_count', label: 'Citation count', type: 'string', placeholder: 'citation_count:[0 TO 100]',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'comment', label: 'Comment', type: 'string', placeholder: '# reserved for internal notes',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'copyright', label: 'Copyright', type: 'string', placeholder: '# copyright notes (free text)',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'data', label: 'Data', type: 'string', placeholder: '# reserved for librarians',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'database', label: 'Database', type: 'string', placeholder: 'physics',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'date', label: 'Date', type: 'string', placeholder: '# must follow date format, e.g. 1976-01-02T00:30:00Z',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'doctype', label: 'Document Type', type: 'string', placeholder: 'book',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'doi', label: 'DOI', type: 'string', placeholder: '010.1038/srep04183',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'eid', label: 'Electronic ID', type: 'string', placeholder: '# internal use',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'email', label: 'Email', type: 'string', placeholder: '# author email, if published',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'facility', label: 'Facility', type: 'string', placeholder: 'CERN',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'grant', label: 'Grant ID', type: 'string', placeholder: 'NNX12AG54G',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'id', label: 'ID', type: 'string', placeholder: '1',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'identifier', label: 'Identifier', type: 'string', placeholder: '# bibcode, eid, doi or other ids',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'indexstamp', label: 'Indexstamp', type: 'string', placeholder: '# reserved for internal use',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'isbn', label: 'ISBN', type: 'string', placeholder: '',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'issn', label: 'ISSN', type: 'string', placeholder: '',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'issue', label: 'Issue', type: 'string', placeholder: '1',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'lang', label: 'Language', type: 'string', placeholder: '# internal use',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'orcid', label: 'ORCID', type: 'string', placeholder: '0000-0001-8178-9506',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'page', label: 'Page', type: 'string', placeholder: '2',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'property', label: 'Property', type: 'string', placeholder: '# internal use',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'pub', label: 'Publication', type: 'string', placeholder: 'apj',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'pubdate', label: 'Publ. Date', type: 'string', placeholder: '2014-08',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'read_count', label: 'Times read', type: 'string', placeholder: '[10 TO 20]',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'reference', label: 'Reference', type: 'string', placeholder: '# internal, use references() instead',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'simbid', label: 'SIMBAD Id', type: 'string', placeholder: '# internal use',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'thesis', label: 'Thesis', type: 'string', placeholder: '',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'vizier', label: 'Vizier', type: 'string', placeholder: '',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'volume', label: 'Volume', type: 'string', placeholder: 'v1',
operators: singleTokenOperators, createOperatorIfNecessary: true},
{id: 'year', label: 'Year', type: 'string', placeholder: '2015',
operators: singleTokenOperators, createOperatorIfNecessary: true}

],
extend: {
createFunctionInputs: function(profiles) {
Expand Down Expand Up @@ -379,7 +463,8 @@ define([
getQuery: function(rules) {
if (!rules)
rules = this.getRules();

if (_.isEmpty(rules))
return '';
var query = this.rulesTranslator.buildQuery(rules);

return query || '';
Expand Down Expand Up @@ -473,7 +558,12 @@ define([
*/
isDirty: function() {
try {
if (this._rules && this.getQuery(this._rules) != this.getQuery()) {
var formQ = this.getQuery();

if (formQ == '')
return false;

if (this._rules && this.getQuery(this._rules) != formQ) {
return true;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/js/components/query_builder/rules_translator.js
Expand Up @@ -417,6 +417,12 @@ define(['underscore',
// ignore
break;
case 'QIDENTIFIER':
ruleNode.setField(qtree.children[0].label);
ruleNode.setValue(qtree.children[1].input);
ruleNode.setOffset(qtree.children[1].start);
ruleNode.setEnd(qtree.children[1].end);
ruleNode.setOperator('is');
break;
case 'QCOORDINATE':
case 'QREGEX':
throw new Error('Not yet ready for: ' + JSON.stringify(qtree));
Expand Down
@@ -1,4 +1,4 @@
<div id="search-gui"><span style="text-align:right;font-size:small;float:right;">This tool is experimental, please forgive its temporary shortcomings...</span>
<div id="search-gui"><span style="text-align:right;font-size:small;float:right;">This tool is still experimental.</span>
</div>


Expand Down
54 changes: 48 additions & 6 deletions test/mocha/js/components/query_builder/plugin.testcases.spec.js
Expand Up @@ -126,16 +126,58 @@ define(['underscore',
testQ('(x AND (y AND z)', '(x AND (y AND z)');
});

it("all supported indexes", function (done) {
testQ('title:foo', 'title:foo');
it("supports fields that we have", function (done) {
this.timeout(5000);
testQ('_version_:1', '_version_:1');
testQ('abstract:foo', 'abstract:foo');
testQ('ack:foo', 'ack:foo');
testQ('aff:foo', 'aff:foo');
testQ('alternate_bibcode:foo', 'alternate_bibcode:foo');
testQ('alternate_title:foo', 'alternate_title:foo');
testQ('arxiv_class:foo', 'arxiv_class:foo');
testQ('author:foo', 'author:foo');
testQ('keyword:foo', 'keyword:foo');
testQ('author_facet:foo', 'author_facet:foo');
testQ('bibgroup:foo', 'bibgroup:foo');
testQ('body:foo', 'body:foo');
testQ('citation:foo', 'citation:foo');
testQ('citation_count:0', 'citation_count:0');
testQ('comment:foo', 'comment:foo');
testQ('copyright:foo', 'copyright:foo');
testQ('data:foo', 'data:foo');
testQ('database:foo', 'database:foo');
testQ('date:2012', 'date:2012');
testQ('doctype:foo', 'doctype:foo');
testQ('doi:foo', 'doi:foo');
testQ('eid:foo', 'eid:foo');
testQ('email:foo', 'email:foo');
testQ('facility:foo', 'facility:foo');
testQ('full:foo', 'full:foo');
// TBD: add more

testQ('grant:foo', 'grant:foo');
testQ('id:0', 'id:0');
testQ('identifier:foo', 'identifier:foo');
testQ('indexstamp:0001', 'indexstamp:0001');
testQ('issn:foo', 'issn:foo');
testQ('isbn:foo', 'isbn:foo');
testQ('issue:foo', 'issue:foo');
testQ('keyword:foo', 'keyword:foo');
testQ('lang:foo', 'lang:foo');
testQ('orcid:foo', 'orcid:foo');
testQ('page:foo', 'page:foo');
testQ('property:foo', 'property:foo');
testQ('pub:foo', 'pub:foo');
testQ('pubdate:2012', 'pubdate:2012');
testQ('read_count:0', 'read_count:0');
//testQ('reader:foo', 'reader:foo');
//testQ('recid:foo', 'recid:foo');
testQ('reference:foo', 'reference:foo');
testQ('simbid:0', 'simbid:0');
testQ('thesis:foo', 'thesis:foo');
testQ('title:foo', 'title:foo');
testQ('vizier:foo', 'vizier:foo');
testQ('volume:foo', 'volume:foo');
testQ('year:2012', 'year:2012');
done();
});


});
});
2 changes: 1 addition & 1 deletion test/test-loader.js
Expand Up @@ -103,7 +103,7 @@ define([

$.ajax({
type: "GET",
url: "/api/v1/search",
url: "/api/v1/search/query",
data: "q=*:*",
dataType: "json",
success: function(data) {
Expand Down

0 comments on commit 38aa478

Please sign in to comment.