background image
C H A P T E R 1 1
Data Storage and Retrieval
11-44
Using Newton Data Storage Objects
This query finds entries containing the words
"Bob"
,
"Bobby"
, and so forth, but
not words such as
"JoeBob"
. Text queries are not case sensitive--even though the
original query spec is all lower case, this query finds entries such as
"Bob"
or
"BOB"
.
Because the
words
slot contains an array, it can be used to search for multiple
string beginnings. For example, the following code fragment returns entries that
contain both of the string beginnings
"Bob"
and
"Apple"
. Thus, an entry
containing the strings
"Bobby"
and
"Applegate"
would be included in the
results of the search, but an entry missing either of the word beginnings
"Bob"
or
"Apple"
is not included.
// find entries holding "bob" and "apple" word beginnings
// won't find entries having only one of these beginnings
local myCurs := mySoup:Query({words: ["bob", "apple"]});
Because each element in the array is a string, each "word" to be matched can
actually contain multiple words and punctuation. For example, the following code
fragment returns entries that contain both of the string beginnings
"Bob"
and
"Apple Computer, Inc."
:
// find word beginnings "bob" and "Apple Computer, Inc."
local myCursor := mySoup:Query({words: ["bob",
"Apple Computer, Inc."]});
Note
The more unique the search string is, the more quickly a
words
search proceeds. Thus,
words
queries are slow for search words
that have only one or two characters in them.
To search for entire strings, rather than string beginnings, the query spec must
include an
entireWords
slot that holds the value
true
, as shown in the
following code fragment:
// return entries holding entire words "bob" and "Apple Computer"
local myCursor := mySoup:Query({words: ["bob", "Apple Computer"],
entireWords: true });
This query returns entries that contain both of the strings
"Bob"
and
"Apple
Computer"
. Because the
entireWords
slot holds the value
true
, this query
does not match strings such as
"Apple Computer, Inc."
or
"Bobby"
.
Entries containing only one of the specified words are not included in the results of
the search.
To conduct a text search that is not constrained by word boundaries, add to your
query spec a
text
slot containing a single string to be matched. For example, the
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна