28.01.2013 Views

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

WHERE CONTAINS(postcode, '1234', FUZZY(0.5, 'spellCheckFactor=1.0'))<br />

ORDER BY SCORE() DESC;<br />

Fuzzy Search on Text Columns<br />

Text types support a more sophisticated kind of fuzzy search. Texts are tokenized (split into terms) and the fuzzy<br />

comparison is done term by term. For example, when searching with '<strong>SAP</strong>', a record such as '<strong>SAP</strong> Deutschland AG<br />

& Co. KG' gets a high score, because the term '<strong>SAP</strong>' exists in both texts. A record such as '<strong>SAP</strong>PHIRE NOW<br />

Orlando' gets a lower score, because '<strong>SAP</strong>' is only a part of the longer term '<strong>SAP</strong>PHIRE' (3 of 8 characters match).<br />

Fuzzy search on text columns replaces non-fault-tolerant statements such as<br />

SELECT ... FROM documents WHERE doc_content LIKE '% Driethanolamyn %' ...<br />

The following SQL data types are supported:<br />

● TEXT<br />

● SHORTTEXT<br />

● fulltext index<br />

A fulltext index is an additional index structure that can be defined for non-text columns to add text search<br />

features. Supported column types are, for example, NCLOB and NVARCHAR.<br />

It is possible to speed up the fuzzy search by creating data structures called 'fuzzy search indexes', which are<br />

used for a faster calculation of the fuzzy score. These indexes exist in the memory only, so no additional disk<br />

space is needed.<br />

To get the best response times possible, you should enable the fuzzy search indexes for all database columns that<br />

have a high load of fuzzy searches and for all database columns that are used in performance-critical queries.<br />

Fuzzy Search on SQL Type TEXT<br />

A call to contains that references a TEXT column is automatically processed as a text search. In this case, the<br />

mode textsearch=compare and all fuzzy search options are allowed:<br />

CREATE COLUMN TABLE mytable<br />

(<br />

col1 TEXT<br />

);<br />

SELECT score() AS score, * FROM mytable WHERE contains(col1, 'a b',<br />

fuzzy(0.8, 'textsearch=compare'));<br />

Fuzzy Search on SQL Type SHORTTEXT<br />

When a SHORTTEXT column is created, a column of column store type cs_string and a second hidden text<br />

column are created. A call to contains that references the SHORTTEXT column is automatically redirected by the<br />

<strong>SAP</strong> <strong>HANA</strong> <strong>Developer</strong> <strong>Guide</strong><br />

Enabling Search<br />

P U B L I C<br />

© 2012 <strong>SAP</strong> AG. All rights reserved. 281

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!