Comments (9)
http://medoo.in/api/where #Full Text Searching
from medoo.
Thank you for your quick reply, but I had already read that section in Documentation, but I still can't accomplish the following ( and perhaps I stated this poorly in the beggining ). which is do a string search that begins with e.g. FOO% or ends with e.g. %BAR. When I take a look at the queryString there is always a % sign on either side of string.
from medoo.
A fast and easy solution for your request is to add a new IF statement inside "where_clause" function with a new label for the operation you want to implement, for example:
We want to remove the first '%' when using the LIKE operation ('FOO%') so lets start to make a new LIKE operation named as "xLIKE".
if (isset($where['xLIKE']))
{
$like_query = $where['xLIKE'];
if (is_array($like_query))
{
$is_OR = isset($like_query['OR']);
if ($is_OR || isset($like_query['AND']))
{
$connector = $is_OR ? 'OR' : 'AND';
$like_query = $is_OR ? $like_query['OR'] : $like_query['AND'];
}
else
{
$connector = 'AND';
}
$clause_wrap = array();
foreach ($like_query as $column => $keyword)
{
if (is_array($keyword))
{
foreach ($keyword as $key)
{
$clause_wrap[] = $this->column_quote($column) . ' LIKE ' . $this->quote('' . $key . '%');
}
}
else
{
$clause_wrap[] = $this->column_quote($column) . ' LIKE ' . $this->quote('' . $keyword . '%');
}
}
$where_clause .= ($where_clause != '' ? ' AND ' : ' WHERE ') . '(' . implode($clause_wrap, ' ' . $connector . ' ') . ')';
}
}
Also, remember to add your new xLIKE option inside the explode list (function where_clause(...)):
$single_condition = array_diff_key($where, array_flip(
explode(' ', 'AND OR GROUP ORDER HAVING LIMIT LIKE MATCH xLIKE')
));
And the usage of this new option is the same as the LIKE one but naming it as xLIKE:
$data = $conn->select("item_data", [
"[>]item_general" => ["id" => "id"]
],[
"item_general.country",
"item_general.lastupdate",
"item_data.title",
"item_data.category",
"item_data.price",
"item_data.currency",
"item_data.url_details"
],[
"xLIKE" => [
"item_data.title" => "Title"
],
"ORDER" => "item_data.price"
]);
Regards.
from medoo.
That will be better I think:
$database->select("account", [
"user_id",
"user_name",
],[
"LIKE" => [
// Match %title%
"content" => "something"
// Match %title
"%content" => "something"
// Match title%
"content%" => "something"
]
]);
from medoo.
Definitely that is a better solution!
Also I suggest to put that example at the Medoo documentation.
http://medoo.in/api/where #Full Text Searching
from medoo.
@JulioSimon Yes, until the new version with this feature released.
from medoo.
Added, like the sample above.
$database->select("account", [
"user_id",
"user_name",
],[
"LIKE" => [
// Match %title%
"content" => "something"
// Match %title
"%content" => "something"
// Match title%
"content%" => "something"
]
]);
from medoo.
Thank you, it worked like a charm
from medoo.
if you mean that "text%" does not working you should fix the ~ operator section in data_implode method
fix these lines:
if ($operator == '~' || $operator == '!~'){
if ($type != 'array'){
$value = array($value);
}
$like_clauses = array();
foreach ($value as $item){
$item = strval($item);
if (preg_match('/^(?!(%|\[|_])).+(?<!(%|\]|_))$/', $item)){
$item = '%' . $item . '%';
}
elseif(substr($item, -1) == "_"){
$item = $item . '%';
}
$like_clauses[] = $column . ($operator === '!~' ? ' NOT' : '') . ' LIKE ' . $this->fn_quote($key, $item);
}
$wheres[] = implode(' OR ', $like_clauses);
}
from medoo.
Related Issues (20)
- sum() sometimes returns string instead of number HOT 1
- invalid value for parameter "client_encoding": "utf8mb4" HOT 1
- 'String' in Data Type Declaration does not work HOT 4
- Any one know how to use this library with mysql's AES_ENCRYPT and AES_DECRYPT HOT 2
- Update from 0.9.6 version :) HOT 1
- Multi-Insertion:how to fetch insert errors?
- New type error after fix #1085 HOT 5
- Rand() optimization HOT 2
- Can't connect to db HOT 1
- Column value is empty or 0 or null HOT 1
- more database support please HOT 1
- Aliases with period separator are disregarded HOT 3
- Fatal error: Uncaught Error: Class "Medoo\Medoo" not found in Project_Asset_Management+Ticket\includes\loader.php:39 HOT 1
- Faster Migrate to Medoo From Conventional HOT 2
- The log() method reports an error, there is a problem with type judgment 'double' => PDO::PARAM_STR. HOT 1
- Problem replacing groups of words larger than 10 elements in WHERE clause using LIKE operator HOT 1
- Real Postgres "DISTINCT ON" query... HOT 1
- Like operator does not work HOT 1
- MariaDB - Table B stops working when table A triggers an INSERT on B
- inner join error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from medoo.