I am trying to query the windows desktop search API using SQL.
I have to say I really HATE the windows 7 search GUI, and so I decided to write my own. I have a lot of files indexed (approx 1.000.000), and I want to do a search for names. Something like: Show me every name which contains "bunny".
But here i run into a performance problem. Searching for
SELECT "System.ItemPathDisplay"
FROM "SystemIndex"
WHERE System.FileName LIKE 'egon%'
is really fast. Also the %egon
alternative. But %egon%
takes forever. I am not sure if it is in the nature of the index (I understand that the possibilities increase enormously) or if I am doing something wrong.
The question is:
If I have that, its basically just optimizing SQL.
Alternative question: Does anybody knows a fast SQL statement to find all files with egon somewhere in the name.
Edit: Why I do not like the search GUI
Well, its just not intuitive, compared to XP. If you disable the dog and use the old XP interface, I could create a search query like:
- All files older than 1 month
- bigger than 10 MB
- name pattern
*_homework_*.docx
Try this in Windows 7 without "learning" the syntax. And hell, I do not want to learn another syntax just to find one file.
The other main problem are maybe my search habits. Most of the time I somehow know the file name (or parts) and simply want the location. And if you use the search this way you ran into several problem:
And now I really think my system has a bug. I tried to quickly check it, searched in some average size folder for "test" and he found some files. Then I tried to sort them for folders (to verify my second point) and now he is just searching forever... I mean really, while I am typing he tries to find the word "hello"... oh, finished - he found approx 20 files. So, now, lets try something.... Ok, now it seems like he has recovered.. But still, to slow for my taste...
So, enough cursing about search :-)
It looks like they're building an index on the name, so it can use the index as long as you've specified the beginning of the string, but if you haven't, it has to use a table scan.
Assuming they're using Microsoft's full-text search engine, then try using something like:
... WHERE system.filename CONTAINS 'egon'
There are basically two choices: it'll be rejected as invalid (i.e. this SQL interface doesn't support their F-T search extension) or else it'll be quite a bit faster.
EDIT:Oops -- the syntax should be "contains(system.filename, 'egon')". Sorry 'bout that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With