title: PHP search engine for text files with indexing
body: <p>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':</p>
  <pre><code>text_root_dir
  |-- |-- `001
             |-- text0003.txt
             |-- text0004.txt
             |-- text0005.txt
             |-- `001_a
                     |-- text0006.txt
                     |-- text0007.txt
                     |-- text0008.txt
      |-- text0001.txt
      |-- text0002.txt
  </code></pre>
  <p>The text file details are saved in a MySQL table (with the '<em>art_textfile</em>' storing the text file name and '<em>art_path</em>' column storing the file path):</p>
  <pre><code>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;
  </code></pre>
  <p>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:</p>
  <ol>
  <li>Storing the contents in the MySQL database and perform a search with MySQL query (LIKE 's%')</li>
  <li>Scan the directory by PHP and search within each text file for a search expression.</li>
  </ol>
  <p>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.</p>
  <p>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.</p>
  <p>Thanks for reading this far. Also thanks for your thoughts.</p>