这个练习会使用SAP HANA Express Edition的文本语义分析引擎对JSON格式的documents进行语义分析。 首先创建一个column table,对其index开启fuzzy text search(模糊搜索)功能。 上述描述的操作可以用下面的SQL语句来完成: create column table food_analysis( name nvarchar(64), description text FAST PREPROCESS ON FUZZY SEARCH INDEX ON); 其中description字段开启了模糊搜索功能。 将存储于名为doc_store的document store collection里的json key-value键值对拷贝到刚刚创建的数据库表里: insert into food_analysiswith doc_store as (select "name", "description" from food_collection)select doc_store."name" as name, doc_store."description" as descriptionfrom doc_store; 执行上述的sql语句,确保数据全部拷贝到数据库表food_analysis中: 使用下列的sql语句对description字段进行模糊搜索: select name, score() as similarity, TO_VARCHAR(description)from food_analysiswhere contains(description, "nuts", fuzzy(0.5,"textsearch=compare"))order by similarity desc 执行结果: HANA Express Edition里的linguistic 文本分析步骤也比较简单。 首先还是创建一个数据库表: create column table food_sentiment( name nvarchar(64) primary key, description nvarchar(2048)); 将document store里的json数据拷贝到数据库表里: insert into food_sentimentwith doc_store as (select "name", "description" from food_collection)select doc_store."name" as name, doc_store."description" as descriptionfrom doc_store; 针对description字段创建一个新的index: CREATE FULLTEXT INDEX FOOD_SENTIMENT_INDEX ON "FOOD_SENTIMENT" ("DESCRIPTION")CONFIGURATION "GRAMMATICAL_ROLE_ANALYSIS"LANGUAGE DETECTION ("EN")SEARCH ONLY OFFFAST PREPROCESS OFFTEXT MINING OFFTOKEN SEPARATORS ""TEXT ANALYSIS ON; 上述SQL语句会自动创建一个名为$TA_FOOD_SENTIMENT_INDEX的文本分析表: 该表里的内容: 由此可以发现,之前我们导入到数据库表里的英文句子,被HANA text engine拆解成单词,并且每个单词的词性也自动被HANA解析出来了。 要获取更多Jerry的原创文章,请关注公众号"汪子熙":