PHP string to boolean function?
#1
Posted 23 December 2011 - 09:58 PM
im planning on using IN BOOLEAN MODE on mysql to get the people who meet the boolean search
Any help would be great,
Many Thanks, Gary
#2
Posted 24 December 2011 - 01:43 AM
<?php $string = 'I am a string'; var_dump($string); echo '<hr>'; $bool = (bool)$string; var_dump($bool);
#3
Posted 24 December 2011 - 11:05 AM
keevitaja, on 24 December 2011 - 01:43 AM, said:
<?php $string = 'I am a string'; var_dump($string); echo '<hr>'; $bool = (bool)$string; var_dump($bool);
yes that gives true or false, im looking for the search boolean, for example a user searches cars NOT motorbikes, it would change it to cars -motorbikes for the sql in boolean mode
#5
Posted 28 December 2011 - 03:35 PM
web-itec, on 24 December 2011 - 12:22 PM, said:
Heres a starting point.
<?php
function format_query_criteria($string) {
$string = preg_replace('/(not\s)/i', '-', $string);
return $string;
}
echo format_query_criteria("Cars NOT motorbikes");
// echos: Cars -motorbikes
#7
Posted 28 December 2011 - 08:05 PM
keevitaja, on 24 December 2011 - 01:43 AM, said:
<?php $string = 'I am a string'; var_dump($string); echo '<hr>'; $bool = (bool)$string; var_dump($bool);
PHP Monkey, on 28 December 2011 - 03:35 PM, said:
<?php
function format_query_criteria($string) {
$string = preg_replace('/(not\s)/i', '-', $string);
return $string;
}
echo format_query_criteria("Cars NOT motorbikes");
// echos: Cars -motorbikesBoth you fail lol because you didn;t read the question
The op is talking about full text searching using MySQL - all the boolean operators are built into MySQL - why you'd both go and make more work is beyond me
For instance, say you wanted everything from a table called "food", where the title and description columns contained the letters "chips" , but not "bread":
SELECT `id`, `title`, `date`, `description`
FROM `food`
WHERE MATCH(title, description) AGAINST ('+chips -bread' IN BOOLEAN MODE)
You could even taking the matching further to include, exclude mutliple words, include/exclude a full word, force certain words/phrases to have a higher/lower contribution to the relevance score etc. E.g. the basis of a fairly comprehensive search function form. So using full text searching you could easily have a search form to display results:
- has a input to enter a list words where you want contained (E.g. any)
- has an input for a list of words you don't want included
- has an input for a list of words you do want included
etc.
#9
Posted 28 December 2011 - 09:20 PM
web-itec, on 24 December 2011 - 11:05 AM, said:
rallport, on 28 December 2011 - 08:05 PM, said:
No I didn't.
He wanted a way to convert "Cars not motorbikes" into "Cars -motorbikes", thats what that function I wrote does. If someone types in 'Cars not motorbikes', it will convert 'not ' into '-' for the query.
By the way when using full text searching, using the + sign isn't needed, typing '+chips -bread' is the same as 'chips -bread'.
This post has been edited by PHP Monkey: 28 December 2011 - 09:28 PM
#10
Posted 29 December 2011 - 08:54 PM
PHP Monkey, on 28 December 2011 - 09:20 PM, said:
He wanted a way to convert "Cars not motorbikes" into "Cars -motorbikes", thats what that function I wrote does. If someone types in 'Cars not motorbikes', it will convert 'not ' into '-' for the query.
By the way when using full text searching, using the + sign isn't needed, typing '+chips -bread' is the same as 'chips -bread'.
Why so touchy? It's nearly new years eve.
Anyways, have a read of the fulltext docs and you'll get what I mean.
#12
Posted 29 December 2011 - 10:45 PM
rallport, on 28 December 2011 - 08:06 PM, said:
well ive been learning/coding for 6 years yes, i have came across it and i have messed about with +this -that but i have never had to use it in a website i have made but this particular client now insists i have a boolean search
EDIT
just so you know i encouraged the client in the end that boolean search isnt really essential so ive not done it now as couldnt be bothered making the function when there was no gain from it for either me or the client but if anyone has got a function that does it then please let me know as its better for him to have than not
This post has been edited by web-itec: 29 December 2011 - 10:49 PM
Help

















