This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
admin:indexing:autocomplete:sql [2011/01/24 21:57] els |
admin:indexing:autocomplete:sql [2016/06/28 22:38] (current) |
||
---|---|---|---|
Line 23: | Line 23: | ||
=== Initializing the Pull-Down Box === | === Initializing the Pull-Down Box === | ||
- | The following SQL statement provides the results shown in the previous example: | + | The following SQL statement provides the results shown in the previous example. Depending on the size of the database, it may be important to not issue a SQL statement until the user has typed two or three letters. That can dramatically affect the number of rows retrieved, and also the time required to query the Omnidex indexes. |
- | <code sql> | + | <code> |
select FNAME, count(*) | select FNAME, count(*) | ||
from LIST | from LIST | ||
Line 31: | Line 31: | ||
group by FNAME | group by FNAME | ||
order by 2 desc | order by 2 desc | ||
- | with optimization=distinct_key | + | with optimization=distinct_key; |
</code> | </code> | ||
This SQL statement will provide results that can then be placed into drop-down boxes as needed: | This SQL statement will provide results that can then be placed into drop-down boxes as needed: | ||
- | ^ First Name ^ Count ^ | + | <code> |
- | | WILLIAM | 118130 | | + | FNAME COUNT('*') |
- | | WILLIE | 19307 | | + | ------------------------------------ |
- | | WILMA | 5075 | | + | WILLIAM 118130 |
- | | WILLARD | 2350 | | + | WILLIE 19307 |
- | | WILLIS | 1661 | | + | WILMA 5075 |
- | | WILBUR | 1660 | | + | WILLARD 2350 |
- | | WILBERT | 1357 | | + | WILLIS 1661 |
- | | WILSON | 1351 | | + | WILBUR 1660 |
- | | WILFRED | 1141 | | + | WILBERT 1357 |
- | | WILL | 826 | | + | WILSON 1351 |
- | | WILLA | 800 | | + | WILFRED 1141 |
- | | WILFREDO | 698 | | + | WILL 826 |
- | | WILLIAMS | 626 | | + | WILLA 800 |
- | | WILEY | 536 | | + | WILFREDO 698 |
- | | WILDA | 457 | | + | WILLIAMS 626 |
- | | WILFORD | 428 | | + | WILEY 536 |
- | | WILMER | 367 | | + | WILDA 457 |
- | | WILHELMINA | 348 | | + | WILFORD 428 |
- | | WILBURN | 345 | | + | WILMER 367 |
- | | WILTON | 280 | | + | WILHELMINA 348 |
- | | WILLY | 216 | | + | WILBURN 345 |
- | | WILBER | 175 | | + | WILTON 280 |
- | | WILLENE | 163 | | + | WILLY 216 |
- | | WILLIAN | 155 | | + | WILBER 175 |
- | | WILLIA | 113 | | + | WILLENE 163 |
- | | WILLETTE | 104 | | + | WILLIAN 155 |
- | | WILLIEMAE | 59 | | + | WILLIA 113 |
- | | WILLODEAN | 48 | | + | WILLETTE 104 |
- | | WILLENA | 47 | | + | WILLIEMAE 59 |
- | | WILHEMINA | 43 | | + | WILLODEAN 48 |
- | | WILLOW | 39 | | + | WILLENA 47 |
- | | WILLETTA | 35 | | + | WILHEMINA 43 |
+ | WILLOW 39 | ||
+ | WILLETTA 35 | ||
+ | 32 rows returned | ||
+ | </code> | ||
+ | |||
=== Refining the Pull-Down Box === | === Refining the Pull-Down Box === | ||
Line 76: | Line 82: | ||
It is also possible to resubmit the query to the database with an additional letter added to the criteria, though care should be given to insure that performance does not degrade with this approach. | It is also possible to resubmit the query to the database with an additional letter added to the criteria, though care should be given to insure that performance does not degrade with this approach. | ||
+ | === Subsequent Searches === | ||
+ | |||
+ | As the user provides criteria to various fields, that criteria can also be included in the AutoComplete query. For example, the same statement above can be performed with criteria against the State and Last Name columns as shown below: | ||
+ | |||
+ | <code> | ||
+ | select FNAME, count(*) | ||
+ | from LIST | ||
+ | where STATE = 'NY' and | ||
+ | LNAME = 'Myers' and | ||
+ | FNAME='Wil*' | ||
+ | group by FNAME | ||
+ | order by 2 desc | ||
+ | with optimization=distinct_key; | ||
+ | </code> | ||
+ | |||
+ | The AutoComplete choices and their counts will be correspondingly reduced to those in the State of New York with a Last Name of Myers: | ||
+ | |||
+ | <code> | ||
+ | FNAME COUNT('*') | ||
+ | ------------------------ ---------- | ||
+ | WILLIAM 6 | ||
+ | WILDA 1 | ||
+ | WILLARD 1 | ||
+ | WILLIE 1 | ||
+ | WILMA 1 | ||
+ | WILMER 1 | ||
+ | 6 rows returned | ||
+ | </code> | ||
===== ===== | ===== ===== |