Skip to content

Commit

Permalink
Merge pull request #529 from romanchyla/fix-query-form
Browse files Browse the repository at this point in the history
Fix query form
  • Loading branch information
romanchyla committed Jul 31, 2015
2 parents d1879a8 + d1b330c commit 0091600
Show file tree
Hide file tree
Showing 11 changed files with 446 additions and 64 deletions.
2 changes: 1 addition & 1 deletion local-config.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
210 changes: 179 additions & 31 deletions src/js/components/query_builder/plugin.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/js/components/query_builder/rules_translator.js
Original file line number Diff line number Diff line change
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
14 changes: 12 additions & 2 deletions src/js/widgets/search_bar/search_bar_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ define([
},

onBuilderChange: function() {
if (this.queryBuilder.isDirty()) {
if (this.queryBuilder.isDirty(this.getFormVal())) {
var newQuery = this.queryBuilder.getQuery();
this.setFormVal(newQuery);
}
Expand Down Expand Up @@ -304,7 +304,12 @@ define([

var formVal = this.getFormVal();
if (formVal.trim().length > 0) {
this.queryBuilder.updateQueryBuilder(formVal);
if (this.queryBuilder.isDirty(this.getFormVal()) || _.isEmpty(this.queryBuilder.getRules())) {
this.queryBuilder.updateQueryBuilder(formVal);
}
else {
this.queryBuilder.setRules(this.queryBuilder.getRules());
}
}
else { // display a default form
this.queryBuilder.setRules({
Expand Down Expand Up @@ -510,6 +515,11 @@ define([
this.view.setFormVal(queryString);
}
this.view.$el.find('.show-form').click();
},

onDestroy: function () {
this.view.queryBuilder.destroy();
this.view.destroy();
}
});
return SearchBarWidget;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
58 changes: 53 additions & 5 deletions test/mocha/js/components/query_builder/plugin.testcases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,64 @@ 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.skip("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();
});

it("understands funcitons", function(done) {
testQ('pos(james AND jim, 1, 2)', 'pos(james AND jim, 1, 2)');
testQ('pos(james AND jim, 1)', 'pos(james AND jim, 1)');
done();
});

});
});
134 changes: 131 additions & 3 deletions test/mocha/js/components/query_builder/rules_translator.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,144 @@

define(['jquery',
define([
'jquery',
'underscore',
'js/components/query_builder/rules_translator',
'js/components/generic_module'
], function(
], function(
$,
_,
RulesTranslator,
GenericModule) {

describe("QueryBuilder - Rule Translator (component)", function () {
describe("QueryBuilder - Rule Translator (rules_translator.spec.js)", function () {

it("from UI to the query string", function() {
var t = new RulesTranslator();

expect(t.buildQuery({
"condition": "OR",
"rules": [
{
"condition": "AND",
"rules": [
{
"id": "author",
"field": "author",
"type": "string",
"input": "text",
"operator": "contains",
"value": "\"accomazzi,a\" OR \"kurtz,m\""
}
]
},
{
"id": "author",
"field": "author",
"type": "string",
"input": "text",
"operator": "is",
"value": "foo"
}
]
})).to.eql('(author:("accomazzi,a" OR "kurtz,m")) OR author:foo');

expect(t.buildQuery({
"rules": [
{
"id": "pos()",
"field": "pos()",
"type": "string",
"operator": "is_function",
"value": "complex AND query|1"
}
]
})).to.eql('pos(complex AND query, 1)');

expect(t.buildQuery({
"rules": [
{
"id": "pos()",
"field": "pos()",
"type": "string",
"operator": "is_function",
"value": "complex AND query|1|10"
}
]
})).to.eql('pos(complex AND query, 1, 10)');

expect(t.buildQuery({
"rules": [
{
"id": "trending()",
"field": "trending()",
"type": "string",
"operator": "is_function",
"value": "complex AND query"
}
]
})).to.eql('trending(complex AND query)');

expect(t.buildQuery({
"rules": [
{
"id": "reviews()",
"field": "reviews()",
"type": "string",
"operator": "is_function",
"value": "complex AND query"
}
]
})).to.eql('reviews(complex AND query)');

expect(t.buildQuery({
"rules": [
{
"id": "citations()",
"field": "citations()",
"type": "string",
"operator": "is_function",
"value": "complex AND query"
}
]
})).to.eql('citations(complex AND query)');

expect(t.buildQuery({
"rules": [
{
"id": "references()",
"field": "references()",
"type": "string",
"operator": "is_function",
"value": "complex AND query"
}
]
})).to.eql('references(complex AND query)');

expect(t.buildQuery({
"rules": [
{
"id": "topn()",
"field": "topn()",
"type": "string",
"operator": "is_function",
"value": "10|complex AND query"
}
]
})).to.eql('topn(10, complex AND query)');

expect(t.buildQuery({
"rules": [
{
"id": "topn()",
"field": "topn()",
"type": "string",
"operator": "is_function",
"value": "10|complex AND query|citation_count desc"
}
]
})).to.eql('topn(10, complex AND query, citation_count desc)');

});

it.skip("qtree -> rules", function() {

Expand Down
Loading

0 comments on commit 0091600

Please sign in to comment.