Skip to content

Commit

Permalink
Attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Goulven.Furet authored and Goulven.Furet committed Oct 23, 2023
1 parent dc58fde commit 79a330c
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Product build(final DataFragment fragment, final Product data ) throws Ag
throw e;
}
catch (final Exception e) {
e.printStackTrace();
logger.warn("AggregationService {} throw an exception while processing data {}",service.getClass().getName(), data,e);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public void onDataFragment(final DataFragment dataFragment, final Product produc
Set<String> toRemoveFromUnmatched = new HashSet<>();
// Adding the list of "to be removed" attributes
toRemoveFromUnmatched.addAll(attributesConfig.getExclusions());



/////////////////////////////////////////
// Converting to AggregatedAttributes for matches from config
/////////////////////////////////////////
Expand All @@ -71,7 +70,7 @@ public void onDataFragment(final DataFragment dataFragment, final Product produc
all.addAll(product.getAttributes().getUnmapedAttributes().stream().map(e -> new Attribute(e.getName(),e.getValue(),e.getLanguage())).toList());


for (Attribute attr : dataFragment.getAttributes()) {
for (Attribute attr : all) {

// Checking if a potential AggregatedAttribute
Attribute translated = attributesConfig.translateAttribute(attr, dataFragment.getDatasourceName());
Expand All @@ -85,16 +84,22 @@ public void onDataFragment(final DataFragment dataFragment, final Product produc
// Applying parsing rule
translated = parseAttributeValue(translated, attrConfig);

if (translated.getRawValue() == null) {
continue;
}

AggregatedAttribute agg = product.getAttributes().getAggregatedAttributes().get(attr.getName());

toRemoveFromUnmatched.add(translated.getName());

if (null == agg) {
// A first time match
agg = new AggregatedAttribute();
agg.setName(attr.getName());
}




toRemoveFromUnmatched.add(translated.getName());
agg.addAttribute(translated,attrConfig, new UnindexedKeyValTimestamp(dataFragment.getDatasourceName(), translated.getValue().toString()));

// Replacing new AggAttribute in product
Expand Down Expand Up @@ -153,6 +158,12 @@ public void onDataFragment(final DataFragment dataFragment, final Product produc
product.getAttributes().getUnmapedAttributes().add(agg);
}


// Removing
product.getAttributes().setUnmapedAttributes(product.getAttributes().getUnmapedAttributes().stream().filter(e -> !toRemoveFromUnmatched.contains(e.getName())) .collect(Collectors.toSet()));



// TODO : Removing matchlist again to handle remove of old attributes in case of configuration change
// product.getAttributes().getUnmapedAttributes().
}
Expand Down Expand Up @@ -488,6 +499,17 @@ public Attribute parseAttributeValue(final Attribute attr, final AttributeConfig

}




/////////////////////////////////
// FIXED TEXT MAPPING
/////////////////////////////////
if (!conf.getMappings().isEmpty() ) {
String replacement = conf.getMappings().get(attr.getRawValue());
attr.setRawValue(replacement);
}

/////////////////////////////////
// Checking preliminary result
/////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public class AttributeConfig {
*/
private boolean asRating = false;

/**
* If true, this attribute will be used as search filter
*/
private boolean asSearchFilter = true;





/**
* The ordering that must be applied to this attributes values after aggregations. (ie rendered in search attributes selection)
Expand All @@ -69,12 +77,12 @@ public class AttributeConfig {


/** If true, this attribute will be used for aggregations searches **/
private Boolean searchable = false;
// private Boolean searchable = false;

/**
* The position in the search page navigation zone
*/
private Integer searchPresentationOrder = Integer.MIN_VALUE;
// private Integer searchPresentationOrder = Integer.MIN_VALUE;

/**
* If set, this attribute will appear at the given attributeValuesOrdering in tabularised
Expand All @@ -89,22 +97,22 @@ public class AttributeConfig {
private String searchTemplate;



/**
* If non null, present the "count by" stats for this attribute, Will appear at the index designated by the integer value
*/
private Integer statsOrder;

/**
* the Chart.js chart type
*/
private AttrChartType statsType = AttrChartType.bar;

/**
* If true, will be the default stats rendered. (Should so only have one
* attribute set to true)
*/
private boolean statsDefaultView = false;
//
// /**
// * If non null, present the "count by" stats for this attribute, Will appear at the index designated by the integer value
// */
// private Integer statsOrder;
//
// /**
// * the Chart.js chart type
// */
// private AttrChartType statsType = AttrChartType.bar;
//
// /**
// * If true, will be the default stats rendered. (Should so only have one
// * attribute set to true)
// */
// private boolean statsDefaultView = false;



Expand All @@ -127,6 +135,13 @@ public class AttributeConfig {
* If set, text attributes will be converted to numerics using this table conversion
*/
private Map<String,Double> numericMapping = new HashMap<>();


/**
* If set, fixed text mappings conversion
*/
private Map<String,String> mappings = new HashMap<>();




Expand Down Expand Up @@ -314,15 +329,6 @@ public void setSynonyms(final Map<String, Set<String>> synonyms) {




public Boolean getSearchable() {
return searchable;
}

public void setSearchable(final Boolean aggregate) {
searchable = aggregate;
}

/**
* If set, this attribute will appear at the given attributeValuesOrdering in tabularised
* search results
Expand All @@ -343,30 +349,6 @@ public void setFaIcon(final String faIcon) {
this.faIcon = faIcon;
}

public Integer getStatsOrder() {
return statsOrder;
}

public void setStatsOrder(final Integer presentStats) {
statsOrder = presentStats;
}

public AttrChartType getStatsType() {
return statsType;
}

public void setStatsType(final AttrChartType statsType) {
this.statsType = statsType;
}

public boolean isStatsDefaultView() {
return statsDefaultView;
}

public void setStatsDefaultView(final boolean statsDefaultView) {
this.statsDefaultView = statsDefaultView;
}


public String getSearchTemplate() {
return searchTemplate;
Expand Down Expand Up @@ -412,21 +394,6 @@ public void setNumericMapping(final Map<String, Double> numericMapping) {
this.numericMapping = numericMapping;
}



public Integer getSearchPresentationOrder() {
return searchPresentationOrder;
}



public void setSearchPresentationOrder(final Integer searchPresentationOrder) {
this.searchPresentationOrder = searchPresentationOrder;
}




public boolean isAsRating() {
return asRating;
}
Expand All @@ -445,5 +412,21 @@ public void setName(final Localisable name) {
this.name = name;
}

public Map<String, String> getMappings() {
return mappings;
}

public void setMappings(Map<String, String> mappings) {
this.mappings = mappings;
}

public boolean isAsSearchFilter() {
return asSearchFilter;
}

public void setAsSearchFilter(boolean asSearchFilter) {
this.asSearchFilter = asSearchFilter;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -213,27 +213,27 @@ public List<AttributeConfig> searchTableAttributes() {
return ret;
}

/**
*
* @return the list of AttributeConfig that have to appear in search results,
* ordered by their display position
*/
public List<AttributeConfig> statsAttributes() {
final List<AttributeConfig> ret = new ArrayList<>();
for (final AttributeConfig a : attributesConfig.getConfigs()) {
if (null != a.getStatsOrder()) {
try {
ret.add(a.getStatsOrder(), a);
} catch (final IndexOutOfBoundsException e) {
LOGGER.warn("statsOrder {} is invalid for attribute {}. Will place last", a.getStatsOrder(),
a.getName());
ret.add(a);
}
}
}
return ret;
}

// /**
// *
// * @return the list of AttributeConfig that have to appear in search results,
// * ordered by their display position
// */
// public List<AttributeConfig> statsAttributes() {
// final List<AttributeConfig> ret = new ArrayList<>();
// for (final AttributeConfig a : attributesConfig.getConfigs()) {
// if (null != a.getStatsOrder()) {
// try {
// ret.add(a.getStatsOrder(), a);
// } catch (final IndexOutOfBoundsException e) {
// LOGGER.warn("statsOrder {} is invalid for attribute {}. Will place last", a.getStatsOrder(),
// a.getName());
// ret.add(a);
// }
// }
// }
// return ret;
// }
//


/**
Expand All @@ -243,7 +243,10 @@ public List<AttributeConfig> statsAttributes() {
public List<AttributeConfig> verticalFilters() {

return verticalFilters.stream()

.map(e -> getAttributesConfig().getAttributeConfigByKey(e))
.filter(e->e != null)
.filter(e->e.isAsSearchFilter())
.collect(Collectors.toList());

}
Expand Down
11 changes: 10 additions & 1 deletion commons/src/main/java/org/open4goods/model/product/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,16 @@ public List<String> datasourceCategoriesWithoutShortest() {
}



public String brandAndModel() {
String ret = "";
if (!StringUtils.isEmpty(brand())) {
ret += brand() +"-";
}

ret += model();

return ret;
}

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.open4goods.config.yml.attributes.AttributeConfig;
Expand Down Expand Up @@ -137,7 +138,7 @@ public VerticalSearchResponse verticalSearch(VerticalConfig vertical, VerticalSe

VerticalSearchResponse vsr = new VerticalSearchResponse();

List<AttributeConfig> customAttrFilters = vertical.verticalFilters();
List<AttributeConfig> customAttrFilters = vertical.verticalFilters().stream().filter(e-> e!= null).collect(Collectors.toList());


Criteria criterias = new Criteria("vertical").is(vertical.getId())
Expand Down
6 changes: 3 additions & 3 deletions ui/src/main/resources/templates/inc/attribute-sourcing.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span th:with="conflicts = ${attribute.hasConflicts()}, sourcesCount=${attribute.sourcesCount()}, distinctValues=${attribute.distinctValues()}">
<span th:if="${attribute}" th:with="conflicts = ${attribute.hasConflicts()}, sourcesCount=${attribute.sourcesCount()}, distinctValues=${attribute.distinctValues()}">

<!-- /** Conflicts **/ -->
<img th:if="${conflicts}" class="help-pointer" height="16" src="/icons/ko.png" data-bs-toggle="tooltip" data-bs-placement="top" th:title="#{attribute.sourcing.conflict(${attribute.sourcesCount()}, ${disctinctValues})}">
Expand All @@ -7,7 +7,7 @@


<!-- /** 1 source **/ -->
<span th:if="${sourcesCount == 1}" class="help-pointer badge rounded-pill bg-info" th:text="${sourcesCount}" data-bs-toggle="tooltip" data-bs-placement="top" th:title="#{attribute.sourcing.list(${attribute.sourcesCount()}, ${disctinctValues}, ${attribute.providersToString()})}">1</span>
<span th:if="${sourcesCount == 1}" class="help-pointer badge rounded-pill bg-info" th:text="${sourcesCount}" data-bs-toggle="tooltip" data-bs-placement="top" th:title="#{attribute.sourcing.list(${attribute.sourcesCount()}, ${disctinctValues}, ${attribute.providersToString()})}"></span>
<!-- /** multiple source **/ -->
<span th:unless="${sourcesCount == 1}" class="help-pointer badge rounded-pill bg-success" th:text="${sourcesCount}" data-bs-toggle="tooltip" data-bs-placement="top" th:title="#{attribute.sourcing.list(${attribute.sourcesCount()}, ${disctinctValues}, ${attribute.sourcesToString()})})}">1</span>
<span th:unless="${sourcesCount == 1}" class="help-pointer badge rounded-pill bg-success" th:text="${sourcesCount}" data-bs-toggle="tooltip" data-bs-placement="top" th:title="#{attribute.sourcing.list(${attribute.sourcesCount()}, ${disctinctValues}, ${attribute.sourcesToString()})}"></span>
</span>
6 changes: 3 additions & 3 deletions ui/src/main/resources/templates/inc/product-attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<tbody>
<th:block th:each="attribute : ${product.attributes.aggregatedAttributes.values()}">
<tr>
<th class="help-pointer" scope="row" th:text="${helper.attributeName(attribute.name)}"></th>
<th scope="row" th:text="${helper.attributeName(attribute.name)}"></th>


<th:block th:switch="${attribute.name}">
<td class="lead help-pointer" th:case="'REPAIRABILITY_INDEX'" th:insert="~{inc/attributes/class_energy.html}"> </td>
<td class="lead help-pointer" th:case="*" th:text="${attribute.value}"></td>
<td class="lead" th:case="'REPAIRABILITY_INDEX'" th:insert="~{inc/attributes/class_energy.html}"> </td>
<td class="lead" th:case="*" th:text="${attribute.value}"></td>
</th:block>
<td class="float-end">
<th:block th:insert="~{inc/attribute-sourcing.html}"></th:block>
Expand Down
Loading

0 comments on commit 79a330c

Please sign in to comment.