Another search question

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

Post Reply
wmcasey
Posts: 12
Joined: Mon Nov 17, 2003 7:32 pm

Another search question

Post by wmcasey »

Is there an easy way to alter the searching to search ONLY for keywords? it appears as though now it searches through the content and titles as well.

Perhaps just altering the index?


Bill
Thorsten
Posts: 15724
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi Bill,

you have to change the table structure and the function of the search engine. Do you use phpMyAdmin, then this is very easy to realize.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
wmcasey
Posts: 12
Joined: Mon Nov 17, 2003 7:32 pm

Post by wmcasey »

I do use phpmyadmin, how woudl you recommend I alter the index?
Thorsten
Posts: 15724
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi Bill,

just execute these queries:

Code: Select all

ALTER TABLE <prefix>faqdata DROP INDEX keywords

Code: Select all

ALTER TABLE <prefix>faqdata ADD INDEX keywords ('keywords'(1)) 
Then edit the function searchEngine() in the file functions.php. Change this part:


Code: Select all

    if (mysql_check("4.0.1") == FALSE) {
        // Search with MySQL 3.23.23+
        $query = "SELECT id, lang, rubrik, thema, content FROM ".$sqltblpre."faqdata WHERE MATCH (thema,content,keywords) AGAINST ('".$begriff."') AND active = 'yes'";
        }
    else {
        // Search with MySQL 4.0.1+
        $query = "SELECT id, lang, rubrik, thema, content FROM ".$sqltblpre."faqdata WHERE MATCH (thema,content,keywords) AGAINST ('".str_replace(" ", "* ", trim($begriff))."*' IN BOOLEAN MODE) AND active = 'yes'";
        }
to this:

Code: Select all

    if (mysql_check("4.0.1") == FALSE) {
        // Search with MySQL 3.23.23+
        $query = "SELECT id, lang, rubrik, thema, content FROM ".$sqltblpre."faqdata WHERE MATCH (keywords) AGAINST ('".$begriff."') AND active = 'yes'";
        }
    else {
        // Search with MySQL 4.0.1+
        $query = "SELECT id, lang, rubrik, thema, content FROM ".$sqltblpre."faqdata WHERE MATCH (keywords) AGAINST ('".str_replace(" ", "* ", trim($begriff))."*' IN BOOLEAN MODE) AND active = 'yes'";
        }
I have not tested it! But it should work...

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
wmcasey
Posts: 12
Joined: Mon Nov 17, 2003 7:32 pm

Post by wmcasey »

Alright, I have made these changes. Seems like it is not finding the keywords properly. I have tried searching for many items and no articles are being returned.

If I look at the phpmyadmin "structure" page, it says that the keywords indexd has a cardnality of 24. I think that it should be higher than that.

Perhaps we are not entering the keywords properly??
Thorsten
Posts: 15724
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

does this query

Code: Select all

SELECT id, lang, rubrik, thema, content FROM faqdata WHERE MATCH (keywords) AGAINST ('<your search>') AND active = 'yes'
work in the SQL console in phpMyAdmin?

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
wmcasey
Posts: 12
Joined: Mon Nov 17, 2003 7:32 pm

Post by wmcasey »

I think we have it. The index type defaulted to >index>, I changed it to fulltext, and it seems like it is working.



Thanks a bunch for your help!


Bill
Thorsten
Posts: 15724
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi Bill,

okay, that's great! :)

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply