Advanced Searching:  Using Comparison Logic and Operators


The MySQL database used in this application allows the user to specify logical comparison operators in order to select records from the database.  If you are familar with mathematical or computer programming logic, you might try your hand at a few searches to get a feel for how this all works.  Our implemenation is similar to style of searching known as query by example.  The advanced version allows you to add the the logical operators right in the fields.  You must remember to check the "Advanced Searching" checkbox before actually requesting your search.

Here are some examples of using logic on several of the fields in the database.  Be aware that you cannot use logic operators on text fields.  Searching with logical operators in text fields requires a much more complex user interface.

Also we should point out that you MUST use the actual database table column names.  These names are not always those shown in the application.  See the column names reference  for more information.

Note also that across columns there is an implicit "AND".  For instance if you entered 3 in the N field and 5 in the Rating field, you are asking for a search that will compare and match only if N = 3 AND Rating = 5.  Currently there is no provision in our application to allow "OR"ing of two columns in the database.  Having said that, if you use the wildcard character "%" and do not check the Advanced Searching checkbox,  you may be able to simulate an OR function

Sample Wildcard Searches

Field
Search Operation
Results

Flags
SiteFlags < 100
All database reords with the SiteRating field set to 0, 1... to 99 or set to a minus number will match and be displayed in your results table.

N
N >  1 AND N < 10


If the database has twelve records with N = 1,2,3,4,5,6,7,8,9,10,11,12, records with 2 thru 9 will be selected and displayed

Active
Active = 0 OR Active > 0
Active is a special type of number, a boolean value (1 or 0), and thus there are only two values to be found.  It is much easier just to use hon-advanced searching and put in a "%" instead. However, this has the same effect, any value of Active will match.

Rating
SiteRating <> 0
Will return all the records where the Rating field is not zero.  Since this is a numeric field, even fields "defaulted" (no value has been entered by anyone) will not be found in the displayed results.


Logical Comarison Operators

Operator
Example Usage
Function

>
N > 1


Greater Than: Will match your search if the value in the field is 2 or greater, but not match 0 (zero), 1 or any minus number

<
N < 2
Less Than: Will match your search if the value in the field is a minus number, 0 (zero) or 1, but not match any values that are 2 or greater

>=
SiteRating >= 1
Greater Than or Equals: Will match your search if the value in the field is 1 or greater (2,3,4, etc.) but will not match a minus number or 0 (zero)

<=
SiteFlags <= 5
Less Than or Equals: Will match your search if the value in the field is a minus number, 0 (zero), 1, 2, 3, 4, or 5, but will not match any number greater than 5 (i.e. 6,7,8, ... etc will not match).

<>
Expand_1 <> 0
Not Equals: Will match if your search if the value in the field is a minus number or a positive non-zero number (i.e. -2, -1, 1, 2 etc)

AND
N > 1 AND N < 10
Logical AND: Matches two phrases, the "left" and the "right" . If both "evaluate" to TRUE, then you have a logical match and the search will display results.  For this example, the only matching numbers will be 2,3,4,5,6,7,8, and 9. 

OR
SiteRating = 5 OR SiteRating  > 9
Logical OR: Matches two phrases, the "left" and the "right".  If either the left phrase (SiteRating=5) OR the right phrase (SiteRating > 9) is TRUE, then the search will match.  For instance, in this example records with 5 OR 10, 11, 12...(i.e. all values greater than 9) will match your search.

The SiteCategory field offers a pulldown menu of the Categories used in the database.  Currently this is the only way to specify searches for this particular field.  To match a particular category, simply click on the arrow and select one of the category types.  MATCH ALL does just that, searching the entire database matching all categories.  MILNET CHOICE searches for database records that match categories germaine to the MILNET subject matter, i.e, will match categories such as "MILITARY", "INFO", "RESEARCH", "OPINION", "SPACE", or "TERRORISM".  This leaves out activist sites, those with highly political propoganda, conspiracy theory sites, arms control sites, videos, images, and totally irrelevant sites such as games. The WEAPONS category is not included in the MILNET CHOICE selection since we use that category to specify weapons non-military enthusiast's sites, typically focusing on civilian weapons, tactical equipment and civilian gun control. 

The table below indicates if a field is a numeric field or a text field.  You should use different search strategies for text than numbers when using advanced searching.

Number
1 or 0
Text
Text
Text
Text
Text
Text
Number
Number
Number
N
Active
Category
Sub-Category
Name
Theme/Keyword
Description
URL
Rating
Flags
Exp_1
N
Active
SiteCategory
Expand_2
SiteName
SiteTheme
SiteComment
SiteURL
SiteRating
SiteFlags
Expand_1

Use the bolded text when entering advanced searches in the fields .  Note that SiteCategory may only be selected using the pull down menu category items.

Some other notes on the database: 



© Copyright 2008, Michael G. Crawford for MILNET