Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

Search:

Online AI coding exercises

Project ideas


PHP search engine

My search engine is written in PHP.
It has a simple Linux grep underneath it.
e.g. Search for grep.

  

Plan

  1. We will search the Works of Shakespeare.
  2. Take in an argument from a form.
  3. The argument is in the URL (HTTP GET).
  4. Make a command-line call to something like:
     cd (somedir) ; grep -i (searcharg) */*html 
    (";" allows two commands on one line)
  5. Collect the grep output in a PHP variable.
  6. Note we did case-insensitive search.

What to link the hit to

  

Make the hits clickable

  

How to stop "infinite" output

What if grep returns tens of thousands of lines?
What if someone searches for a single character?

Here is a simple solution: Pipe grep to head, which collects the first n lines of what is piped into it.

  1. Collect the first 500 lines and no more:
     grep string files | head -500 
  2. The previous will actually terminate grep once 500 is reached.

ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.      New 250 G VPS server.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.