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.

2. Perform the search on two columns.<br />

SELECT SCORE() AS score, * FROM companies2<br />

WHERE CONTAINS(companyname, 'IBM',<br />

FUZZY(0.7,'textSearch=compare,bestMatchingTokenWeight=0.7'))<br />

AND CONTAINS(contact, 'Master',<br />

FUZZY(0.7,'textSearch=compare,bestMatchingTokenWeight=0.7'))<br />

ORDER BY score DESC;<br />

SCORE ID COMPANYNAME CONTACT<br />

0.91 6 IBM Corp M. Master<br />

3. Perform a freestyle search.<br />

SELECT SCORE() AS score, * FROM companies2<br />

WHERE CONTAINS((companyname,contact), 'IBM Master', FUZZY(0.7))<br />

ORDER BY score DESC;<br />

SCORE ID COMPANYNAME CONTACT<br />

0.8 6 IBM Corp M. Master<br />

Note: <strong>Free</strong>style search always uses TF/IDF to calculate the score and does not support parameters<br />

such as 'textSearch=compare' or 'bestMatchingTokenWeight=0.7' that influence score calculation.<br />

Therefore, we get a different score for the same record.<br />

Fuzzy Search on String Columns<br />

String types support a basic fuzzy string search. The values of a column are compared with the user input using<br />

the fault-tolerant fuzzy string comparison.<br />

When working with string types, the fuzzy string compare always compares the full strings. When, for example,<br />

searching with '<strong>SAP</strong>', a record such as '<strong>SAP</strong> Deutschland AG & Co. KG' gets a very low score, because only a very<br />

small part of the string is equal (3 of 27 characters match).<br />

A fuzzy search on string types is a replacement for a non-fault-tolerant SQL statement such as<br />

SELECT ... FROM products WHERE product_name = 'coffe krisp biscuit' ...<br />

that would not return any results because of the spelling errors.<br />

Supported SQL data types are VARCHAR and NVARCHAR.<br />

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

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

disk 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 />

<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. 271

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

Saved successfully!

Ooh no, something went wrong!