Commit 8f7100ca authored by bligny's avatar bligny

Search : add case where there are several element in the search input array....

Search : add case where there are several element in the search input array. Add display of total number of document found and shown. Mainly for test purpose, maybe to be removed for production
parent c3f40d84
......@@ -106,19 +106,24 @@ else {
$totalfound=0;
// ------------ Textual search -------------
// Format input search string
$searchinput = $_GET["query"]; // ex : "[\"medical device\"]"
$searchinput=ltrim($searchinput,"[\"");
$searchinput=rtrim($searchinput,"\"]");
//echodump("Search input :", $searchinput); // ex "medical device"
// Search $base cols using preg_match_all : see regex, PCRE mask¶
// 1) Format input query into search string
// ex input query string:
// [\"medical device\"] or [\"anti-inflammatory\",\"non-specific anti-inflammatory\"]
$searchinput = $_GET["query"];
//echodump("Query :", $searchinput);
// replace " [ and ] characters by empty string
$searchinput=str_replace(array("\"", "[", "]"),"",$searchinput);
// replace ',' by '|' (eq or for regex)
$searchinput=str_replace(",","|",$searchinput);
$searchpattern="/".$searchinput."/i"; // ex "/medical device/i"
//echodump("Search pattern :", $pattern);
//echodump("Search pattern :", $searchpattern);
// Search in $base occurences of $searchtext. Update $sims if found.
// $base is a 2D array (array(array).
// Search $searchpattern in $base. Update $sims if found.
// $base is a 2D array : (array(array).
// echodump("base", $base);
// The first line, or row is the first element in the $base array:
// The first row is the first element in the $base array:
// echodump("base row 0", $base[0]);
// The column "abstract" for first row :
// echodump("base row 0, 'abstract' col:", $base[0]["abstract"]);
......@@ -135,7 +140,7 @@ else {
$docid = 'd'.$idrow;
//echo "doc ". $docid.", ".$res ." occurence(s) found \n";
$totalfound++;
// build sims array similar to what token search does
// build sims array similar to what token-based search does
$sims[$docid] = $res;
}
//echo "id : ". $id . "\n";
......
......@@ -448,8 +448,22 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
apiurl = TW.conf.relatedDocsAPI
}
let cbDisplay = function(jsonData) {
// Add nhits and nTotal parameters to be displayed in the right panel
let cbDisplay = function(jsonData, nhits=null, nTotal=null) {
// console.log("cbDisplay", jsonData)
// debug, chercher $("#read-sameside-neighs").html(sameNodesDIV)
// Show the number of docs found and displayed in the left panel
// this will not properly work if there is more than one doc db. In this case,
// need to also update methods.js and inscrement nhits and nTotal for all the bases
// Note ex tgtDivId : id=rd-0-csv
// The label we want to update is "csv (sem)" in :
// <ul id="reldocs-tabs" ...><li><a ...>csv (sem)</a></li></ul>
if (nhits !== null && nTotal !== null) {
let label = nhits + " doc displayed / " + nTotal;
$("#reldocs-tabs").find("a").html(label);
}
return displayTopPapers(jsonData, nodetypeId, chosenAPI, tgtDivId)
}
......@@ -486,6 +500,7 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
});
}
else {
let thisRelDocsConf = TW.currentRelDocsDBs[nodetypeId][chosenAPI]
// /!\ documentation and specification needed for the php use cases /!\
let joinedQ = JSON.stringify(qWords).split('&').join('__and__');
......@@ -496,7 +511,9 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
// POSS object + join.map(join)
let urlParams = "ndtype="+nodetypeId+"&dbtype="+chosenAPI+"&query="+joinedQ+"&gexf="+TW.File+"&n="+TW.conf.relatedDocsMax ;
// debug (does not work with safari)
console.log(apiurl + '/info_div.php?'+urlParams)
$.ajax({
type: 'GET',
url: apiurl + '/info_div.php',
......@@ -505,15 +522,15 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
success : function(data){
// debug
// console.log(data);
cbDisplay(data.hits);
cbDisplay(data.hits, data.nhits, data.ntotal);
//cbDisplay(data.hits);
},
error: function(){
console.log(`Not found: relatedDocs for ${apiurl}`)
// debug
// console.log(apiurl + '/info_div.php?'+urlParams)
cbDisplay([{ "error": stockErrMsg }])
}
});
}
}
......
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