views:

42

answers:

2

Hello

I have a MySQL database that I replicate from another server. The database contains a table with this columns

ID, FileName and FileSize

In the table there are more than 4'000'000 records. I want to make fast a search in FileName (varchar) column

I found that I can use for this Sphinx search engine. The problem is that I want to restrict searches by filetype. Do I have to and how (trigers?) to extract file extensions for all rows? May be I have to create another table (because this one is replicated) and join them in 1:1 relation?

Can you give me some advices please :)

A: 

Why not use an SQL query with a Regex?

Make it something like...

.$query.\.$extension

That would wildcard match the search term into the filename, then a period, then the extension name.

Crowe T. Robot
I think that this kind of search is not well optimized (from what I know about indexes) Another reason is that may be I will need to make some filename transformations, for example devide "MyPicture.jpg" tocolumn "My Picture" (with space) and column "jpg" (filetype)
ju
A: 

You'll definitely want to separate the file type into a separate column - this will allow you to direct a Sphinx search on that term (with the match mode set to extended):

normal query terms @filetype jpg

However, this is not exact matching - it will still use Sphinx's intelligence around word matches and such. This may be what you want, but if you don't, I recommend normalising your db and putting file types in another table, and having a foreign key in your files table. Then, you can use this integer as an attribute in your Sphinx setup, and filter on it using the particular file type's id. This will be faster and more reliable in Sphinx, but it is a bit more work.

pat