3 thoughts on “Simple text search in PHP

  1. Part of being a good programmer is picking the best tool for the job.

    Most databases offer various search solutions for exactly the job you want to do. Staying away from it would, then, make you…?

    Free cookie for the person to guess the correct answer. No deliveries, unfortunately.

    As for nudges, can’t you ‘just’ perform two separate searches for the OR followed by a merge and do a filter for the NOT operator? I know it’ll increase load and decrease performance, but seriously, that’s the consequence of not picking the best tool for the job.

    In addition, thinking in Java-ey terms, you could, instead of concating the search string, make it a set of ‘search objects’, consisting of string and operator, and ‘iterate’ over all song titles for all the search objects. But that’s a bit of work for something simple…

  2. Expanding on the search objects idea:

    Three types of search objects:
    AND
    OR
    NOT

    For all search terms (every word in your search term) you create an object with the desired operator. Then you iterate over all song titles and only include the song title if it includes ALL the search objects of type AND, OR if it includes one of the search objects of type OR, and ONLY if it does not include one of the objects of type NOT.

    As said, it’s a bit complex for a simple tool, but eh.

  3. I really like your idea of the Java-tool, and heck: I even considered building one before me posting this. Extensibility, and just the fun of building it were it’s pro’s, the con’s of it being a little overdone and the necessary integration with Apache kind of held me back from creating such a tool.

    The reason for me to not use mySQL or the likings is that I really like the simple idea of building my own search-tool with does its work without the overhead of bigger platforms and on a plain text file.
    Blah, I guess it’ll be the DB then; incrementally updating the DB will be my first task 😉

    I’m still open for any additions or nudges though 😀

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.