SQL Yoga version 1.1.0 build 4 :: Visit website

Printer friendly version

function sqlyoga_splitUserSearchString()

Parses a search string and converts it into an array of it's component parts.

function sqlyoga_splitUserSearchString pString, pDefaultOperator
Parameters
TypeNameDescription
Simple parameter. pString A string representing the terms a user wants to search for.
Simple parameter. pDefaultOperator Default boolean operator to use between words that do not explicity state one. Valid values are "AND" or "OR". Default value is "AND".
Description

Search interfaces often allow a user to enter a search string for querying the database. A string entered by the user as

tacos pizza

might look like this in a WHERE clause:
field = 'tacos' AND field='pizza'

or
field='tacos' OR field='pizza'

A search string such as
"cheese pizza" tacos

might look like this in a WHERE clause:
field = 'cheese pizza' OR field='tacos'


This function splits up the string into it's component parts and stores them in a numerically indexed array. This array can be used to generate conditions for a SQL Query object. For example, it can be passed as a parameter to sqlquery_addScope.
The string
"cheese pizza" tacos

would be parsed and converted to an array that looks like this (assuming OR was the default operator):
[1]["string"] = cheese pizza 
[1]["operator"] = OR
[2]["string"] = tacos
[2]["operator"] = OR

Return

Numerically indexed array. Each index has two keys: operator and string.

See also