Google currently uses keywords such as site:
or is:
in searches (the second example is from Gmail). I'm trying to develop a similar system and am wondering how best to go about identifying and handling those terms. For simplicity's sake, assume an OO language is being used (Ruby, Python, Java, C#, et al).
Currently, my plan is to have a separate class for each keyword. These classes have a precedence value and three methods:
isRelevant(String searchPhrase)
: Returns true if the search phrase matches the class's filter.getResults(String searchPhrase)
: Returns a list of results based on the search phrase.reviseSearch(String searchPhrase)
: Returns a modified version of the search phrase. This will normally be removing the match to avoid it being processed again by a lower-precedence instance, but might also add text or clear the string entirely.
The calling method will then go through these keyword filters until the search phrase is empty or there are no more filters (in the latter case it will revert to its normal search behavior).
Thus, the question: Is this the most efficient way of doing this, or is there some more appropriate method? Some of the details still need to be figured out, but is this a step in the right direction?