1

我有大约 280,000 个文件需要搜索,并返回并打开正确的文件。文件名与预期的搜索词完全匹配。

搜索词将由使用 PHP 的输入框获取。完成此操作的最佳方法是什么,以便搜索不会花费大量时间?

谢谢!

4

2 回答 2

2

I suspect the file system itself will struggle with 280,000 files in one directory.

An approach I've taken in the past is to put those files in subdirectories based upon the initial letters of the filename e.g.

1/100000.txt
1/100001.txt
...
9/900000.txt

etc. You can subdivide further using the second letter etc.

于 2012-10-18T16:14:45.623 回答
0

Its good you added mysql to your tags. Ideally i would have a CRON task that would index the directories into a mysql table and use that to do the actual search. Algebra is faster than File System iteration. You could run the task daily or hourly depending on how often your files change. Or use something like Guard to monitor the file system for changes and make appropriate updates.

See: https://github.com/guard/guard

于 2012-10-18T16:14:34.857 回答