sap-commerce-cloudflexible-search

Flexible Search for fetching Email


I am very new to SAP Commerce and have been experimenting with Flexible search. Some queries work i.e and some dont.

Below one works fine.

1) Select * {User} SELECT {user.pk} FROM {User AS user} 
2) SELECT {user.pk}, {ItemType} FROM {User AS user} 

However when I am fetching email or uui, it is just not working.

1) SELECT {email} FROM {User AS user} 
2) SELECT {originaluid} FROM {User AS user} 

I have tried with {p_ as well which didn't work either.

1) SELECT {email} FROM {User AS user} 
2) SELECT {p_originaluid} FROM {User AS user} 

It's giving the same error for all the nonworking(wihth the different column names i.e p_originaluid) ones Exception message:

cannot search unknown field 'TableField(name='p_email',langPK='null',type=User)' within type User unless you disable checking, infoMap=TypeInfoMap for type = 8796093939794 code = User superType = 8796093841490 itemTable = users UPTable = usersup LTableName = userslp PropsTable = userprops core fields = owner = [owner,OwnerPkString,class de.hybris.platform.util.ItemPropertyValue] modifiedtime = [modifiedtime,modifiedTS,class java.util.Date] itemtype = [itemtype,TypePkString,class de.hybris.platform.util.ItemPropertyValue] creationtime = [creationtime,createdTS,class java.util.Date] pk = [pk,PK,class de.hybris.platform.core.PK] unlocalized fields = consentreference = [consentReference,p_consentreference, class java.lang.String] description = [description,p_description, class java.lang.String]

A bit of help will be great on the below questions:

1) Considering the above scenario why am I able to fetch all the columns? 
2) While doing a flexible search I found "SELECT TypePkString FROM {User AS user}" query, my question is since TypePkString is a database column why is it used with SELECT without curly braces?

Solution

  • To answer your 1st question:

    The way the type system works in SAP Commerce is. You have base item type and then you have drived item types. If you check core-items.xml Every type is derived from the generic item type directly or indirectly.

    When you have any sub-item type derived from a parent type I.e Employee or B2BCustomer and you do not define a separate table ( tag ) for these separate types, the SAP Commerce uses a base table and add additional columns specific to those (Employee or B2BCustomer SAP) sub-item type.

    This is why you may see many columns even for the specific type I.e B2BCustomer.

    The best way to find the attributes added to specific subtypes is by looking into the back office type system.

    In your case if you look into the type system by going into https://localhost:9002/backoffice/ -> Types -> User -> XML Representation and search for email, you may not find there

    Now use the above steps and search for email under Type B2B Customer. You should be able to find it under the XML but when you look for email under core-items.xml file you might not find it there, that's because in the back office type system (for B2BCustomer) you will see it extended from (Extended tab) b2bcommerce. Now look for b2bcommerce-items.xml you should definitely see the item type for B2BCustomer and it should also have an attribute called email.

    The reason for telling you above is so that you could know how and where to look.

    When you use {} in your flexible search it uses the type system to look up and because of the same reason its unable to look it up email in User type is a part of B2BCustomer, not User, in your case:

    select {email} from {B2BCustomer} should work.
    

    For 2nd question: As said before, Whenever you write {} in the flexible search, SAP Commerce looks into the type system and tries to resolve it however when you do not put curry braces it looked up DB columns for the given table like the below queries.

    select p_email from {User}
    select p_originaluid FROM {User}
    

    Though p_email is not a part of User as told before you can still query it if you just try to fetch from the column directly same applies to the second query.

    Hope this answers your question.