69
Procedure
Creating the Database Schema and Tables
CREATE SCHEMA customers;
SET SCHEMA customers;
-- create sample table
CREATE COLUMN TABLE customer
(
id INTEGER PRIMARY KEY,
firstname SHORTTEXT(100) FUZZY SEARCH INDEX ON,
lastname SHORTTEXT(100) FUZZY SEARCH INDEX ON,
streetname NVARCHAR(100) FUZZY SEARCH INDEX ON,
housenumber NVARCHAR(20) FUZZY SEARCH MODE
'housenumber',
postcode NVARCHAR(20) FUZZY SEARCH INDEX ON FUZZY SEARCH MODE
'postcode',
cityname NVARCHAR(100) FUZZY SEARCH INDEX ON,
countrycode NVARCHAR(2),
phone NVARCHAR(20),
dateofbirth DATE
);
-- needed to model an attribute view on top of the table
GRANT SELECT ON customer TO modelowner;
-- needed to allow activation of attribute views that use this table
GRANT SELECT ON customer TO _sys_repo WITH GRANT OPTION;
-- for better performance, database indexes should be created
-- on all NVARCHAR columns that are used in the search rules
-- example:
CREATE INDEX customer_cityname ON customer(cityname);
-- insert a sample record:
INSERT INTO customer VALUES(1, 'Billy', 'Smith', 'Summerset Drv', '1001',
'123456789', 'Littleton', 'US', '555-1234', '1950-12-01');
-- to be able to use stopwords a stopword table is needed:
CREATE COLUMN TABLE stopwords
(
stopword_id VARCHAR(32) PRIMARY KEY,
list_id VARCHAR(32) NOT NULL,
language_code VARCHAR(2),
term NVARCHAR(200) NOT NULL
);
GRANT SELECT ON stopwords TO _sys_repo WITH GRANT OPTION;
INSERT INTO stopwords VALUES('1', 'firstname', '', 'Dr');
-- and for term mappings another table:
CREATE COLUMN TABLE termmappings
(
mapping_id VARCHAR(32) PRIMARY KEY,
list_id VARCHAR(32) NOT NULL,
language_code VARCHAR(2),
term_1 NVARCHAR(255) NOT NULL,
term_2 NVARCHAR(255) NOT NULL,
weight DECIMAL NOT NULL
);
GRANT SELECT ON termmappings TO _sys_repo WITH GRANT OPTION;
INSERT INTO termmappings VALUES('1', 'firstname', '', 'William', 'Will',
'1.0');
INSERT INTO termmappings VALUES('2', 'firstname', '', 'William', 'Bill',
'0.9');
INSERT INTO termmappings VALUES('3', 'firstname', '', 'William', 'Billy',
'0.9');
INSERT INTO termmappings VALUES('7', 'firstname', '', 'Will', 'William',
'1.0');
INSERT INTO termmappings VALUES('8', 'firstname', '', 'Will', 'Bill',
'0.9');
INSERT INTO termmappings VALUES('9', 'firstname', '', 'Will', 'Billy',
'0.9');
218
PUBLIC
© 2016 SAP SE or an SAP affiliate company. All rights reserved.
SAP HANA Search Developer Guide
Accessing Data Using Full-Text Search