Skip to content

Commit

Permalink
Merge pull request #2377 from merenlab/2153-bug-search-with-operators…
Browse files Browse the repository at this point in the history
…-in-the-interactive-interface

Refactor searchContigs func
  • Loading branch information
metehaansever authored Dec 2, 2024
2 parents b995ab6 + 5dbe740 commit c101155
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions anvio/data/interactive/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,6 @@ function searchContigs()
search_column = (column == 0) ? 'Item Name' : layerdata[0][column];
var operator = $('#searchOperator').val();

if (operator < 6)
{
var operator_text = $('#searchOperator option:selected').text();

// logical operator
var _pre = "layerdata[";
var _post = "][" + column + "] " + operator_text + " \"" + svalue.trim() + "\"";

}
else if (operator == 6)
{
// contains
var _pre = "layerdata[";
var _post = "][" + column + "].toString().toLowerCase().indexOf(\"" + svalue + "\".toLowerCase()) != -1";
}

var _len = layerdata.length;
var _counter = 0;
search_results = [];
Expand All @@ -56,8 +40,40 @@ function searchContigs()
if (layerdata[row][column]==null)
continue;

if (eval(_pre + row + _post)){
search_results.push({'split': layerdata[row][0], 'value': layerdata[row][column]});
var cellValue = layerdata[row][column];
var matchFound = false;

var numericCellValue = parseFloat(cellValue);
var numericSValue = parseFloat(svalue);

switch (operator) {
case '0': // exact match
matchFound = (cellValue == svalue.trim());
break;
case '1': // not equal
matchFound = (cellValue != svalue.trim());
break;
case '2': // greater than
matchFound = (numericCellValue > numericSValue);
break;
case '3': // less than
matchFound = (numericCellValue < numericSValue);
break;
case '4': // greater than or equal
matchFound = (numericCellValue >= numericSValue);
break;
case '5': // less than or equal
matchFound = (numericCellValue <= numericSValue);
break;
case '6': // contains
matchFound = cellValue.toString().toLowerCase().indexOf(svalue.toLowerCase()) !== -1;
break;
default:
break;
}

if (matchFound) {
search_results.push({'split': layerdata[row][0], 'value': cellValue});
_counter++;
}
}
Expand Down

0 comments on commit c101155

Please sign in to comment.