Skip to content

Commit

Permalink
Categories edition
Browse files Browse the repository at this point in the history
  • Loading branch information
goulven authored and goulven committed Dec 8, 2024
1 parent a450720 commit 05554a0
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ public void updateVerticalWithMappings(

}


@GetMapping(path="/update/verticals/attributes/{vertical}")
@Operation(summary="Update the suggested attributes for a given vertical directly in the file !")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public void updateVerticalWithAttributes(
@RequestParam (defaultValue = "tv") String vertical) throws ResourceNotFoundException, IOException {

//TODO(p2,conf) : from conf
verticalsGenService.generateAttributesMapping(verticalsConfigService.getConfigById(vertical));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public String generateMapping(VerticalConfig vc, Integer minOfferscount) {
.map(e->e.gtin())
.toList();

return generateCategoryMappingFragmentForGtin(items,vc.getExcludedFromCategoriesMatching());
return generateCategoryMappingFragmentForGtin(items,vc.getGenerationExcludedFromCategoriesMatching());



Expand Down Expand Up @@ -533,19 +533,33 @@ public void updateVerticalFile(Integer minOffers, String fileName) {
* @param vertical
* @return
*/
public String generateAttributesMapping(String vertical, Set<String> excludeAttributes) {
VerticalAttributesStats stats = attributesStats(vertical);
public String generateAttributesMapping(VerticalConfig verticalConfig) {
LOGGER.info("Generating attributes mapping for {}", verticalConfig);
VerticalAttributesStats stats = attributesStats(verticalConfig.getId());

Set<String> exclusions = new HashSet<String>();
if (null != verticalConfig.getGenerationExcludedFromAttributesMatching()) {
exclusions.addAll(verticalConfig.getGenerationExcludedFromAttributesMatching());
}

// Adding existing defined attributes matching
verticalConfig.getAttributesConfig().getConfigs().stream().map(e->e.getSynonyms().values()).forEach(e -> {
e.forEach(elem -> {
elem.forEach(e1 -> {
exclusions.add(e1);
});
});
});



int totalItems = stats.getTotalItems();

for (Entry<String, AttributesStats> cat : stats.getStats().entrySet()) {

if (null != excludeAttributes && !excludeAttributes.contains(cat.getKey())) {

if (!exclusions.contains(cat.getKey())) {

LOGGER.info("An unknown attribute !");

// AttributesConfig
}
Expand All @@ -555,8 +569,35 @@ public String generateAttributesMapping(String vertical, Set<String> excludeAttr

}




/**
*
* @return an attribute definition, from template
*/
// public String attributeConfigTemplate() {
// String ret = "";
// try {
// Resource r = resourceResolver.getResource("classpath:/templates/attribute.yml");
// String content = r.getContentAsString(Charset.defaultCharset());
//
// Map<String, Object> context = new HashMap<String, Object>();
//
// context.put("id",id );
// context.put("googleTaxonomyId", googleTaxonomyId);
// // Here is a tweak, we provide some sample products coma separated
// context.put("matchingCategories", generateCategoryMappingFragmentForGtin(Arrays.asList(matchingCategories.split(",")), null));
// context.put("urlPrefix", urlPrefix);
// context.put("h1Prefix", h1Prefix);
// context.put("verticalHomeUrl", verticalHomeUrl);
// context.put("verticalHomeTitle", verticalHomeTitle);
//
// ret = evalService.thymeleafEval(context, content);
// } catch (IOException e) {
// LOGGER.error("Error while generating vertical file",e);
// }
//
// return ret;
//
// }
//

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,18 @@ public class VerticalConfig{
private Set<String> excludingTokensFromCategoriesMatching = new HashSet<String>();

/**
* The set of datasourcenames that will be excluded to generate categories matching
* The set of datasourcenames that will be excluded in generation of categories matching
*/
@JsonMerge
private Set<String> excludedFromCategoriesMatching = new HashSet<String>();
private Set<String> generationExcludedFromCategoriesMatching = new HashSet<String>();

/**
* The set of attributes names that will be excluded in generation of attributes suggestion
*/

@JsonMerge
private Set<String> generationExcludedFromAttributesMatching = new HashSet<String>();



/**
Expand Down Expand Up @@ -793,12 +800,12 @@ public void setForceNameGeneration(boolean forceUrlNameGeneration) {
this.forceNameGeneration = forceUrlNameGeneration;
}

public Set<String> getExcludedFromCategoriesMatching() {
return excludedFromCategoriesMatching;
public Set<String> getGenerationExcludedFromCategoriesMatching() {
return generationExcludedFromCategoriesMatching;
}

public void setExcludedFromCategoriesMatching(Set<String> excludedFromCategoriesMatching) {
this.excludedFromCategoriesMatching = excludedFromCategoriesMatching;
public void setGenerationExcludedFromCategoriesMatching(Set<String> excludedFromCategoriesMatching) {
this.generationExcludedFromCategoriesMatching = excludedFromCategoriesMatching;
}

public Set<String> getExcludingTokensFromCategoriesMatching() {
Expand All @@ -809,6 +816,14 @@ public void setExcludingTokensFromCategoriesMatching(Set<String> excludingTokens
this.excludingTokensFromCategoriesMatching = excludingTokens;
}

public Set<String> getGenerationExcludedFromAttributesMatching() {
return generationExcludedFromAttributesMatching;
}

public void setGenerationExcludedFromAttributesMatching(Set<String> generationExcludedFromAttributesMatching) {
this.generationExcludedFromAttributesMatching = generationExcludedFromAttributesMatching;
}




Expand Down
15 changes: 14 additions & 1 deletion verticals/src/main/resources/verticals/_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ forceNameGeneration: true


# These datasources will be excluded from categories matching
excludedFromCategoriesMatching:
generationExcludedFromCategoriesMatching:
- "fnac.com"
# - "rakuten.com-csv.yml"

generationExcludedFromAttributesMatching:
- FEED_URL
- FABRICANT
- REFURBISHED
- DISPONIBILITE
- ETAT_PRODUIT


# If product categories contains one of this token, this will be unmatched
excludingTokensFromCategoriesMatching:
- ACCESSOIRE



#####################################################################################################################################
# I18N CONFIGURATION
# Configure in a i18n way all the texts of a product, including the Url, the title, the description, the open graph metas, ....
Expand Down Expand Up @@ -256,6 +267,7 @@ attributesConfig:
- "CODEBARRE"
- "ETAT"
- "REFURBISHED"
- "ETAT_PRODUIT"
- "DISPONIBILITE"

# Noisy items
Expand Down Expand Up @@ -286,6 +298,7 @@ attributesConfig:
- "PRE_ORDER"
- "RATING"
- "SEARCH_PRICE"
- "PRICE_NEW"
- "STOCK_QUANTITY"
- "STOCK_STATUS"
- "WEB_OFFER"
Expand Down

0 comments on commit 05554a0

Please sign in to comment.