INDEXATION FOR NEWBIES
What is the indexation ?
...
Country A
...
Country B
...
Country Z
...
Index1_A
Index7_Z
{
"Id":"1287499",
"is_b2c":"1",
"is_b2b":"1",
"product_status":"2",
"material_status":"0",
"delivery_sla":"B",
"color_label":"GREEN",
"design_key":"1287499",
"design_label":"WELDINGROD GREEN",
"categories":"AINR10645,own_emea_RA",
"color_code":"0499",
"color_family":"G",
"diameter":"4 mm",
"family":"var_ACCESSORIES",
"length":"50000 mm",
"order_online":"0",
"packing_unit":"UN",
"pattern":"UNICOLOR",
"surface_per_box":"50 m²",
"total_thickness":"4 mm",
"variation_name":"WELDINGROD GREEN",
"product_type":"WELDING",
"accessory_type":"WEL02"
},
{"Id":"1287500","is_b2c":"1","is_b2b":"1","product_status":"2","material_status":"0","categories":"AINR10645,own_emea_RA","color_code":"0500","color_family":"U","color_label":"BLUE","design_key":"1287500","design_label":"WELDINGROD BLUE","diameter":"4 mm","family":"var_ACCESSORIES","length":"50000 mm","delivery_sla":"C","order_online":"0","packing_unit":"UN","pattern":"UNICOLOR","total_thickness":"4 mm","variation_name":"WELDINGROD BLUE","product_type":"WELDING","accessory_type":"WEL02"},{"Id":"1287501","is_b2c":"1","is_b2b":"1","product_status":"2","material_status":"0","categories":"AINR10645,own_emea_RA","color_code":"0501","color_family":"CG","color_label":"G","design_key":"1287501","design_label":"WELDINGROD MEDIUMGREY","diameter":"4 mm","family":"var_ACCESSORIES","length":"50000 mm","delivery_sla":"B","order_online":"0","packing_unit":"UN","pattern":"UNICOLOR","surface_per_box":"50 m²","total_thickness":"4 mm","variation_name":"WELDINGROD MEDIUMGREY","product_type":"WELDING","accessory_type":"WEL02"},
{"Id":"1287502","is_b2c":"1","is_b2b":"1","product_status":"2","material_status":"0","categories":"AINR10645,own_emea_RA","color_code":"0502","color_family":"CG","color_label":"LIGHT BROWN","delivery_sla":"B","design_key":"1287502","design_label":"WELDINGROD LIGHTBROWN","diameter":"4 mm","family":"var_ACCESSORIES","length":"50000 mm","order_online":"0","packing_unit":"UN","pattern":"UNICOLOR","surface_per_box":"50 m²","total_thickness":"4 mm","variation_name":"WELDINGROD LIGHTBROWN","accessory_type":"WEL02","product_type":"WELDING"},
{"Id":"1287503","is_b2c":"1","is_b2b":"1","product_status":"2","material_status":"0","categories":"AINR10645,own_emea_RA","color_code":"0503","color_family":"BW","color_label":"BROWN","delivery_sla":"B","design_key":"1287503","design_label":"WELDINGROD BROWN","diameter":"4 mm","family":"var_ACCESSORIES","length":"50000 mm","order_online":"0","packing_unit":"UN","pattern":"UNICOLOR","surface_per_box":"50 m²","total_thickness":"4 mm","variation_name":"WELDINGROD BROWN","product_type":"WELDING","accessory_type":"WEL02"},
{"Id":"1287504","is_b2c":"1","is_b2b":"1","product_status":"2","material_status":"0","design_key":"1287504","color_family":"Y","color_label":"MEDIUM YELLOW","design_label":"WELDINGROD MEDIUMYELLOW","diameter":"4 mm","family":"var_ACCESSORIES","length":"50000 mm","order_online":"0","total_thickness":"4 mm","variation_name":"WELDINGROD MEDIUMYELLOW","delivery_sla":"B","packing_unit":"UN","pattern":"UNICOLOR","surface_per_box":"50 m²","categories":"AINR10645,own_emea_RA","color_code":"0504","accessory_type":"WEL02","product_type":"WELDING"},
{"Id":"1287505","is_b2c":"1","is_b2b":"1","product_status":"2","material_status":"0","categories":"AINR10645,own_emea_RA","color_code":"0505","color_family":"Y","color_label":"DARK YELLOW","design_key":"1287505","design_label":"WELDINGROD DARKYELLOW","diameter":"4 mm","family":"var_ACCESSORIES","length":"50000 mm","delivery_sla":"B","order_online":"0","packing_unit":"UN","pattern":"UNICOLOR","surface_per_box":"50 m²","total_thickness":"4 mm","variation_name":"WELDINGROD DARKYELLOW","product_type":"WELDING","accessory_type":"WEL02"},
{"Id":"1287506","is_b2c":"0","is_b2b":"0","product_status":"","material_status":"5","collections":"-1","categories":"AINR10645,own_emea_RA","accessory_type":"WEL02","product_type":"WELDING","family":"ACCESSORIES"},
{"Id":"1287507","is_b2c":"0","is_b2b":"0","product_status":"","material_status":"0","collections":"-1","categories":"AINR10645,own_emea_RA","accessory_type":"WEL02","product_type":"WELDING","family":"ACCESSORIES"},
{"Id":"1287508","is_b2c":"0","is_b2b":"0","product_status":"","material_status":"1","collections":"-1","family":"ACCESSORIES","product_type":"WELDING","categories":"AINR10645,own_emea_RA","accessory_type":"WEL02"},
{"Id":"1287509","is_b2c":"1","is_b2b":"1","product_status":"2","material_status":"0","pattern":"UNICOLOR","surface_per_box":"50 m²","total_thickness":"4 mm","variation_name":"WELDINGROD LIGHT GREENBLUE","color_label":"LIGHT GREEN BLUE","design_key":"1287509","design_label":"WELDINGROD LIGHT GREENBLUE","diameter":"4 mm","family":"var_ACCESSORIES","length":"50000 mm","delivery_sla":"B","order_online":"0","packing_unit":"UN","categories":"AINR10645,own_emea_RA","color_code":"0509","color_family":"U","accessory_type":"WEL02","product_type":"WELDING"},
{"Id":"1287510","is_b2c":"0","is_b2b":"0","product_status":"","material_status":"9","collections":"-1","categories":"AINR10645,own_emea_RA","accessory_type":"WEL02","family":"ACCESSORIES","product_type":"WELDING"},
{"Id":"1287511","is_b2c":"0","is_b2b":"0","product_status":"","material_status":"1","collections":"-1","product_type":"WELDING","family":"ACCESSORIES","categories":"AINR10645,own_emea_RA","accessory_type":"WEL02"},
{"Id":"1287512","is_b2c":"0","is_b2b":"0","product_status":"","material_status":"1","collections":"-1","categories":"AINR10645,own_emea_RA","accessory_type":"WEL02","family":"ACCESSORIES","product_type":"WELDING"},
{"Id":"1287513","is_b2c":"1","is_b2b":"1","product_status":"2","material_status":"0","categories":"AINR10645,own_emea_RA","color_code":"0513","color_family":"R","color_label":"LIGHT RED BLUE","delivery_sla":"B","design_key":"1287513","design_label":"WELDINGROD LIGHT REDBLUE","diameter":"4 mm","family":"var_ACCESSORIES","length":"50000 mm","order_online":"0","packing_unit":"UN","pattern":"UNICOLOR","surface_per_box":"50 m²","total_thickness":"4 mm","variation_name":"WELDINGROD LIGHT REDBLUE","accessory_type":"WEL02","product_type":"WELDING"},
{"Id":"1287514","is_b2c":"0","is_b2b":"0","product_status":"","material_status":"0","collections":"-1","product_type":"WELDING","family":"ACCESSORIES","categories":"AINR10645,own_emea_RA","accessory_type":"WEL02"},
{"Id":"1287515","is_b2c":"1","is_b2b":"1","product_status":"2","material_status":"0","categories":"AINR10645,own_emea_RA","color_code":"0515","color_family":"R","color_label":"DARK RED BLUE","delivery_sla":"B","design_key":"1287515","design_label":"WELDINGROD DARK REDBLUE","diameter":"4 mm","family":"var_ACCESSORIES","length":"50000 mm","order_online":"0","packing_unit":"UN","pattern":"UNICOLOR","surface_per_box":"50 m²","total_thickness":"4 mm","variation_name":"WELDINGROD DARK REDBLUE","product_type":"WELDING","accessory_type":"WEL02"}
Provider.php
ServiceA.php
ServiceZ.php
Data.json
<?php
/**
* Class CollectionProvider
*/
class CollectionProvider
{
/**
* Insert the collections in ES
*/
public function populate(args)
{
$collections = getCollectionsFromFiles(); // Does a lot of Stuff
foreach ($collections as $collection) {
$this->collectionIndex->addDocument($collection); // Add a document to an index
}
}
}
Mapper.php
Model.php
ServiceB.php
<?php
namespace AppBundle\Elastica\Model;
use Elastica\Document;
class Sku extends Document
{
public function getData()
{
$rawTechnicalCharacteristics = [];
if (null !== $this->technicalCharacteristics) {
foreach ($this->technicalCharacteristics as $type => $technicalCharacteristic) {
$rawTechnicalCharacteristics[$type] = $technicalCharacteristic->getValue();
}
}
return [
'sku_id' => $this->getId(),
'sku_name' => $this->getName(),
'sku_backing' => $this->getBacking(),
'sku_color_name' => $this->getColorName(),
'sku_thumbnail' => $this->getThumbnail(),
'sku_product_type_label' => $this->getProductTypeLabel(),
'sku_format_type' => $this->getFormatType(),
'sku_format_shape' => $this->getFormatShape(),
// And a hell lot more
'sku_length_per_box' => $this->getLengthPerBox(),
'sku_locking_system' => $this->getLockingSystem(),
'sku_staining_method' => $this->getStainingMethod(),
'sku_dye_method' => $this->getDyeMethod(),
];
}
}
When do I need to Index?
Title Text
<?php
namespace AppBundle\Elastica\Model;
use Elastica\Document;
class Sku extends Document
{
public function getData()
{
$rawTechnicalCharacteristics = [];
if (null !== $this->technicalCharacteristics) {
foreach ($this->technicalCharacteristics as $type => $technicalCharacteristic) {
$rawTechnicalCharacteristics[$type] = $technicalCharacteristic->getValue();
}
}
return [
'sku_id' => $this->getId(),
'sku_name' => $this->getName(),
'sku_backing' => $this->getBacking(),
'sku_color_name' => $this->getColorName(),
'sku_thumbnail' => $this->getThumbnail(),
'sku_product_type_label' => $this->getProductTypeLabel(),
'sku_format_type' => $this->getFormatType(),
'sku_format_shape' => $this->getFormatShape(),
// And a hell lot more
'sku_length_per_box' => $this->getLengthPerBox(),
'sku_locking_system' => $this->getLockingSystem(),
'sku_staining_method' => $this->getStainingMethod(),
'sku_dye_method' => $this->getDyeMethod(),
];
}
}
AsA wise developper, I start an indexation when I modify the getData function
<?php
namespace AppBundle\Elastica\Mapper;
class SkuMapper extends AbstractMapper
{
/**
* @param array $technicalCharacteristics
* @return Sku
*/
private function getModel(array $technicalCharacteristics) {
$sku = new Sku();
// A lot of mapping stuff before...
if (!empty($technicalCharacteristics['thumbnail_image']) &&
!empty($technicalCharacteristics['thumbnail_image']->getValue())) {
$sku->setThumbnail($technicalCharacteristics['thumbnail_image']->getValue());
} elseif ($sku->isAccessory() &&
!empty($sku->getPatternCode()) &&
isset($sku->getAccessoryType()['label']) &&
isset($sku->getAccessoryType()['code'])
) {
$sku->setThumbnail(
$this->accessoryService->getThumbnail(
$sku->getPatternCode(),
$sku->getAccessoryType()['label'],
$sku->getAccessoryType()['code']
)
);
}
// A lot of mapping stuff after...
return $sku;
}
}
<?php
namespace AppBundle\Elastica\Mapper;
class SkuMapper extends AbstractMapper
{
/**
* @param array $technicalCharacteristics
* @return Sku
*/
private function getModel(array $technicalCharacteristics) {
$sku = new Sku();
// A lot of mapping stuff before...
if (!empty($technicalCharacteristics['thumbnail_image']) &&
!empty($sku->setThumbnail($technicalCharacteristics['thumbnail_image']->getValue()))) {
$sku->setThumbnail($technicalCharacteristics['thumbnail_image']->getValue());
} elseif ($sku->isAccessory() &&
!empty($sku->getPatternCode()) &&
isset($sku->getAccessoryType()['label']) &&
isset($sku->getAccessoryType()['code'])
) {
$sku->setThumbnail(
$this->accessoryService->getThumbnail(
$sku->getPatternCode(),
$sku->getAccessoryType()['label'],
$sku->getAccessoryType()['code']
)
);
}
// A lot of mapping stuff after...
return $sku;
}
}
AsA wise developper, I start an indexation when I modify a Mapper
NBC FOR NEWBIES
PO: We need this new thumbnail field to have beautiful images displayed!
Gotcha! I'm on it!
<?php
namespace AppBundle\Elastica\Model;
use Elastica\Document;
class Sku extends Document
{
public function getData()
{
$rawTechnicalCharacteristics = [];
if (null !== $this->technicalCharacteristics) {
foreach ($this->technicalCharacteristics as $type => $technicalCharacteristic) {
$rawTechnicalCharacteristics[$type] = $technicalCharacteristic->getValue();
}
}
return [
'sku_id' => $this->getId(),
'sku_name' => $this->getName(),
'sku_backing' => $this->getBacking(),
'sku_color_name' => $this->getColorName(),
'sku_thumbnail' => $this->getThumbnail(),
'sku_product_type_label' => $this->getProductTypeLabel(),
'sku_format_type' => $this->getFormatType(),
'sku_format_shape' => $this->getFormatShape(),
// And a hell lot more
'sku_length_per_box' => $this->getLengthPerBox(),
'sku_locking_system' => $this->getLockingSystem(),
'sku_staining_method' => $this->getStainingMethod(),
'sku_dye_method' => $this->getDyeMethod(),
];
}
}
<?php
namespace AppBundle\Elastica\Model;
use Elastica\Document;
class Sku extends Document
{
public function getData()
{
$rawTechnicalCharacteristics = [];
if (null !== $this->technicalCharacteristics) {
foreach ($this->technicalCharacteristics as $type => $technicalCharacteristic) {
$rawTechnicalCharacteristics[$type] = $technicalCharacteristic->getValue();
}
}
return [
'sku_id' => $this->getId(),
'sku_name' => $this->getName(),
'sku_backing' => $this->getBacking(),
'sku_color_name' => $this->getColorName(),
'sku_product_type_label' => $this->getProductTypeLabel(),
'sku_format_type' => $this->getFormatType(),
'sku_format_shape' => $this->getFormatShape(),
// And a hell lot more
'sku_length_per_box' => $this->getLengthPerBox(),
'sku_locking_system' => $this->getLockingSystem(),
'sku_staining_method' => $this->getStainingMethod(),
'sku_dye_method' => $this->getDyeMethod(),
];
}
}
class SkuRepository extends SearchRepository
{
/**
* @param array $skuIds
*
* @return Query
*/
public function getSamplesFromSkuIdsQuery(array $skuIds) :Query
{
$query = new Query();
$boolSkuQuery = new BoolQuery();
$boolSkuQuery->addShould(new Query\Terms('sku_id.raw', $skuIds));
$query->setQuery($boolSkuQuery);
$query->setSource([
'include' => [
'sku_samples',
'sku_color_code',
'sku_color_name',
'sku_texture_code',
'sku_pattern_code',
'sku_thumbnail',
],
]);
return $query;
}
}
Indexation Process
Deployment Process
Ticket merged
deck
By Gabriel Andrin
deck
- 695