[an error occurred while processing this directive]
![]() | Types of Searches |
This page explains the concept of a "search type" as well as some basic concepts of searching which you may need to learn if you want to try using a more complex searching method. These search type concepts will help you understand the definitions given for each of the specific search types you can choose via the glimpse_type parameter on a Glimpse search form.
Glimpse knows how to do several different kinds of searches. The search type (defined by the glimpse_type parameter) refers to these different kinds of searches you can have Glimpse do for visitors to your site.
You may prefer to not concern yourself with the type of search and just allow the Glimpse search facility to always use the default and fastest search type (the whole word search).
If the default search type is not meeting a specific search capability you wish to provide, you may want to explore some of the more complex and powerful search types; you'll need to understand these concepts in order to choose one of the types.
The extra power of these other search types comes with a price:
In most cases, the user (people using your search form) will need to understand how to take advantage of the more powerful search.
Either they'll have to already know about the search type, or you'll have to explain it to them (or put a link to our explanation). If you use a form that permits a special kind of search but nobody ever uses it (e.g., they still most always just type one whole word to search for), you may be having Glimpse do extra work when the simple word search would have done the same thing faster. Which brings us to the next note...
These other search types will range from "not quite as fast" to "very slow" (depending on the specific search terms entered by the user as well as on the search type and possibly to no extra benefit as explained above, if visitors to your site do not take advantage of the extra capability).
One of the purposes of telling Glimpse what type of search you're doing is that in some cases Glimpse can skip many steps and save time by having that knowledge which lets Glimpse know how much of the index it needs to search.
For example, in a simple word search (since the Glimpse index is a sorted list of words like a dictionary with pointers for each word to the file(s) containing the word), if only one word is entered by the user. Glimpse knows it only has to search the index, and it knows exactly where in the index to check as well. This is why a simple word search is usually the fastest search type.
Of course, if you specify a search type that doesn't require consulting the files themselves, but ask Glimpse to show the matching lines from the file, it will have to search the file anyway, but may still save some time because it need only search certain matches and not potential matches which turn out to be rejects.
Enough generalities; the next section will explain some basic search concepts employed by Glimpse.
This section explains some basic concepts of Glimpse searching (and searching in general).
The following are not the types of search which you may select, but rather an explanation of some the concepts used in the explanations of the types of searches.
Whole Word Searches (vs. "substring searches")By a "whole word" search, we mean probably just what you guessed; that only whole words are matched. For instance, if the user were to enter "car", as the search term, a file containing "the fastest car on the road" would match in a whole word search but not a file containing "NASCAR" or "cartoon" (unless of course the file had car as a separate word somewhere else in it). In the first example car is a separate word, but in latter two it's just part of a word.
To put it another way: in a whole word search, the search term or terms entered by the user are treated by Glimpse as representing whole words; most often a single word or several words.
A whole word search only matches if the pattern entered by the user matches a pattern in the file which is surrounded only by blanks, tabs, or other non-visible characters (or no characters, such as at the end of a line).
The opposite of a whole word search is referred to as a "substring search," a "partial word search," or a "word fragment search."
Boolean SearchesThe word Boolean refers to the famous mathematician George Boole who invented Boolean logic. All it really means is the logical conjunction of several terms (in our case search terms, in other cases mathematical terms or logical premises) with the 'Boolean operators' 'AND,' 'OR,' and/or 'NOT'.
A Boolean value is just a value that can have one of two states (on or off, TRUE or FALSE, or whatever two words you may choose to represent the two states). In Boolean logic, for instance, each premise has a Boolean value (TRUE or FALSE). The premises are linked together with Boolean operators (AND, OR, NOT). The expression can then be reduced to a single value (TRUE or FALSE).
For example: Take your umbrella if it is raining OR it is cloudy. The two premises (it is raining, it is cloudy) are each either TRUE or FALSE. Because they are linked with an OR, we know that if either one is TRUE then the entire expression reduces to TRUE (in other words, the conclusion you should take your umbrella is TRUE if either of the premises is true).
Take your sunscreen if it is NOT raining AND it is NOT cloudy. The two premises are the same (it is raining, it is cloudy), but in this case they are modified by the Boolean NOT. Suppose it's cloudy but it's not raining. It is cloudy = TRUE, and it is raining = FALSE. NOT(it is cloudy) = NOT(TRUE) = FALSE. It is raining is FALSE, so NOT(it is raining) is TRUE. So the expression reduces to NOT(TRUE) AND NOT(FALSE) or TRUE AND FALSE. The AND only reduces to TRUE if both clauses are TRUE, so TRUE AND FALSE = FALSE (don't take your sunscreen).
If this seems like a hopelessly convoluted method to determine whether to bring your sunscreen, its because human beings have natural thinking mechanisms which make the conclusion obvious without having to undertake such a painstaking logical analysis. However, computers don't have these thinking capabilities, but they can reason effectively using simple Boolean logic.
Here is an example of a Boolean Expression: (can you tell which of the statements following it is the correct interpretation?)
"Buy the stock if its price is less than 50 AND the earnings report is favorable OR the merger goes through."
Is the correct interpretation of the statement above:
Or is the correct interpretation:
"By the stock if..."
(The answer: the first set of conditions is the correct interpretation, because the Boolean AND takes precedence over the Boolean OR; so we conjoin the first two conditions, find the answer, then test (OR) that answer with the third condition. Parenthesis can be used to override Boolean precedence (the second interpretation would be correct if the rule were written as: "price < 50 AND (earnings report favorable OR merger goes through)")).
What does all this have to do with glimpse searching? Glimpse supports a Boolean search. What this means is you can not only tell Glimpse to "find me all files containing this word", but you can also give it more complex Boolean instructions like "find me all files that have this word AND this word, AND which also have any one of these three words ." Rewriting this request in Boolean terms, we have: "find all files for which the following reduces to TRUE: word1 AND word2 AND (word3 OR word4 OR word5)" (where the word is TRUE if its in the file).
Note we had to use parenthesis to override the precedence of AND. If we had not used the parenthesis, we would have been saying "find all files having word1 AND word2 AND word3 OR having either word3 OR word4."
Glimpse uses a semi-colon for AND, a comma for OR, and curly brackets {} for parentheses.
So, our above five word search would be written as a Glimpse search pattern as follows:
word1;word2;{word3,word4,word5}
This concludes our introduction to glimpse search types. By understanding these concepts (Whole Word searches and Boolean searches), you are prepared to choose a Glimpse search type for your search form using the glimpse_type search parameter.
[an error occurred while processing this directive]