Loading...
 
Skip to main content

Development


Modifying the search module

Hi

I've modified the upload form for file galleries so that extra keywords are collected for each file, these are stored in an additional filed in the tiki_files table.

I've been trying to figure out how the search module works, and am a bit stuck. There's a function 'find_files' in searchlib.php that looks like I should simply be able to modify
'data' => 'description',
to
'data' => 'keywords',

However, when I do this the page doesn't display. Any suggestions as to what I should do to be able to search my additional keywords. Is there any way to concatenate description and keywords?

Any help welcomed.

Thanks

Andrew

Hi,

I'm dont know much in the search area, however is "keywords" being included in the seachs SQL query ?

Damian


> I'm dont know much in the search area, however is "keywords" being included in the seachs SQL query ?
>

Hi Damian

I was hoping so. Perhaps I've just misunderstood the code, but I thought making the above change would swap my 'keywords' text into data, and then the function would simply search through the text in keywords instead of that in the description. I posted flo a message directly to see which array was used as the data feed.

I guess I'm simply not fully understanding what the code is doing, and therefore changing it incorrectly. Looking at the search functions it looks like the different areas put their data into common variables, and these are then searched by one bit of SQL. I was simply trying to feed different data into the existing variables. I've had a little email to Flo who I believe's the search guru, so I may be trying to pick people's brains on icq shortly. But this has all been rewritten for 1.8 apparently to make it database independant.

Cheers, and thanks for replying

Andrew



> I'm dont know much in the search area, however is "keywords" being included in the seachs SQL query ?
>

Hi Damian

I was hoping so. Perhaps I've just misunderstood the code, but I thought making the above change would swap my 'keywords' text into data, and then the function would simply search through the text in keywords instead of that in the description. I posted flo a message directly to see which array was used as the data feed.

I guess I'm simply not fully understanding what the code is doing, and therefore changing it incorrectly. Looking at the search functions it looks like the different areas put their data into common variables, and these are then searched by one bit of SQL. I was simply trying to feed different data into the existing variables. I've had a little email to Flo who I believe's the search guru, so I may be trying to pick people's brains on icq shortly. But this has all been rewritten for 1.8 apparently to make it database independant.

Cheers, and thanks for replying

Andrew


Got this one sorted thanks to a friend (Anu).

For anyone else interested.

Add the extra field to the table (keywords in my case)
Add keywords to the full text index (sql I think is create index(fulltext) on tablename(field) - check this out as it's from memory)

Then in searchlib.php

In the function you're adding to eg. find files add an Extra line
'keywords' => 'keywords',

In the main function _find (at the top)
after the array_push line under $search_fields add the line
if ($h['keywords'] && $h['name'] != $h['keywords']) array_push($search_fields, $h['keywords']);
et voila you should now be able to search in your new field. A few quirks noticed on the way include it has to be an EXACT match, and the search term must be 4 or more characters.

Apparently this file is rewritten for 1.8 to make it database independant, but I thought it may be of use for those using the older versions.

Cheers

Andrew



One more addition

the code below doesn't work if the same word appears in e.g. the description and the keyword. To get around this you need to change the line about match against to

$sqlft ='MATCH(' .join(',', $search_fields) . ') AGAINST ('.$qwords.' IN BOOLEAN MODE)';

There are more boolean mode options that I've not explored, so you may change the syntax further.... see...

http://www.mysql.com/doc/en/Fulltext_Search.htmlQuestion

for further details

Cheers

Andrew