Commit 5bca359d authored by bligny's avatar bligny

Add and operator to search csv query.

parent 8f7100ca
...@@ -304,13 +304,27 @@ ...@@ -304,13 +304,27 @@
<!-- checkbox --> <!-- checkbox -->
<li class="navbar-lower"> <li class="navbar-lower">
<input id="checkboxdiv" onclick="alertCheckBox(this);" <table id="search_table">
title="Add next search results to current selection" <tr><td>
class="nav btn btn-info" &nbsp;
type="checkbox"> <input id="checkboxdiv" onclick="alertCheckBox(this);"
<span style="position: relative; top: 4px;">Add to selection</span> title="Add next search results to current selection"
</li> class="nav btn btn-info"
type="checkbox">
<!--span style="position: relative; top: 4px;">Add to selection</span-->
<span>Add to selection</span>
</td></tr>
<tr><td>
&nbsp;
<input type="radio" id="orop" name="search_operator" value="or"
checked>
<label for="orop">OR&nbsp;&nbsp;</label>
<input type="radio" id="andop" name="search_operator" value="and"
unchecked>
<label for="andop">AND</label>
</td></tr>
</table>
</li>
</ul> </ul>
......
...@@ -109,15 +109,51 @@ else { ...@@ -109,15 +109,51 @@ else {
// Search $base cols using preg_match_all : see regex, PCRE mask¶ // Search $base cols using preg_match_all : see regex, PCRE mask¶
// 1) Format input query into search string // 1) Format input query into search string
// get search operator if provided. Default is 'or'
$searchop="or";
$queryop_key="queryOp";
if (array_key_exists( $queryop_key , $_GET )){
$searchop = strtolower($_GET[$queryop_key]);
if (!(in_array($searchop, array('and','or')))){
echo "<br> Erreur : queryOp must be 'and' or 'or' <br>";
return;
}
}
//echodump("searchOp :", $searchop);
// get and format input query string
// ex input query string: // ex input query string:
// [\"medical device\"] or [\"anti-inflammatory\",\"non-specific anti-inflammatory\"] // [\"medical device\"] or [\"anti-inflammatory\",\"non-specific anti-inflammatory\"]
$searchinput = $_GET["query"]; $searchinput = $_GET["query"];
//echodump("Query :", $searchinput); //echodump("Query :", $searchinput);
// replace " [ and ] characters by empty string // remove '"' around inner terms, and leading and trailing []
$searchinput=str_replace(array("\"", "[", "]"),"",$searchinput); $searchinput=str_replace("\"","",$searchinput);
// replace ',' by '|' (eq or for regex) $searchinput=trim($searchinput,"[]");
$searchinput=str_replace(",","|",$searchinput); //echodump("Query :", $searchinput);
$searchpattern="/".$searchinput."/i"; // ex "/medical device/i"
// some checks : no <>(){}[]:=\/$*?+^| characters
$regex_char="<>(){}[]:=\/$*.?+^|"; // Leave the '.' : eq to any char
$check_pattern='/['.preg_quote($regex_char, '/').']/'; // escape all
if (preg_match($check_pattern, $searchinput)){
echo '<br> info_div.php (csv mode): The input query contains a forbidden character <br>';
echodump("Query :", $searchinput);
return;
}
// build regex pattern see https://www.php.net/manual/fr/book.pcre.php
// PCRE for Perl Compatible Regular Expression
// le and est plus compliqué que le et. Ci dessous, ça a l'air de marcher
//$pattern="/(?=.*ceci)(?=.*test)/i"; $pattern="/(?=.*est)(?=.*ceci est un)/i";
// "/(?=.*nutrition)(?=.*oral nutrition supplement)/i"
if ($searchop === 'and'){ // (?=.*ceci)(?=.*test)
$searchpattern = str_replace(",",")(?=.*",$searchinput);
$searchpattern = "(?=.*".$searchpattern.")";
}else{
$searchpattern=str_replace(",","|",$searchinput);
}
$searchpattern="/".$searchpattern."/i"; // ex "/medical device/i"
//echodump("Search pattern :", $searchpattern); //echodump("Search pattern :", $searchpattern);
// Search $searchpattern in $base. Update $sims if found. // Search $searchpattern in $base. Update $sims if found.
......
...@@ -405,3 +405,20 @@ ul.infoitems { ...@@ -405,3 +405,20 @@ ul.infoitems {
background-color: #EEEEEE; color: #999999; background-color: #EEEEEE; color: #999999;
text-align: right; text-align: right;
} }
/* Add AND/OR search operator*/
#search_table td input[type=checkbox]{
vertical-align: middle ;
margin-top: 0px;
margin-bottom:4px;
}
#search_table td input[type=radio]{
margin-top: 4px;
margin-bottom:0px;
}
#search_table td label {
font-weight:normal;
}
...@@ -433,7 +433,7 @@ function queryForType(ntypeId){ ...@@ -433,7 +433,7 @@ function queryForType(ntypeId){
// - nodetypeId: the queried nodetype // - nodetypeId: the queried nodetype
// - chosenAPI: the API "switch" dbtype ('twitter'||'csv'||'CortextDB') // - chosenAPI: the API "switch" dbtype ('twitter'||'csv'||'CortextDB')
// - tgtDivId: the div #id to update // - tgtDivId: the div #id to update
function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId, searchOperator) {
// waiting image // waiting image
let image='<img style="display:block; margin: 0px auto;" src="twlibs/img/loader.gif"></img>'; let image='<img style="display:block; margin: 0px auto;" src="twlibs/img/loader.gif"></img>';
...@@ -452,9 +452,9 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { ...@@ -452,9 +452,9 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
let cbDisplay = function(jsonData, nhits=null, nTotal=null) { let cbDisplay = function(jsonData, nhits=null, nTotal=null) {
// console.log("cbDisplay", jsonData) // console.log("cbDisplay", jsonData)
// debug, chercher $("#read-sameside-neighs").html(sameNodesDIV) // debug, chercher $("#read-sameside-neighs").html(sameNodesDIV)
// Show the number of docs found and displayed in the left panel // 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, // 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 // need to also update methods.js and inscrement nhits and nTotal for all the bases
// Note ex tgtDivId : id=rd-0-csv // Note ex tgtDivId : id=rd-0-csv
// The label we want to update is "csv (sem)" in : // The label we want to update is "csv (sem)" in :
...@@ -463,7 +463,7 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { ...@@ -463,7 +463,7 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
let label = nhits + " doc displayed / " + nTotal; let label = nhits + " doc displayed / " + nTotal;
$("#reldocs-tabs").find("a").html(label); $("#reldocs-tabs").find("a").html(label);
} }
return displayTopPapers(jsonData, nodetypeId, chosenAPI, tgtDivId) return displayTopPapers(jsonData, nodetypeId, chosenAPI, tgtDivId)
} }
...@@ -500,7 +500,7 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { ...@@ -500,7 +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__');
...@@ -510,10 +510,10 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { ...@@ -510,10 +510,10 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
// (we send it as param because phpAPI supports different dbtypes) // (we send it as param because phpAPI supports different dbtypes)
// 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+"&queryOp="+searchOperator+"&gexf="+TW.File+"&n="+TW.conf.relatedDocsMax ;
// debug (does not work with safari) // debug (does not work with safari)
console.log(apiurl + '/info_div.php?'+urlParams) console.log(apiurl + '/info_div.php?'+urlParams)
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: apiurl + '/info_div.php', url: apiurl + '/info_div.php',
...@@ -530,7 +530,7 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) { ...@@ -530,7 +530,7 @@ function getTopPapers(qWords, nodetypeId, chosenAPI, tgtDivId) {
cbDisplay([{ "error": stockErrMsg }]) cbDisplay([{ "error": stockErrMsg }])
} }
}); });
} }
} }
......
...@@ -635,22 +635,26 @@ function updateRelatedNodesPanel( sels , same, oppos ) { ...@@ -635,22 +635,26 @@ function updateRelatedNodesPanel( sels , same, oppos ) {
if (TW.conf.getRelatedDocs) { if (TW.conf.getRelatedDocs) {
let rdTabCount = 0 let rdTabCount = 0
// get search_operator : 'or' or 'and'
let searchOperator=$("input[name='search_operator']:checked").val();
// update all related docs tabs // update all related docs tabs
for (let ntId in TW.SystemState().activetypes) { for (let ntId in TW.SystemState().activetypes) {
if (TW.SystemState().activetypes[ntId]) { if (TW.SystemState().activetypes[ntId]) {
let qWords = queryForType(ntId) let qWords = queryForType(ntId); // a string array
// console.log("available topPapers tabs:", TW.gui.reldocTabs[ntId]) //console.log("strings to search :", qWords);
//console.log("available topPapers tabs:", TW.gui.reldocTabs[ntId]);
for (let relDbType in TW.gui.reldocTabs[ntId]) { for (let relDbType in TW.gui.reldocTabs[ntId]) {
let tabId = `rd-${ntId}-${relDbType}` let tabId = `rd-${ntId}-${relDbType}`;
rdTabCount ++ rdTabCount ++;
// if not already done // if not already done
if (! TW.lastRelDocQueries[tabId] if (! TW.lastRelDocQueries[tabId]
|| TW.lastRelDocQueries[tabId] != qWords) { || TW.lastRelDocQueries[tabId] != qWords) {
getTopPapers(qWords, ntId, relDbType, tabId) getTopPapers(qWords, ntId, relDbType, tabId, searchOperator);
// memoize // memoize
TW.lastRelDocQueries[tabId] = qWords TW.lastRelDocQueries[tabId] = qWords;
} }
} }
} }
......
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