i need to do a file search with php, and i have the filename search down, with glob, but i still need to search inside files.
i have a prototype, at tann98.vacau.com/file-search, but i need keywords, and suggestions. plus it needs to look inside files to find matches.
does anyone have ideas on how to do this kinda thing?
A very basic method would be to read each file into PHP and search through them with one of the string searching functions.
However this is very inefficient, since you will have to do that file reading and searching every single time you perform a search.
That’s why search engines create indexes of the entire files they know about in advance, and then just look into those indexes for the search keyword. If you want to look into that, you would need a separate script (say indexer.php) that will do something like this:
And have it run every now and then to update its index. Its index could for example look like this:
Then, when you are searching for a certain keyword, you just need to load the index from your index file or database and see which filenames that word is found in.
And there you have a very simplistic way of doing something like this. Further down the road you can store the index into a database, count how many times a word is found in each file to provide more relevant results, etc etc.