Parameters Optional

The SQL Query Clause has the additional feature that parameters are optional: if a given $qp... parameter is not provided a value at search time, or is given an empty value, then that part of the SQL clause is automatically dropped. This allows the SQL Query Clause to be made as complex as needed for the most-specific possible query, yet automatically "fall back" to a simpler version (or none at all) if certain parts are not needed.

For example, a profile with the fields Color, Price and Quantity might have its SQL Query Clause set to:

Color = $qpDesiredColor and Price <= $qpMaxPrice and
  (Quantity >= $qpMin and Quantity <= $qpMax)

This will search all three fields, if all of the $qp... parameters are provided. However, if say only qpMaxPrice and qpMin were provided non-empty values at search time, the equivalent search clause actually used would effectively be just:

Price <= $qpMaxPrice and (Quantity >= $qpMin)

This feature allows tremendous flexibility in users' searches. One search form can now handle a full spectrum of queries - from simple text searches to complex drill-down queries with many parameters - without reconfiguration by the admin or "knob-turning" by the search user. The profile will simply search for the fields filled in, no more no less.

Note also that infield: or SQL Query Clause clauses that are invalid - e.g. due to permissions, syntax errors, nonexistent fields etc. - will generally be dropped if possible (with an error message), while other (valid) clauses will still be handled. This graceful degradation is not always possible however, and may also result in further cascading errors and/or incorrect/unexpected results.


Copyright © Thunderstone Software     Last updated: Oct 10 2023
Copyright © 2024 Thunderstone Software LLC. All rights reserved.