473,321 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

regexp, mysql and plural marking

hello all,

for a search engine, I'm looking for a regexp than can do the job
it is just (!) a 's' problem (frequent in french) :

I have a field 'thesaurus' in a table MySQL (3.23.56) ;

I have a field 'search' in a form where user can input a word ;

what I want is :

if search == 'mil'
return 'mil' (if exist) AND 'mils' (if exist),
but do not return 'military', 'million','milsblabla',...

if search == 'mils'
return 'mil' (if exist) AND 'mils' (if exist)
but do not return 'military', 'million','milsblabla',...

thank you for help or suggestion.

--
@@@@@
E -00
' `)
|\_ =="
Jul 17 '05 #1
1 2412
denisb <ne***@no-log.org> wrote:
for a search engine, I'm looking for a regexp than can do the job
it is just (!) a 's' problem (frequent in french) :
I have a field 'thesaurus' in a table MySQL (3.23.56) ;
I have a field 'search' in a form where user can input a word ;
what I want is :
if search == 'mil'
return 'mil' (if exist) AND 'mils' (if exist),
but do not return 'military', 'million','milsblabla',...
if search == 'mils'
return 'mil' (if exist) AND 'mils' (if exist)
but do not return 'military', 'million','milsblabla',...


no answers...
so I do that :

// initialise WHERE condition for mysql query
$what = "";
// user can search all words or at least one of them
$choice = (($andor == "and") ? "AND" : "OR");
// no html
$search = str_replace(array("&quot;","&lt;","&gt;","&amp;"),
array("","","",""),
$search);
// no accent (french site)
$search = strtolower(strtr($search,
"ÄÅÀÃáàâäãåÉéèêëíìîïÖÕóòôöõÜúùûüÿÇçÑñ",
"aaaaaaaaaaeeeeeiiiiooooooouuuuuyccnn"));
// only >=4 digits numbers
$search = ereg_replace("[[:blank:]][[0-9]{1,3}]+[[:blank:]]"," ",
ereg_replace("[^[:alnum:]]+"," ",
$search));
// only >=3 letters words
$search = ereg_replace("[[:blank:]][^ ]{1,2}[[:blank:]]"," ",
" ".$search." ");
// separators in thesaurus
$search = trim(ereg_replace("[[:blank:]]+","#",$search));
// make WHERE condition
$search_list = array();
$search_list = explode("#",$search);
for ($i = 1, $n = count($search_list); $i < $n-1; $i++) {
$plural = strrchr($search_list[$i], "s");
if ($plural == 's') {
$singular = substr($search_listl[$i], 0,
(strlen($search_list[$i]) - 1));
$what .= "((thesaurus LIKE '%#".$search_list[$i]."#%') OR
(thesaurus LIKE '%#".$ singular."#%'))".
(($i != $n-2) ? " ".$choice." " : "");
} else {
$what .= "((thesaurus LIKE '%#".$search_list[$i]."#%') OR
(thesaurus LIKE '%#".$search_list[$i]."s#%'))".
(($i != $n-2) ? " ".$choice." " : "");
}
}

and now :

==> "SELECT aaa, bbb, ccc FROM ttt WHERE (".$what.") ORDER BY aaa DESC"

it works for me, but I stay sure there is more simple...
--
@@@@@
E -00 it is too hard (for me) to write english message !
' `) /
|\_ =="
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Lucas-Smith | last post by:
Can anyone point me to a regular expression in PHP which could be used to check that a proposed (My)SQL database/table/column name is valid, i.e. shouldn't result in an SQL error when created? ...
6
by: Sandman | last post by:
Textblock (indented for clarity): Hello, my nickname is Sandman, here is a list of things I like: <ol> <li> Perl <li> PHP <li> MySQL </ol>
0
by: Ed Leafe | last post by:
I recently upgraded to 4.1 alpha (MySQL 4.1.0-alpha-standard-log) on my Linux server, and came across a problem with a query that had been working in 3.23 that no longer worked in 4.1a. I've...
6
by: Oliver Spiesshofer | last post by:
Hi, I would like to replace all strings in a table with regexp: the strings contain the substring "-na", and I would like to replace the whole table field with the original content but without...
1
by: Federico Bari | last post by:
Hello everyone, sorry for my bad English. I have to create a query under mySQL for a small research engine; I have to rate the results of a simple regular expression matches inside a text field....
2
by: Steve - DND | last post by:
Just wondering if anyone out there has any code to convert a plural word to it's singular form and vice versa. Most of our database tables are named in a plural fashion. When we go to create...
7
by: Bosconian | last post by:
This might seem like a trivial thing, but has anyone has come up with a better way of outputting a singular vs. plural string? For example: // default plural label $string = "appointments";...
6
by: Christoph | last post by:
I'm trying to set up client side validation for a textarea form element to ensure that the data entered does not exceed 200 characters. I'm using the following code but it doesn't seem to be...
0
by: problematic | last post by:
Hello guys Actually i dont know does mysql support prepare with regexp but i have this query. prepare stm from "select count(id) as total from products where content regexp ']?]' "; set @a =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.