Commit 77a0f02a authored by Romain Loth's avatar Romain Loth

basic search hits templates mecanism

parent 7fa9d71a
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"reldbtype": "csv", "reldbtype": "csv",
"reldbfile": "shale_and_ice.csv", "reldbfile": "shale_and_ice.csv",
"reldbqcols": ["title"], "reldbqcols": ["title"],
"reltemplate": "_todo" "reltemplate": "bib_details"
} }
}, },
"model_calibration.gexf": { "model_calibration.gexf": {
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"reldbtype": "csv", "reldbtype": "csv",
"reldbfile": "model_calibration.csv", "reldbfile": "model_calibration.csv",
"reldbqcols": ["title"], "reldbqcols": ["title"],
"reltemplate": "_todo" "reltemplate": "bib_details"
} }
} }
} }
...@@ -40,14 +40,14 @@ ...@@ -40,14 +40,14 @@
"reldbtype": "csv", "reldbtype": "csv",
"reldbfile": "mini_for_csv.csv", "reldbfile": "mini_for_csv.csv",
"reldbqcols": ["title","keywords","text"], "reldbqcols": ["title","keywords","text"],
"reltemplate": "_todo" "reltemplate": "bib_details"
}, },
"node1": { "node1": {
"name": "person", "name": "person",
"reldbtype": "csv", "reldbtype": "csv",
"reldbfile": "mini_for_csv.csv", "reldbfile": "mini_for_csv.csv",
"reldbqcols": ["author"], "reldbqcols": ["author"],
"reltemplate": "_todo" "reltemplate": "bib_details"
} }
}, },
"test_with_various_atts.gexf": {} "test_with_various_atts.gexf": {}
...@@ -73,7 +73,8 @@ ...@@ -73,7 +73,8 @@
"name": "ISItermsWhitelistV2Oct_5 & ISItermsWhitelistV2Oct_5", "name": "ISItermsWhitelistV2Oct_5 & ISItermsWhitelistV2Oct_5",
"reldbqtable": "ISItermsWhitelistV2Oct_5", "reldbqtable": "ISItermsWhitelistV2Oct_5",
"reldbfile" : "wos_climate-change_title_2014-2015.db", "reldbfile" : "wos_climate-change_title_2014-2015.db",
"reldbtype": "CortextDB" "reldbtype": "CortextDB",
"reltemplate": "universal"
} }
} }
} }
......
...@@ -159,7 +159,9 @@ TW.conf = (function(TW){ ...@@ -159,7 +159,9 @@ TW.conf = (function(TW){
// ------------ // ------------
TWConf.paths = { TWConf.paths = {
'ourlibs': 'twlibs', 'ourlibs': 'twlibs',
'templates': "twlibs/hit_templates",
'modules': 'twmodules', 'modules': 'twmodules',
'sourceFile': "", // server-side .gexf|.json default source 'sourceFile': "", // server-side .gexf|.json default source
'sourceMenu': "db.json" // ...or server-side gexf default source list 'sourceMenu': "db.json" // ...or server-side gexf default source list
} }
......
...@@ -10,6 +10,10 @@ ini_set('display_startup_errors',1); ...@@ -10,6 +10,10 @@ ini_set('display_startup_errors',1);
include('tools.php'); include('tools.php');
include('parameters_details.php'); include('parameters_details.php');
if ($output_mode == "json") {
header('Content-Type: application/json');
}
$dbtype = null; $dbtype = null;
if (array_key_exists('reldbtype', $my_conf[$ntid])) { if (array_key_exists('reldbtype', $my_conf[$ntid])) {
$dbtype = $my_conf[$ntid]['reldbtype']; $dbtype = $my_conf[$ntid]['reldbtype'];
......
...@@ -196,6 +196,13 @@ html.waiting { ...@@ -196,6 +196,13 @@ html.waiting {
font-family: "Crete Round", "garamond", serif ; font-family: "Crete Round", "garamond", serif ;
padding: 5px; padding: 5px;
} }
.hit-keywords {
color: #000;
font-style: italic;
font-family: "Crete Round", "garamond", serif ;
padding: 5px;
}
/* small messages */ /* small messages */
p.micromessage{ p.micromessage{
font-size: 85%; font-size: 85%;
......
<li class="searchhit" title='$${score}'>
<a href="$${link}">$${tit}</a> <span class="author">$${au}</span>
</li>
<li class="searchhit" title="$${score}">
<p>
<a href="$${link}"><b>$${tit}</b></a>
by
<span class="author">$${au}</span>
,
<i>$${src}</i>
[$${date}]
</p>
<p>
<span class="hit-keywords">
$${kws}
</span>
<span class="hit-text">
$${txt}
</span>
</p>
</li>
...@@ -373,12 +373,12 @@ function getTopPapers(){ ...@@ -373,12 +373,12 @@ function getTopPapers(){
topPapersFetcher( topPapersFetcher(
swNodetypes[0], swNodetypes[0],
qWordsbySwType[swNodetypes[0]], qWordsbySwType[swNodetypes[0]],
`<h2>${swNodetypes[0]}</h2>`, [[],[]],
function(enrichedHtml) { function(priorJsonHits) {
topPapersFetcher( topPapersFetcher(
swNodetypes[1], swNodetypes[1],
qWordsbySwType[swNodetypes[1]], qWordsbySwType[swNodetypes[1]],
enrichedHtml+`<p class=centered>---</p><h2>${swNodetypes[1]}</h2>`, priorJsonHits,
displayTopPapers displayTopPapers
) )
} }
...@@ -396,31 +396,30 @@ function getTopPapers(){ ...@@ -396,31 +396,30 @@ function getTopPapers(){
// - cbNext is a partial function to handle the follow-up // - cbNext is a partial function to handle the follow-up
// (just pass it resHTML, to continue enriching or display) // (just pass it resHTML, to continue enriching or display)
// //
function topPapersFetcher(swType, qWords, priorHtml, cbNext){ function topPapersFetcher(swType, qWords, accumulHits, cbNext){
if (isUndef(priorHtml)) priorHtml = '' // list of json object with hit metadata (title, author, etc.) by nodetype
if (isUndef(accumulHits)) accumulHits = [[],[]]
// callback to continue accumulating json hits or display to html
if (isUndef(cbNext)) cbNext = displayTopPapers if (isUndef(cbNext)) cbNext = displayTopPapers
// introducing the modern node type thanks to updated db.json specs // introducing the modern node type thanks to updated db.json specs
let nodetype = (swType == 'semantic') ? 0 : 1 let nodetype = (swType == 'semantic') ? 0 : 1
let stockErrMsg = `<p class="micromessage">
Your settings for relatedDocsType are set on ${TW.conf.relatedDocsType}
API but it couldn't be connected to.</p>`
if (TW.conf.relatedDocsType == "api") {
stockErrMsg += `<p class="micromessage">Check if it is running and
accessible:<br><span class=code>${TW.conf.relatedDocsAPI}</span></p>`
}
let resHTML = ''
let apiurl = TW.conf.relatedDocsAPIS[TW.conf.relatedDocsType] let apiurl = TW.conf.relatedDocsAPIS[TW.conf.relatedDocsType]
if (! apiurl) { if (! apiurl) {
apiurl = TW.conf.relatedDocsAPI apiurl = TW.conf.relatedDocsAPI
} }
let stockErrMsg = `
<p class="micromessage">The API ${TW.conf.relatedDocsType} couldn't be connected to.</p>
<p class="micromessage">The queried route found in TW.conf was: <span class=code>${apiurl}</span>
<br>Check if it is running and accessible.</p>`
let resHTML = ''
if (TW.conf.relatedDocsType == "twitter") { if (TW.conf.relatedDocsType == "twitter") {
let joinedQ = qWords.map(function(w){return'('+w+')'}).join(' AND ') let joinedQ = qWords.map(function(w){return'('+w+')'}).join(' AND ')
$.ajax({ $.ajax({
...@@ -430,33 +429,36 @@ function topPapersFetcher(swType, qWords, priorHtml, cbNext){ ...@@ -430,33 +429,36 @@ function topPapersFetcher(swType, qWords, priorHtml, cbNext){
contentType: "application/json", contentType: "application/json",
success : function(data){ success : function(data){
if (data.length) { if (data.length) {
for (var k in data) { accumulHits[nodetype] = accumulHits[nodetype].concat(data)
let tweetJson = data[k]
resHTML += renderTweet(tweetJson)
}
} }
else { else {
resHTML += `<p class="micromessage centered">The query accumulHits[nodetype].push({
"error": `<p class="micromessage centered">The query
<span class=code>${joinedQ}</span> delivers <span class=code>${joinedQ}</span> delivers
no results on Twitter.</p>` no results on Twitter.</p>`
})
} }
cbNext(priorHtml + resHTML) cbNext(accumulHits)
}, },
error: function(){ error: function(){
console.log(`Not found: relatedDocs for ${apiurl}`) console.log(`Not found: relatedDocs for ${apiurl}`)
cbNext(priorHtml + stockErrMsg) accumulHits[nodetype].push({
"error": stockErrMsg
})
cbNext(accumulHits)
} }
}); });
} }
else if (TW.conf.relatedDocsType == "LocalDB") { else if (TW.conf.relatedDocsType == "LocalDB") {
let thisRelDocsConf = TW.gmenuInfos[TW.File][nodetype] let thisRelDocsConf = TW.gmenuInfos[TW.File][nodetype]
if (!thisRelDocsConf) { if (!thisRelDocsConf) {
resHTML = accumulHits[nodetype].push({
`<p>Your settings for relatedDocsType are set on a local database, "error": `<p>Your settings for relatedDocsType are set on a local database,
but your servermenu file does not provide any information about but your servermenu file does not provide any information about
the CSV or DB table to query for related documents the CSV or DB table to query for related documents
(on nodetype ${nodetype}: ${swType})</p>` (on nodetype ${nodetype}: ${swType})</p>`
cbNext(priorHtml + resHTML) })
cbNext(accumulHits)
return return
} }
else { else {
...@@ -474,22 +476,95 @@ function topPapersFetcher(swType, qWords, priorHtml, cbNext){ ...@@ -474,22 +476,95 @@ function topPapersFetcher(swType, qWords, priorHtml, cbNext){
type: 'GET', type: 'GET',
url: apiurl + '/info_div.php', url: apiurl + '/info_div.php',
data: urlParams, data: urlParams,
contentType: "application/json",
success : function(data){ success : function(data){
console.log(`relatedDocs: ${apiurl}/info_div.php?${urlParams}`); if (data.hits) {
resHTML = data accumulHits[nodetype] = accumulHits[nodetype].concat(data.hits)
cbNext(priorHtml + resHTML) }
cbNext(accumulHits)
}, },
error: function(){ error: function(){
console.log(`Not found: relatedDocs for ${apiurl}`) console.log(`Not found: relatedDocs for ${apiurl}`)
cbNext(priorHtml + stockErrMsg) accumulHits[nodetype].push({
"error": stockErrMsg
})
cbNext(accumulHits)
} }
}); });
} }
} }
} }
function displayTopPapers(enrichedHtml) { function makeRendererFromTemplate(tmplName) {
$("#topPapers").html(enrichedHtml); let tmplURL = TW.conf.paths.templates + '/' + tmplName + '.html'
let gotTemplate = AjaxSync({ url: tmplURL });
var tmplStr = ''
if (gotTemplate['OK']) {
tmplStr = gotTemplate.data
}
// we return a customized renderJsonToHtml function
return function(jsonHit) {
let htmlOut = tmplStr
for (key in jsonHit) {
// our tags look like this in the template ====> by $${author}, [$${date}]
let reKey = new RegExp('\\$\\$\\{'+key+'\\}', 'g')
// we replace them by value
htmlOut = htmlOut.replace(reKey, jsonHit[key])
}
// we also replace any not found keys by 'N/A'
let reKeyAll = new RegExp('\\$\\$\\{[^\\}]+\\}', 'g')
htmlOut = htmlOut.replace(reKeyAll, "N/A")
return htmlOut
}
}
function displayTopPapers(jsonHits) {
// console.log('jsonHits', jsonHits)
let resHTML = '<ul class="infoitems">'
let toHtmlFun = function(){}
for (var ndtypeId in TW.categories) {
if (TW.conf.relatedDocsType == 'twitter') {
toHtmlFun = renderTweet
}
else {
let thisRelDocsConf = TW.gmenuInfos[TW.File][ndtypeId]
if (thisRelDocsConf && thisRelDocsConf.reltemplate) {
// console.log("my rendering hits template", thisRelDocsConf.reltemplate)
toHtmlFun = makeRendererFromTemplate(thisRelDocsConf.reltemplate)
}
else {
console.warn(`no rendering template found in ${TW.conf.paths.sourceMenu} for this source ${TW.File}...`)
// try the universal template
toHtmlFun = makeRendererFromTemplate("universal")
}
}
// console.log("my rendering fun", toHtmlFun)
for (var k in jsonHits[ndtypeId]) {
let hitJson = jsonHits[ndtypeId][k]
if (hitJson.error) {
resHTML += hitJson.error
}
else {
resHTML += toHtmlFun(hitJson)
}
}
}
resHTML += '</ul>'
// effect the changes in topPapers
$("#topPapers").html(resHTML);
} }
function newPopup(url) { function newPopup(url) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment