From c4906798b45939479c3b7f01d568d31913ee6148 Mon Sep 17 00:00:00 2001 From: stgram Date: Tue, 14 Jan 2014 04:12:46 +0200 Subject: [PATCH 1/4] adding regexp to sql when searching blocks This is to evade the problem in which searching for Diamond Ore brought up Quartz Stairs. In SQL syntax, %SEARCH_STRING%, % matches everything, even digits. Diamond ore is 56, Quartz Stairs 156 The provided example negates digits and some special symbols for quantity and after-id values to trim the results to the proper ones. Note: This so far reduces a lot results when searching for both a keyword and a block, rarely used combination I hope. --- HawkEye Interface/interface.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/HawkEye Interface/interface.php b/HawkEye Interface/interface.php index 46efaf2..8b6d5b7 100644 --- a/HawkEye Interface/interface.php +++ b/HawkEye Interface/interface.php @@ -119,8 +119,30 @@ array_push($args, "`timestamp` <= '" . $data["dateTo"] . "'"); if ($data["keywords"][0] != "") { foreach ($data["keywords"] as $key => $val) + //check if dealing with a block, or an entered string + if($data["block"] != "00") + { + //In SQL syntax, %SEARCH_STRING%, % matches everything, even digits. + //regexp is needed to avoid matching 156 for a 56 search. + $data["keywords"][$key] = "'(^|[^0-9^:^~^x])" . $val . "($|[^0-9^x^-])'"; + //above is negation, bellow I saved my example for inclusion + //$data["keywords"][$key] = "'( |(^|@)([+]|[-])|^|[0-9]-)" . $val . "(~|$|:)'"; + //chest transaction "@(-|+)ID(:|~)" + //pick/drop item " ID(:|$)" + //place/break "(^|-)ID(:|$)" + //edit: place is in format "formerblock-currentblock" + //happy xray hunting. + } + else //if not, continue normal operation + { $data["keywords"][$key] = "'%" . $val . "%'"; - array_push($args, "`data` LIKE " . join(" OR `data` LIKE ", $data["keywords"])); + } + + if($data["block"] != "00") + { //again, if a block, do a REGEXP + array_push($args, "`data` REGEXP " . join(" OR `data` REGEXP ", $data["keywords"])); + } //if dealing with an entered string, do a LIKE seach with the already completed %% request + else array_push($args, "`data` LIKE " . join(" OR `data` LIKE ", $data["keywords"])); } if ($data["exclude"][0] != "") { foreach ($data["exclude"] as $key => $val) @@ -288,4 +310,4 @@ function error($message) { echo json_encode($output); } -?> \ No newline at end of file +?> From f7bdf96af67b28b3c56e5f5ff83399e59643afbb Mon Sep 17 00:00:00 2001 From: stgram Date: Tue, 14 Jan 2014 04:18:24 +0200 Subject: [PATCH 2/4] Update interface.php --- HawkEye Interface/interface.php | 1 - 1 file changed, 1 deletion(-) diff --git a/HawkEye Interface/interface.php b/HawkEye Interface/interface.php index 8b6d5b7..a2f03ee 100644 --- a/HawkEye Interface/interface.php +++ b/HawkEye Interface/interface.php @@ -137,7 +137,6 @@ { $data["keywords"][$key] = "'%" . $val . "%'"; } - if($data["block"] != "00") { //again, if a block, do a REGEXP array_push($args, "`data` REGEXP " . join(" OR `data` REGEXP ", $data["keywords"])); From de6f9a691316b5932ec2b9a3c55fa4b6d1c935ce Mon Sep 17 00:00:00 2001 From: stgram Date: Tue, 14 Jan 2014 04:22:15 +0200 Subject: [PATCH 3/4] Update interface.php --- HawkEye Interface/interface.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/HawkEye Interface/interface.php b/HawkEye Interface/interface.php index a2f03ee..20881ad 100644 --- a/HawkEye Interface/interface.php +++ b/HawkEye Interface/interface.php @@ -119,8 +119,7 @@ array_push($args, "`timestamp` <= '" . $data["dateTo"] . "'"); if ($data["keywords"][0] != "") { foreach ($data["keywords"] as $key => $val) - //check if dealing with a block, or an entered string - if($data["block"] != "00") + if($data["block"] != "00") //check if dealing with a block, or an entered string { //In SQL syntax, %SEARCH_STRING%, % matches everything, even digits. //regexp is needed to avoid matching 156 for a 56 search. @@ -137,11 +136,14 @@ { $data["keywords"][$key] = "'%" . $val . "%'"; } - if($data["block"] != "00") - { //again, if a block, do a REGEXP - array_push($args, "`data` REGEXP " . join(" OR `data` REGEXP ", $data["keywords"])); - } //if dealing with an entered string, do a LIKE seach with the already completed %% request - else array_push($args, "`data` LIKE " . join(" OR `data` LIKE ", $data["keywords"])); + if($data["block"] != "00") //again, if a block, do a REGEXP + { + array_push($args, "`data` REGEXP " . join(" OR `data` REGEXP ", $data["keywords"])); + } + else //if dealing with an entered string, do a LIKE seach with the already completed %% request + { + array_push($args, "`data` LIKE " . join(" OR `data` LIKE ", $data["keywords"])); + } } if ($data["exclude"][0] != "") { foreach ($data["exclude"] as $key => $val) From 7b9bf897a1bc6981b92ce0b5c7252e98bbf5711f Mon Sep 17 00:00:00 2001 From: stgram Date: Tue, 14 Jan 2014 04:24:07 +0200 Subject: [PATCH 4/4] Update interface.php --- HawkEye Interface/interface.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/HawkEye Interface/interface.php b/HawkEye Interface/interface.php index 20881ad..b88b791 100644 --- a/HawkEye Interface/interface.php +++ b/HawkEye Interface/interface.php @@ -137,13 +137,9 @@ $data["keywords"][$key] = "'%" . $val . "%'"; } if($data["block"] != "00") //again, if a block, do a REGEXP - { array_push($args, "`data` REGEXP " . join(" OR `data` REGEXP ", $data["keywords"])); - } else //if dealing with an entered string, do a LIKE seach with the already completed %% request - { array_push($args, "`data` LIKE " . join(" OR `data` LIKE ", $data["keywords"])); - } } if ($data["exclude"][0] != "") { foreach ($data["exclude"] as $key => $val)