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 { ...@@ -106,19 +106,24 @@ else {
$totalfound=0; $totalfound=0;
// ------------ Textual search ------------- // ------------ Textual search -------------
// Search $base cols using preg_match_all : see regex, PCRE mask¶
// Format input search string
$searchinput = $_GET["query"]; // ex : "[\"medical device\"]" // 1) Format input query into search string
$searchinput=ltrim($searchinput,"[\""); // ex input query string:
$searchinput=rtrim($searchinput,"\"]"); // [\"medical device\"] or [\"anti-inflammatory\",\"non-specific anti-inflammatory\"]
//echodump("Search input :", $searchinput); // ex "medical device" $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" $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. // Search $searchpattern in $base. Update $sims if found.
// $base is a 2D array (array(array). // $base is a 2D array : (array(array).
// echodump("base", $base); // 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]); // echodump("base row 0", $base[0]);
// The column "abstract" for first row : // The column "abstract" for first row :
// echodump("base row 0, 'abstract' col:", $base[0]["abstract"]); // echodump("base row 0, 'abstract' col:", $base[0]["abstract"]);
...@@ -135,7 +140,7 @@ else { ...@@ -135,7 +140,7 @@ else {
$docid = 'd'.$idrow; $docid = 'd'.$idrow;
//echo "doc ". $docid.", ".$res ." occurence(s) found \n"; //echo "doc ". $docid.", ".$res ." occurence(s) found \n";
$totalfound++; $totalfound++;
// build sims array similar to what token search does // build sims array similar to what token-based search does
$sims[$docid] = $res; $sims[$docid] = $res;
} }
//echo "id : ". $id . "\n"; //echo "id : ". $id . "\n";
......
...@@ -448,8 +448,22 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { ...@@ -448,8 +448,22 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
apiurl = TW.conf.relatedDocsAPI 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) // 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) return displayTopPapers(jsonData, nodetypeId, chosenAPI, tgtDivId)
} }
...@@ -486,6 +500,7 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { ...@@ -486,6 +500,7 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
}); });
} }
else { else {
let thisRelDocsConf = TW.currentRelDocsDBs[nodetypeId][chosenAPI] let thisRelDocsConf = TW.currentRelDocsDBs[nodetypeId][chosenAPI]
// /!\ documentation and specification needed for the php use cases /!\ // /!\ documentation and specification needed for the php use cases /!\
let joinedQ = JSON.stringify(qWords).split('&').join('__and__'); let joinedQ = JSON.stringify(qWords).split('&').join('__and__');
...@@ -496,6 +511,8 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { ...@@ -496,6 +511,8 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
// POSS object + join.map(join) // POSS object + join.map(join)
let urlParams = "ndtype="+nodetypeId+"&dbtype="+chosenAPI+"&query="+joinedQ+"&gexf="+TW.File+"&n="+TW.conf.relatedDocsMax ; 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({ $.ajax({
type: 'GET', type: 'GET',
...@@ -505,15 +522,15 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { ...@@ -505,15 +522,15 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
success : function(data){ success : function(data){
// debug // debug
// console.log(data); // console.log(data);
cbDisplay(data.hits); cbDisplay(data.hits, data.nhits, data.ntotal);
//cbDisplay(data.hits);
}, },
error: function(){ error: function(){
console.log(`Not found: relatedDocs for ${apiurl}`) console.log(`Not found: relatedDocs for ${apiurl}`)
// debug
// console.log(apiurl + '/info_div.php?'+urlParams)
cbDisplay([{ "error": stockErrMsg }]) 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