Download Pro Full-Text Search in SQL Server 2008

Transcript
CHAPTER 8 ■ THESAURUSES
Replacement Sets
Replacement sets provide an alternative to expansion sets. Like expansion sets, replacement
sets are defined using XML in the thesaurus files. Replacement sets also have the same
512-character limitation on terms. You can define replacement sets with <pat> and <sub> tags
contained within a <replacement> tag. Though they’re defined in the same thesaurus files,
replacement sets behave differently from expansion sets. While expansion sets automatically
expand your search to include every search term in the set, replacement sets simply replace
your search term with another search term per your definition. Where expansion sets are
commonly used to define synonyms for words, replacement sets are useful for redefining
acronyms and abbreviations in your searches. Replacement sets operate on search terms in the
manner shown in Figure 8-4.
Full-Text Index
Replacement Set
Search Term
fl
Replacement
Patterns
fl
fla
flor
Sub Term
florida
Lorem
m ipsum
ips
psum
um dolor
dol
o or
or sit
s amet,
consectetur
ect
cteet
etur ad
aadipisicing
dipi
pissic
s
elit, sed
iuus
usm
smod te
ttempor
empo
por
o incididunt
i
do eiusmod
ut
ree et
et dolore
dol
do
oloore
re magna
mag aliqua. Ut
labore
m ad
ad mi
m
inni
nim
m ve
vveniam,
enia quis
en
enim
minim
ruud ex
eexercitation
xer
xe
ercitta
tat
atiioon
o ullamco
nostrud
riiss nisi
nisi ut
ut aaliquip
liquip
u ex ea
laboris
mod
mo
odo co
cconsequat.
ons
on
nse
seq
equat
u Duis aute
commodo
dol
oloor
or in
in reprehenderit
repr
preehe
e
irure dolor
in
Figure 8-4. Logical view of replacement set operation
In Listing 8-1, we created the replacement set shown in Figure 8-4, replacing various
search term abbreviations for Florida with the word florida, as shown:
<replacement>
<pat>fl</pat>
<pat>fla</pat>
<pat>flor</pat>
<sub>florida</sub>
</replacement>
With this replacement set, performing a search for any of the defined abbreviations results
in a search for the word florida. Note that the original search term is completely replaced in the
search, so that the original search term is not included in the final search. Listing 8-9 shows a
simple CONTAINS query with thesaurus replacement.
Listing 8-9. CONTAINS Query with Thesaurus Replacement
SELECT Book_ID
FROM dbo.Book
WHERE CONTAINS
(
Book_Content,
N'FORMSOF(THESAURUS, fl)'
);
www.it-ebooks.info
175