Skip to content

Commit d5362a7

Browse files
authored
Merge pull request #1705 from SynBioHub/fixAdvSearch
Fix issue with advanced search with unique predicates
2 parents b9c4b30 + 5a0fba5 commit d5362a7

5 files changed

Lines changed: 37 additions & 6 deletions

File tree

lib/search.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ search.lucene = function lucene (value) {
136136
for (i = 0; i < values.length - 1; i++) {
137137
var query = values[i].split('=')
138138
if (query[0].indexOf(':') > -1) {
139-
criteriaStr += ' ?subject ' + query[0] + ' ' + query[1] + ' . '
139+
let predicate = query[0].startsWith('http') ? '<' + query[0] + '>' : query[0]
140+
let object = query[1].startsWith('http') ? '<' + query[1] + '>' : query[1]
141+
criteriaStr += ' ?subject ' + predicate + ' ' + object + ' . '
142+
console.log('criteriaStr=' + criteriaStr)
140143
} else if (query[0] === 'objectType') {
141144
if (query[1].includes(':')) {
142145
criteriaStr += ' ?subject a ' + query[1] + ' . '

lib/views/advancedSearch.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,19 @@ function advancedSearchForm (req, res, locals, errors) {
129129

130130
function getQuery (searchPred, searchObj, filterObj, criteriaStr, queryStr, list) {
131131
if (searchPred !== 'No Filter' && (searchObj || (filterObj && filterObj !== 'No Filter'))) {
132+
if (searchPred.toString().startsWith('http')) {
133+
searchPred = '<' + searchPred + '>'
134+
}
132135
var predStr = searchPred
133136
if (!searchPred.toString().startsWith('sbol2:')) {
134137
predStr = searchPred.replace('sbol2:', '')
135138
}
136139
if (searchPred === 'a') {
137140
predStr = 'objectType'
138141
}
142+
if (searchPred.toString().startsWith('http')) {
143+
searchPred = '<' + searchPred + '>'
144+
}
139145
var objStr
140146
if (searchObj) {
141147
objStr = namespace.longName(searchObj)
@@ -315,11 +321,21 @@ function getUriList (req, graphUri) {
315321
}
316322
}
317323

324+
function fixPred (a) {
325+
let short = namespace.shortName(a)
326+
// TODO: a better check for URI would be good
327+
if (a === short && a.startsWith('http')) {
328+
return '<' + a + '>'
329+
} else {
330+
return short
331+
}
332+
}
333+
318334
return Promise.all([
319335

320336
new Promise((resolve, reject) => {
321337
if (req.body.searchPred1 && req.body.searchPred1 !== 'No Filter') {
322-
templateParams.predicate = req.body.searchPred1.includes(':') ? req.body.searchPred1 : 'sbol2:' + req.body.searchPred1
338+
templateParams.predicate = fixPred(req.body.searchPred1)
323339
var objectQuery1 = loadTemplate('sparql/searchObj.sparql', templateParams)
324340
console.debug(objectQuery1)
325341
sparql.queryJson(objectQuery1, graphUri).then((object1List) => {
@@ -338,7 +354,7 @@ function getUriList (req, graphUri) {
338354

339355
new Promise((resolve, reject) => {
340356
if (req.body.searchPred2 && req.body.searchPred2 !== 'No Filter') {
341-
templateParams.predicate = req.body.searchPred2.includes(':') ? req.body.searchPred2 : 'sbol2:' + req.body.searchPred2
357+
templateParams.predicate = fixPred(req.body.searchPred2)
342358
var objectQuery2 = loadTemplate('sparql/searchObj.sparql', templateParams)
343359
console.debug(objectQuery2)
344360
sparql.queryJson(objectQuery2, graphUri).then((object2List) => {
@@ -357,7 +373,7 @@ function getUriList (req, graphUri) {
357373

358374
new Promise((resolve, reject) => {
359375
if (req.body.searchPred3 && req.body.searchPred3 !== 'No Filter') {
360-
templateParams.predicate = req.body.searchPred3.includes(':') ? req.body.searchPred3 : 'sbol3:' + req.body.searchPred3
376+
templateParams.predicate = fixPred(req.body.searchPred3)
361377
var objectQuery3 = loadTemplate('sparql/searchObj.sparql', templateParams)
362378
console.debug(objectQuery3)
363379
sparql.queryJson(objectQuery3, graphUri).then((object3List) => {
@@ -376,7 +392,7 @@ function getUriList (req, graphUri) {
376392

377393
new Promise((resolve, reject) => {
378394
if (req.body.searchPred4 && req.body.searchPred4 !== 'No Filter') {
379-
templateParams.predicate = req.body.searchPred4.includes(':') ? req.body.searchPred4 : 'sbol4:' + req.body.searchPred4
395+
templateParams.predicate = fixPred(req.body.searchPred4)
380396
var objectQuery4 = loadTemplate('sparql/searchObj.sparql', templateParams)
381397
console.debug(objectQuery4)
382398
sparql.queryJson(objectQuery4, graphUri).then((object4List) => {
@@ -395,7 +411,7 @@ function getUriList (req, graphUri) {
395411

396412
new Promise((resolve, reject) => {
397413
if (req.body.searchPred5 && req.body.searchPred5 !== 'No Filter') {
398-
templateParams.predicate = req.body.searchPred5.includes(':') ? req.body.searchPred5 : 'sbol5:' + req.body.searchPred5
414+
templateParams.predicate = fixPred(req.body.searchPred5)
399415
var objectQuery5 = loadTemplate('sparql/searchObj.sparql', templateParams)
400416
console.debug(objectQuery5)
401417
sparql.queryJson(objectQuery5, graphUri).then((object5List) => {

sparql/search.sparql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PREFIX cello: <http://cellocad.org/Terms/cello#>
1111
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1212
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
1313
PREFIX purl: <http://purl.obolibrary.org/obo/>
14+
PREFIX biopax: <http://www.biopax.org/release/biopax-level3.owl#>
15+
PREFIX so: <http://identifiers.org/so/>
16+
PREFIX bench: <http://wiki.synbiohub.org/wiki/Terms/benchling#>
17+
PREFIX genbank: <http://www.ncbi.nlm.nih.gov/genbank#>
1418

1519
SELECT DISTINCT
1620
?subject

sparql/searchCount.sparql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PREFIX cello: <http://cellocad.org/Terms/cello#>
1111
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1212
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
1313
PREFIX purl: <http://purl.obolibrary.org/obo/>
14+
PREFIX biopax: <http://www.biopax.org/release/biopax-level3.owl#>
15+
PREFIX so: <http://identifiers.org/so/>
16+
PREFIX bench: <http://wiki.synbiohub.org/wiki/Terms/benchling#>
17+
PREFIX genbank: <http://www.ncbi.nlm.nih.gov/genbank#>
1418

1519
select (sum(?tempcount) as ?count) WHERE {
1620
{

sparql/searchObj.sparql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PREFIX cello: <http://cellocad.org/Terms/cello#>
1111
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1212
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
1313
PREFIX purl: <http://purl.obolibrary.org/obo/>
14+
PREFIX biopax: <http://www.biopax.org/release/biopax-level3.owl#>
15+
PREFIX so: <http://identifiers.org/so/>
16+
PREFIX bench: <http://wiki.synbiohub.org/wiki/Terms/benchling#>
17+
PREFIX genbank: <http://www.ncbi.nlm.nih.gov/genbank#>
1418

1519
SELECT DISTINCT
1620
?object

0 commit comments

Comments
 (0)