I have some text files inside a directory (and its sub directories). The number of text files will be (50000+) and the directory is outside 'public_html':
text_root_dir
|-- |-- `001
|-- text0003.txt
|-- text0004.txt
|-- text0005.txt
|-- `001_a
|-- text0006.txt
|-- text0007.txt
|-- text0008.txt
|-- text0001.txt
|-- text0002.txt
The text file details are saved in a MySQL table (with the 'art_textfile' storing the text file name and 'art_path' column storing the file path):
CREATE TABLE `stxt_articles` (
`art_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
`art_title` VARCHAR(127) NOT NULL,
`art_author` VARCHAR(255) NOT NULL,
`art_textfile` VARCHAR(255) NOT NULL, /* TEXT FILE NAME */
`art_path` VARCHAR(255) NOT NULL, /* TEXT FILE PATH */
PRIMARY KEY(`art_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
I am using PHP/MySQL (LAMP) and want to do a string search on the text files (with regular expressions if possible). The methods that will work logically are:
- Storing the contents in the MySQL database and perform a search with MySQL query (LIKE 's%')
- Scan the directory by PHP and search within each text file for a search expression.
But with a large dataset of 5000 +files (tend to grow over time), the above options are not practical. It will be too slow to use.
What I am looking for is a PHP/MySQL search idea which creates index for text files and do a search. Pretty much what Lucene does in JAVA. Maybe I can refer it as a lucene alternative in PHP with MySQL.
Thanks for reading this far. Also thanks for your thoughts.