This is an old revision of the document!


Administration: Omnidex Indexing

PowerSearch

The SQL Behind PowerSearch

In most scenarios, the key to implementing PowerSearch is the $CONTAINS function in Omnidex SQL. This function provides access to most of the search capabilities shown on the previous page.

The $CONTAINS Function

The $CONTAINS function is used in the WHERE clause of a SELECT statement to provide criteria accompanied by special options. In traditional SQL statements, criteria is specified using a syntax of:

  SELECT        COUNT(*)
    FROM        LIST
    WHERE       FNAME = 'Bill';

The $CONTAINS function allows this same statement to be reworded as follows:

  SELECT        COUNT(*)
    FROM        LIST
    WHERE       $contains(FNAME, 'Bill');

The real advantage of the $CONTAINS function lies in the options that can be added. The $CONTAINS function is discussed in depth in the documentation on the function. Meanwhile, the following examples show how the options were used to provide each of the capabilities shown on the previous page.

First Name

When searching a database containing first names, you never know whether the formal given name is stored, or one of common variations. PowerSearch will automatically search for common synonyms for first names.

Here are some examples:

Given Name Synonyms
William Bill, Billy, Will, Williams, Willie, Willis, Wilson
James Jim, Jimmy, Jimmie, Jay, Jaime, Jacob
Elizabeth Beth, Betty, Eliza, Elsa, Lisa, Liz, Liza
Ann Ana, Anita, Anna, Anne, Annette, Annie, Annmarie
———————————————————————————————————————————————————–

The SQL syntax for given name synonyms searches is shown below.

  SELECT        ...
    FROM        ...
    WHERE       $contains(FNAME, 'Bill', 'SYNONYMS=ALL_GIVEN_NAMES') ...

Last Name

Many last names sound similar, but are spelled differently. For this reason, phonetic algorithms such as Soundex or Metaphone are commonly used to find last names that sound similar to each other. PowerSearch will automatically search for phonetic equivalents for last names.

Here are some examples:

Last Name Phonetic Equivalents
Smith Schmit, Schmidt, Schmitt, Smidt, Smit, Smith, Smithey, Smyth, Smythe
Meyers Meyers, Myers, Myres, Meiers, Moyers, Meers, Mayers, Maris
Nelson Nelsen, Nielsen, Nielson, Neilsen, Neilson, Nilsen, Nilson, Nilsson
Williams Willaims, Wiliams, Willimas, Wilmes, Willams, Willems
———————————————————————————————————————————————————–

The SQL syntax for phonetic last name searches is shown below.

  SELECT        ... 
    FROM        ... 
    WHERE       $contains(LNAME, 'Meyers', 'PHONETIC') ...

Address

Many addresses use both common and uncommon abbreviations. Street numbers can be easily transposed. Street names can be easily misspelled. PowerSearch will automatically look for abbreviations, misspellings and transpositions.

Here are some examples:

Category Search Term Equivalents
Street Types Ave, St, Blvd Avenue, Street, Boulevard
Street Directions N, S, E, W North, South, East, West
Street Names (abbreviated) 1st, 2nd, 3rd, 4th, 5th First, Second, Third, Fourth, Fifth
Street Names (misspelled) Canterbury Cantaberry, Canterbury, Cantabury
Unit Types Apt, Ste, Rm Apartment, Suite, Room
Street Numbers 12345 13245, 15324, 1234, 2345
———————————————————————————————————————————————————-

The SQL syntax for postal abbrevation synonym searches and misspelling searches is shown below.

  SELECT        ...
    FROM        ...
    WHERE       $contains(ADDRESS1, '825 Fifth Avenue', 
                          'SYNONYMS=ALL_ADDRESS_LINES,MISSPELLINGS') ...

City

Some cities have common abbreviations and others can be easily misspelled. PowerSearch will automatically look for common abbreviations and misspellings.

Here are some examples:

Category Search Term Equivalents
Abbreviations SF, LA, NY San Francisco, Los Angeles, New York
Misspellings Milwaukee Milwalkee, Milwauki, Milwalke
———————————————————————————————————————————————————-

The SQL syntax for city synonym searches and misspelling searches is shown below.

  SELECT        ... 
    FROM        ... 
    WHERE       $contains(CITY, 'NY', 'SYNONYMS=CITY_ABBR,MISSPELLINGS') ...

Zip Code

Zip codes are sometimes guessed based on their approximate geographic location. PowerSearch will automatically search for zipcodes that are geographically adjacent to this zip code.

Here are some examples:

Zip Code Adjacent Zip Code Distance
10021 10162 .48 miles
10155 .64 miles
10028 .67 miles
10044 .73 miles
10052 .80 miles
10022 .82 miles
———————————————————————————————————————————————————-

The SQL syntax for zip code geographic radius searches is shown below.

  SELECT        ...
    FROM        ...
    WHERE       ZIP IN
                (SELECT        ZIP
                   FROM        ZIPCODES
                   WHERE       $distance((SELECT LATITUDE,
                                              LONGITUDE
                                  FROM        ZIPCODES
                                  WHERE       ZIP = '10022'),
                               LATITUDE,
                               LONGITUDE) <= 5) ...

Phone Area Code

Some metropolitan areas use multiple area codes, leading people to be unsure which area code to use. PowerSearch will automatically search the alternate area codes.

Here are some examples:

Metropolitan Area Area Codes
New York, NY 212, 646, 917
Denver, CO 303, 720
Seattle, WA 206, 360, 253, 425, 564
———————————————————————————————————————————————————–

The SQL syntax for telephone area code synonym searches is shown below.

  SELECT        ...
    FROM        ...
    WHERE       $contains(PHONE1_AREA, '917', 'SYNONYMS=AREACODES') ...

Phone Prefix and Suffix

Telephone numbers are easy to transpose or mistype. PowerSearch will automatically search for transpositions and typographical errors in your telephone numbers.

Here are some examples:

Phone Number Transposition
775-4866 755-4846
831-6584 381-8564
———————————————————————————————————————————————————–

The SQL Syntax for telephone number transposition searches is shown below.

  SELECT        ...
    FROM        ...
    WHERE       $contains(PHONE1_PREFIX, '755', 'MISSPELLINGS MIN_SCORE=70') AND \
                $contains(PHONE1_SUFFIX, '4686', 'MISSPELLINGS MIN_SCORE=70') ...

Email

This column contains the e-mail address for the individual. You may also enter just the mailbox name or the domain name. For example, you may enter 'mailbox@domain.com' , or just 'mailbox', or just 'domain.com'. PowerSearch will additionally search for phonetic equivalents or misspellings of your email address.

  SELECT        ...
    FROM        ...
    WHERE       $contains(EMAIL, 'wmeyers@med.cornell.edu', 'MISSPELLINGS MIN_SCORE=80') ...

Final SQL Statement

When combined, the final SQL statement has many $CONTAINS functions which combine to provide the full power of PowerSearch:

  SELECT        COUNT(*)
    FROM        LIST
    WHERE       $contains(FNAME, 'Bill', 'SYNONYMS=ALL_GIVEN_NAMES') AND
                $contains(LNAME, 'Meyers', 'PHONETIC') AND
                $contains(ADDRESS1, '825 Fifth Avenue',
                'SYNONYMS=ALL_ADDRESS_LINES,MISSPELLINGS') AND
                $contains(CITY, 'NY', 'SYNONYMS=CITY_ABBR,MISSPELLINGS') AND
                LIST.STATE = 'NY' AND
                ZIP IN
                (SELECT        ZIP
                   FROM        ZIPCODES
                   WHERE       $distance((SELECT LATITUDE,
                                              LONGITUDE
                                  FROM        ZIPCODES
                                  WHERE       ZIP = '10022'),
                               LATITUDE,
                               LONGITUDE) <= 5) AND
                $contains(PHONE1_AREA, '917', 'SYNONYMS=AREACODES') AND
                $contains(PHONE1_PREFIX, '755', 'MISSPELLINGS MIN_SCORE=70') AND
                $contains(PHONE1_SUFFIX, '4686', 'MISSPELLINGS MIN_SCORE=70') AND
                $contains(EMAIL, 'wmeyers@med.cornell.edu', 'MISSPELLINGS MIN_SCORE=80');

Additional Resources

See also:

 
Back to top
admin/indexing/powersearch/sql.1295846091.txt.gz · Last modified: 2016/06/28 22:38 (external edit)