码迷,mamicode.com
首页 > 其他好文 > 详细

hybris-FlexibleSearch

时间:2015-06-28 23:09:25      阅读:678      评论:0      收藏:0      [点我收藏+]

标签:

基础知识

    FlexibleSearch内置采用hybris Commerce Suite的一个强大的检索语言采用hybris商务套件使用基于SQL语法搜索类型和物品

    一个FlexibleSearch语句的执行发生在两个阶段

        pre-parsing(解析)到一个SQL-compliant语句中和运行这个语句在数据库上

        在预解析阶段,FlexibleSearch框架解析FlexibleSearch语法到SQL-compliant里。下面的两个代码段表现出一个FlexibleSearch查询和这个FlexibleSearch语句查询的结果,这是在数据库上执行的语句:

FlexibleSearch查询语句:    

elect {pk}, {code}, {name[de]} from {Product}
在数据库上执行的SQL语句:
SELECT  item_t0.PK , item_t0.Code , lp_t0.p_name
	FROM products item_t0 JOIN productslp lp_t0 ON item_t0.PK = lp_t0.ITEMPK AND lp_t0.LANGPK= 9013632135395968
	WHERE (item_t0.TypePkString IN  ( 23087380955301264 , 23087380955663520 , 23087380955662768 , 23087380955661760 ,
	23087385363574432 , 23087380955568768 , 23087380955206016 ) )

FlexibleSearch采用hybris Commerce Suite的类型系统从实际的数据库表这样你就可以在类型相同级别运行查询。不同于常规的SQL语句,在一个FlexibleSearch查询中您不必指定明确的数据库表名。FlexibleSearch框架解析类型和数据库表自动依赖关系并指定必要UNIONSJOINS在哪里。类型系统和数据库表示之间整个转换过程是自动进行的要访问一个类型FlexibleSearch查询,请用花括号{and}类型代码


SELECT * FROM {Product}

采用hybris Commerce Suite的某一用户帐户的上下文中执行FlexibleSearch查询使用一个会话因为不同的用户帐户访问采用hybris商务套件的不同项目,搜索结果的数量取决于用户的帐户。搜索结果的数目被按类型的访问权限定义这些仅影响采用hybris管理控制台的搜索结果)限制,目录版本和类别

更多的特权用户帐户更多的搜索结果FlexibleSearch产量用户帐户的上下文中默认情况下分配给会话的用户帐户是匿名的所以任何FlexibleSearch查询返回搜索结果相匹配的默认匿名帐户

匿名不同用户帐户的情况下运行FlexibleSearch查询该会话需要被分配给不同的用户帐户,如:

import de.hybris.platform.servicelayer.user.UserService;
...
// Injected by Spring
userService.setCurrentUser(userService.getUserForUID("myUserAccount"));
...

语法概要

FlexibleSearch查询的基本语法如下:


SELECT <selects> FROM <types> ( WHERE <conditions> )? ( ORDER BY <order> )?
一个FlexibleSearch查询包括:


    强制性的<selects>参数对SELECT子句

    强制性的<type>参数为对FROM子句

    强制性的一个可选的<conditions>字段WHERE子句。

    一个可选的ORDER BY子句。

    

SQL Command / Keyword Description / Comment Code Example
ORDER BY {alias:attribute} Display results ordered by the value of attribute. SELECT ... FROM ... ORDER BY...
ASC 排序结果以升序 (a...z, 0...9). SELECT ... FROM ... ORDER BY ... ASC
DESC 排序结果以降序(z...a, 9...0). SELECT ... FROM ... ORDER BY ... DESC
DISTINCT Eliminates double entries in the query result. SELECT DISTINCT ... FROM ...
OR Performs a logical OR compare between two queries. ... WHERE ... OR ...
AND Performs a logical AND compare between two queries. ... WHERE ... AND ...
IS [NOT] NULL Returns the results that are [not] null ... WHERE ... IS [NOT] NULL
[NOT] IN Returns the results that are [not] part of the following statement ... WHERE ... [NOT] IN ...  
[NOT] EXISTS Returns the results that are [not] matching a given subquery. ...WHERE ... EXISTS ( {{ SELECT ... }} )
LIKE Compares to a pattern. ... WHERE ... LIKE ‘...‘
% Wildcard matching any number of characters. ... WHERE ... LIKE ‘%...‘||‘...%...‘||‘...%‘
_ Wildcard matching a single character. ... WHERE ... LIKE ‘...‘ || ‘......‘ ||‘..._‘
LEFT JOIN ON Merges two tables into one. ... LEFT JOIN ... ON ... = ...
= True if results are equal.  
!=, <> True if results are not equal.  
< True if result 1 is less than result 2.  
<= True if result 1 is equal to or less than result 2.  
> True if result 1 is greater than result 2.  
>= True if result 1 is equal to or greater than result 2.  
CONCAT 连接两个结果 - 在右边侧的例子将返回字符串结果。 CONCAT ( ‘resul‘, ‘t‘ )
:o 外连接参数用于包括与在ProductsLP表(=. 表包含本地化产品)以及缺少行匹配结果否则,例如查询将只返回产品 与ProductsLP表中现有行,因为它只会使用JOIN。 SELECT {p:PK}
   FROM {Product AS p}
   WHERE {p:description[en]:o} LIKE ‘%text%‘
   OR {p:description[de]:o} LIKE ‘%text%‘


<selects>


<selects>字段中的指定要返回的数据库列星号*将返回所有数据库SQL约定。要搜索一个属性指定大括号属性标识符SELECT{code}FROM {Product}

要获取本地化的属性使用的语言标识符作为后缀属性名包含在方括号[and]如:

SELECT * FROM {Category}
这个查询返回每个数据库列的Category表。


SELECT {pk},{code},{name[de]} FROM {Product}

产品查询返回数据库pk,code,name[de].



<type>

数值<type>在FROM子句中字段中指定采用hybris Commerce Suite的类型嵌套在大括号{and}这是要搜索例如

SELECT * FROM {Product}
SELECT * FROM {Category JOIN Catalog}

你可以指定一个别名用于区分属性字段使用AS运算符:


SELECT {p.code} FROM {Product AS p} ORDER BY {p.code}
也可以运行JOIN和LEFT JOIN的查询,如


SELECT {cj.code}
    FROM {SyncItemCronJob AS sicj
         JOIN SyncItemJob AS sij
           ON {sicj:job} = {sij:pk}
     }

SELECT {p1.PK},{p2.PK}
    FROM {Product AS p1
         LEFT JOIN Product AS p2
            ON {p1.code} = {p2.code}
     }
WHERE {p1.PK} <> {p2.PK}
    ORDER BY {p1.code} ASC

一定要记住,这是最重要的,整个<type>块必须由封闭{和}不管多种类型.不要试图在多个<type>在FROM子句中尽管这看起来是工作它可能会导致不可预知的错误


子类型

默认情况下指定类型搜索导致FlexibleSearch查询来搜索该类型任何子类型。例如下面的代码片段返回代码和产品与VariantProduct的所有实例的PK


SELECT {code},{pk} FROM {Product}















hybris-FlexibleSearch

标签:

原文地址:http://my.oschina.net/penfin/blog/471741

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!