In this board you can talk about general questions about phpMyFAQ
Moderator: Thorsten
PinMan
Posts: 34 Joined: Mon May 15, 2006 2:59 pm
Post
by PinMan » Sun Aug 27, 2006 8:46 pm
Hello Thorsten/Matteo,
Are you able to explain the really bizarre search results I'm getting when doing a search for the following please:
"Where can I get a parking permit"
"When are my bins collected"
The site is here -
http://faq.cityandcountyofswansea.info and it's using phpmyfaq version 1.6.4 with mysql 4.1.18-standard.
Ideally I'd like the search to ONLY work for picking up the main keywords and not works like when, where, I, my, is, a, etc - is this possible?
Many thanks
matteo
Posts: 572 Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy
Post
by matteo » Sun Aug 27, 2006 10:04 pm
Hi "PinMan",
my first suggestion is to tune your MySQL configuration adding these lines below to your
my.cnf :
Code: Select all
[mysqld]
ft_stopword_file = /path/to/list_of_noise_words.txt
Here is the quick MySQL reference:
http://dev.mysql.com/doc/refman/4.1/en/server-system-variables.html wrote:ft_stopword_file
The file from which to read the list of stopwords for full-text searches. All the words from the file are used; comments are not honored. By default, a built-in list of stopwords is used (as defined in the myisam/ft_static.c file). Setting this variable to the empty string ('') disables stopword filtering. This variable was added in MySQL 4.0.10.
Regards,
Matteo
PinMan
Posts: 34 Joined: Mon May 15, 2006 2:59 pm
Post
by PinMan » Mon Aug 28, 2006 10:19 am
Hi Matteo,
I'm afraid that with the hosting I have it is not possible to edit either of these files
Is there a way to do this by changing the SQL 'search' query is some way?
Thank you
matteo
Posts: 572 Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy
Post
by matteo » Mon Aug 28, 2006 1:17 pm
Hi "PinMan",
PinMan wrote: Is there a way to do this by changing the SQL 'search' query is some way?
locate, backup and open
[PATH_TO_PMFINSTALL]/inc/functions.php and find these lines below:
Code: Select all
...
function searchEngine($begriff, $category = '%')
{
global $db, $sids, $tree, $PMF_LANG, $PMF_CONF;
$_begriff = $begriff;
...
and change them to read:
Code: Select all
...
/**
* removeNoiseWords()
*
* Remove some noise words, usefull if you cannot modify
* your MySQL conf in order to manage the option:
*
* [mysqld]
* ft_stopword_file = /path/to/list_of_noise_words.txt
*
* @param string
* @return string
* @access public
* @author Matteo Scaramuccia <matteo@scaramuccia.com>
* @since 2006-08-28
*/
function removeNoiseWords($text)
{
$noiseWords = array(
'what',
'where',
'why',
'when'
);
$text = str_replace($noiseWords, '', $text);
return $text;
}
...
function searchEngine($begriff, $category = '%')
{
global $db, $sids, $tree, $PMF_LANG, $PMF_CONF;
$begriff = removeNoiseWords($begriff);
$_begriff = $begriff;
...
The $noiseWords could be easily evaluated from an external file, if needed.
Ciao,
Matteo
PinMan
Posts: 34 Joined: Mon May 15, 2006 2:59 pm
Post
by PinMan » Mon Aug 28, 2006 2:04 pm
Thanks Matteo
It made the results a lot better, but is still throwing up results from the smaller words in the sentance.
Sorry to be a pain, but could I exclude words from the search which are equal to or less than say 3 letters?
I'll try and figure out how to use an external noise list - and learn something along the way 8)
Thank you for your help
matteo
Posts: 572 Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy
Post
by matteo » Mon Aug 28, 2006 3:47 pm
Hi "PinMan",
PinMan wrote: Sorry to be a pain, but could I exclude words from the search which are equal to or less than say 3 letters?
I'll try and figure out how to use an external noise list - and learn something along the way 8)
give a try to this code below:
Code: Select all
/**
* removeNoiseWords()
*
* Remove some noise words, usefull if you cannot modify
* your MySQL conf in order to manage the options:
*
* [mysqld]
* ft_stopword_file = /path/to/list_of_noise_words.txt
* ft_min_word_len = 3
*
* @param string
* @param string
* @param integer
* @return string
* @access public
* @author Matteo Scaramuccia <matteo@scaramuccia.com>
* @since 2006-08-28
*/
function removeNoiseWords($text, $filename = 'inc/noisewords.txt', $minLen = 3)
{
if (isset($minLen)) {
$words = explode(' ', $text);
$gtMinLenWords = array();
foreach ($words as $word) {
if (strlen($word) > $minLen) {
$gtMinLenWords[] = $word;
}
}
$text = implode(' ', $gtMinLenWords);
}
// Case sensitive noise words array
$noiseWords = @file($filename);
if (is_array($noiseWords)) {
$text = str_replace($noiseWords, '', $text);
}
return $text;
}
Ciao,
Matteo
PinMan
Posts: 34 Joined: Mon May 15, 2006 2:59 pm
Post
by PinMan » Mon Aug 28, 2006 6:08 pm
Hello Matteo,
Thanks - it's working a lot better now
Only one slight problem, I'm getting "No entries available." displayed on the search results page - even when there are results.
On a slightly different note, is there a way to rank to search results and have them weighted on the keywords rather than on the full answer text (and sorted on the ID as they appear to be now)?
Thanks,
PinMan
matteo
Posts: 572 Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy
Post
by matteo » Tue Aug 29, 2006 9:50 pm
Hi "PinMan",
PinMan wrote: Only one slight problem, I'm getting "No entries available." displayed on the search results page - even when there are results.
Maybe it is the result of the 50% threshold using the MySQL full-text search. Try to use
"+" as the prefix of a word to see if that threshold is the reason of your strange results. Another reason could be that your result set has less than 3 record and MySQL drop it.
PinMan wrote: On a slightly different note, is there a way to rank to search results and have them weighted on the keywords rather than on the full answer text (and sorted on the ID as they appear to be now)?
You need:
to modify the full text index on faqdata table from:Code: Select all
FULLTEXT (keywords,thema,content), to: to rebuild the index: to modify a little bit the searchEngine function in inc/functions.php to remove the fields removed from the full text index, that is to say from:Code: Select all
array(SQLPREFIX."faqdata.thema",
SQLPREFIX."faqdata.content",
SQLPREFIX."faqdata.keywords"), to:Code: Select all
array(SQLPREFIX."faqdata.keywords"), (not tested)
Ciao,
Matteo
PinMan
Posts: 34 Joined: Mon May 15, 2006 2:59 pm
Post
by PinMan » Thu Aug 31, 2006 8:53 pm
8) Matteo
Your solution worked a treat, thank you so much
matteo
Posts: 572 Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy
Post
by matteo » Thu Aug 31, 2006 9:42 pm
My pleasure, glad to read it worked!