2025-04-17 - LinkPath structure and examples: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 160: | Line 160: | ||
//... | //... | ||
] | ] | ||
</syntaxhighlight> | |||
== ProcessSearchResultMessage == | |||
* Fetch and Sort Product Sizes by Language with Fallback | |||
<syntaxhighlight lang="js"> | |||
Need to fetch all sizes, sorted by language order 'en', 'th'. | |||
If a translation is missing for any language in sortArray: ['en', 'th'], | |||
fallback to the defaultTranslationLink of that productAttribute. | |||
ProductAttributeLabel with labelId = 'Id_X' represents a size. | |||
identifiersIdArray contains all productAttributeIds linked to ProductAttributeLabel where labelId='Id_X'. | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="js"> | |||
let processSearchResultMessage = { | |||
objType: { | |||
serviceTag: 'ProductAttribute', | |||
objectType: 'productAttribute' | |||
}, | |||
requiredData: [ | |||
{ | |||
fieldName: 'text', //all sizes by languageId, where text is the identifiers of the translation objectType, which is the final link step of this requiredData | |||
linkPath: [ | |||
{ | |||
link: { | |||
relType: { | |||
serviceTag: 'Translations', | |||
relationshipTag: 'hasTranslationLink' | |||
// Must use hasTranslationLink because it will be automatically added by inserting a filterElement with logicalType: "translateIds" | |||
// where identifiers come from identifiersIdArray (Process-ComplexFilter), along with a filterElement of type: "logicalOperator" and operator: "and" | |||
}, | |||
objType: { | |||
serviceTag: 'Translations', | |||
objectType: 'translationLink' | |||
}, | |||
direction: 'from' | |||
}, | |||
aggregate: 'min', //if 'min' sorts languages in order 'en', 'th', //if max sorts languages in order 'th', 'en | |||
sortFields: { | |||
fieldName: 'languageId', | |||
dataType: 'array', | |||
sortArray: ['en', 'th'] // sorts languages according to sortArray | |||
}, | |||
filterElements: [ | |||
{ | |||
type: 'group', | |||
elements: [ | |||
{ | |||
type: 'traversal', | |||
traversals: [ | |||
{ | |||
fields: { | |||
languageId: { anyValue: ['en', 'th'] }, | |||
textTag: 'productAttributeValue' | |||
}, | |||
link: { | |||
relationshipDirection: 'from', | |||
relType: { | |||
serviceTag: 'Translations', | |||
relationshipTag: 'currentTranslationLink' | |||
} | |||
} | |||
}, | |||
{ | |||
objType: { | |||
serviceTag: 'ProductAttribute', | |||
objectType: 'productAttribute' | |||
} | |||
} | |||
] | |||
}, | |||
{ | |||
type: 'logicalOperator', operator: 'or' | |||
}, | |||
{ | |||
type: 'traversal', | |||
traversals: [ | |||
{ | |||
fields: { | |||
textTag: 'productAttributeValue' | |||
}, | |||
link: { | |||
relationshipDirection: 'from', | |||
relType: { | |||
serviceTag: 'Translations', | |||
relationshipTag: 'defaultTranslationLink' | |||
} | |||
} | |||
}, | |||
{ | |||
objType: { | |||
serviceTag: 'ProductAttribute', | |||
objectType: 'productAttribute' | |||
} | |||
} | |||
] | |||
} | |||
] | |||
} | |||
] | |||
}, | |||
{ | |||
link: { | |||
relType: { | |||
serviceTag: 'Translations', | |||
relationshipTag: 'isTranslation' | |||
}, | |||
objType: { | |||
serviceTag: 'Translations', | |||
objectType: 'translation' | |||
}, | |||
direction: 'from' | |||
} | |||
} | |||
] | |||
} | |||
], | |||
filter: { | |||
objType: { | |||
serviceTag: 'ProductAttribute', | |||
objectType: 'productAttribute' | |||
}, | |||
elements: [ | |||
{ | |||
type: 'complexFilter', | |||
complexFilter: { | |||
objType: { | |||
serviceTag: 'ProductAttribute', | |||
objectType: 'ProductAttributeLabel' | |||
}, | |||
relType: { | |||
serviceTag: 'ProductAttribute', | |||
relationshipTag: 'isProductAttributeLabel' | |||
}, | |||
direction: 'from', | |||
elements: [ | |||
{ | |||
type: 'logical', | |||
fieldName: 'labelId', | |||
comparison: 'equals', | |||
value: 'Id_X' | |||
} | |||
] | |||
} | |||
} | |||
] | |||
}, | |||
requestProperties: {}, | |||
identifiersIdArray: [ | |||
{ | |||
identifiersId: 'hashOfIdentifiersObject_1', | |||
identifiers: { | |||
productAttributeId: 'productAttributeId_uuid_1' | |||
} | |||
}, | |||
{ | |||
identifiersId: 'hashOfIdentifiersObject_2', | |||
identifiers: { | |||
productAttributeId: 'productAttributeId_uuid_2' | |||
} | |||
}, | |||
{ | |||
identifiersId: 'hashOfIdentifiersObject_3', | |||
identifiers: { | |||
productAttributeId: 'productAttributeId_uuid_3' | |||
} | |||
} | |||
] | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 08:10, 27 October 2025
reqiuredData structure
- requiredData as array that have multiple feildName to findData
[
{
fieldName: "fieldname if main objType or last fieldName for linkPath",
combinationComplexFilter: {
[combinationA]: {
//* complexFilter as normalize structure
}
},
linkPath: [
{
link: {
objType: {
serviceTag: "ServciceTag",
objectType: "linkObjectType1"
},
relType: {
serviceTag: "ServiceTag",
objectType: "hasLinkObjectType1"
},
direction: "to" | "from",
requestProperties: {
orderQuantity: 2,
//...
}
},
//== condition ==
filterElements: [],
aggregate: "max" | "min" | "average",
sortFields: {
fieldName: "fieldname if main objType or last fieldName for linkPath",
dataType: "string" | "number" | "array"
},
combine: true | false,
perParentComplexFilters: {
[combinationTagB]: {
//* complexFilter as normalize structure
}
},
applyCombinations: [
//* tag only in combinationComplexFilters
"combinationTagA"
],
comparison: "lessThan" | "gearterThan" | "lessThanEquals" | "greaterThanEquals" | "high" | "low" | "highLow",
comparisonValue: "value",
comparisonSortField: "fieldName"
},
//...
]
}
]
example
[
{
fieldName: "price",
combinationComplexFilters: {
locationNode: {
//* complexFilter as normalize structure
}
},
linkPath: [
{
link: {
objType: {
serviceTag: "SellOfferManager",
objectType: "sellOffer"
},
relType: {
serviceTag: "SellOfferManager",
objectType: "sellOffer"
},
direction: "from",
requestProperties: {
orderQuantity: 2,
//...
}
},
filterElements: [ //* must change to normalize structure
{
type: "logical", //example
fieldName: "price",
comparison: "greaterThan",
value: 50
},
{
type: "complexFilter",
complexFilter: {
objType: {
serviceTag: "SellOfferManager",
objectType: "sellOffer"
}
//...
//.. maybe ref. from main filter
}
},
//...
]
},
{
link: {
objType: {
serviceTag: "SellOfferManager",
objectType: "sellOffer"
},
relType: {
serviceTag: "SellOfferManager",
objectType: "hasOrderPrice"
},
direction: "from",
requestProperties: {
orderQuantity: 2,
deliveryMethodIds: [
"deliveryMethodId_chiangMai"
]
//...
}
},
//== condition ==
//filterElements
aggregate: "max",
sortFields: {
fieldName: "price",
dataType: "number"
},
combine: true,
perParentComplexFilters: {
sellOfferPlan: {
//* complexFilter as normalize structure
},
sellOfferPlanDeliveryMethodLink: {
//* complexFilter as normalize structure
},
sellOfferPlanUserPaymentMethodLink: {
//* complexFilter as normalize structure
}
},
applyCombinations: [
//* tag only in combinationComplexFilters
"locationNode"
],
// comparison: "greaterThan",
// comparisonValue: "50",
// comparisonSortField: "upToValue"
},
//...
]
},
//...
]
ProcessSearchResultMessage
- Fetch and Sort Product Sizes by Language with Fallback
Need to fetch all sizes, sorted by language order 'en', 'th'.
If a translation is missing for any language in sortArray: ['en', 'th'],
fallback to the defaultTranslationLink of that productAttribute.
ProductAttributeLabel with labelId = 'Id_X' represents a size.
identifiersIdArray contains all productAttributeIds linked to ProductAttributeLabel where labelId='Id_X'.
let processSearchResultMessage = {
objType: {
serviceTag: 'ProductAttribute',
objectType: 'productAttribute'
},
requiredData: [
{
fieldName: 'text', //all sizes by languageId, where text is the identifiers of the translation objectType, which is the final link step of this requiredData
linkPath: [
{
link: {
relType: {
serviceTag: 'Translations',
relationshipTag: 'hasTranslationLink'
// Must use hasTranslationLink because it will be automatically added by inserting a filterElement with logicalType: "translateIds"
// where identifiers come from identifiersIdArray (Process-ComplexFilter), along with a filterElement of type: "logicalOperator" and operator: "and"
},
objType: {
serviceTag: 'Translations',
objectType: 'translationLink'
},
direction: 'from'
},
aggregate: 'min', //if 'min' sorts languages in order 'en', 'th', //if max sorts languages in order 'th', 'en
sortFields: {
fieldName: 'languageId',
dataType: 'array',
sortArray: ['en', 'th'] // sorts languages according to sortArray
},
filterElements: [
{
type: 'group',
elements: [
{
type: 'traversal',
traversals: [
{
fields: {
languageId: { anyValue: ['en', 'th'] },
textTag: 'productAttributeValue'
},
link: {
relationshipDirection: 'from',
relType: {
serviceTag: 'Translations',
relationshipTag: 'currentTranslationLink'
}
}
},
{
objType: {
serviceTag: 'ProductAttribute',
objectType: 'productAttribute'
}
}
]
},
{
type: 'logicalOperator', operator: 'or'
},
{
type: 'traversal',
traversals: [
{
fields: {
textTag: 'productAttributeValue'
},
link: {
relationshipDirection: 'from',
relType: {
serviceTag: 'Translations',
relationshipTag: 'defaultTranslationLink'
}
}
},
{
objType: {
serviceTag: 'ProductAttribute',
objectType: 'productAttribute'
}
}
]
}
]
}
]
},
{
link: {
relType: {
serviceTag: 'Translations',
relationshipTag: 'isTranslation'
},
objType: {
serviceTag: 'Translations',
objectType: 'translation'
},
direction: 'from'
}
}
]
}
],
filter: {
objType: {
serviceTag: 'ProductAttribute',
objectType: 'productAttribute'
},
elements: [
{
type: 'complexFilter',
complexFilter: {
objType: {
serviceTag: 'ProductAttribute',
objectType: 'ProductAttributeLabel'
},
relType: {
serviceTag: 'ProductAttribute',
relationshipTag: 'isProductAttributeLabel'
},
direction: 'from',
elements: [
{
type: 'logical',
fieldName: 'labelId',
comparison: 'equals',
value: 'Id_X'
}
]
}
}
]
},
requestProperties: {},
identifiersIdArray: [
{
identifiersId: 'hashOfIdentifiersObject_1',
identifiers: {
productAttributeId: 'productAttributeId_uuid_1'
}
},
{
identifiersId: 'hashOfIdentifiersObject_2',
identifiers: {
productAttributeId: 'productAttributeId_uuid_2'
}
},
{
identifiersId: 'hashOfIdentifiersObject_3',
identifiers: {
productAttributeId: 'productAttributeId_uuid_3'
}
}
]
}