Skip to content

Commit

Permalink
Now using automated and full categories path
Browse files Browse the repository at this point in the history
  • Loading branch information
goulven authored and goulven committed Oct 3, 2024
1 parent 3dd6ff6 commit ff48af0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ public class CsvDataSourceProperties {
*/
private Boolean trimUrlParameters = false;

/**
* Column name indicating the productCategory
*/
protected List<String> productTags = new ArrayList<>();

/**
* If true, all columns of this datasource will ba added as attributes
Expand Down Expand Up @@ -287,15 +283,6 @@ public void setTrimUrlParameters(final Boolean trimUrlParameters) {
this.trimUrlParameters = trimUrlParameters;
}

public List<String> getProductTags() {
return productTags;
}

public void setProductTags(List<String> productTags) {
this.productTags = productTags;
}



public Set<String> getPrice() {
return price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ public void addRseRating(final Rating rr) throws ValidationException {

public void addProductTags(final List<String> tags) {

addProductTag(StringUtils.join(tags, ">").toUpperCase().trim());
addProductTag(StringUtils.join(tags, " | ").toUpperCase().trim());
}

public void addProductTag(final String category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -418,7 +419,7 @@ private DataFragment parseCsvLine(final DataFragmentWebCrawler crawler, final Cr
}

p.addName(getFromCsvRow(item, csvProperties.getName()));
p.addProductTags(getCategoryFromCsvRows(item, csvProperties.getProductTags()));
p.addProductTags(getCategoryFromCsvRows(item));

if (!StringUtils.isEmpty(csvProperties.getAttrs())) {
handleAttributes(p, config, getFromCsvRow(item, csvProperties.getAttrs()), dedicatedLogger);
Expand Down Expand Up @@ -677,24 +678,21 @@ private void handleAttributes(final DataFragment pd, final DataSourceProperties
*/
private String getFromCsvRow(final Map<String, String> item, final String colName) {

final String val = item.get(colName);
if (null != val) {
return val;

} else {
return null;
}
return item.get(colName);

}

private List<String> getCategoryFromCsvRows(Map<String, String> item, List<String> colNames) {
List<String> ret = new ArrayList<>();
private List<String> getCategoryFromCsvRows(Map<String, String> item) {
Set<String> catsColumns = new HashSet<String>(item.keySet());

List<String> ret = catsColumns.stream()
.filter(e -> e.toLowerCase().contains("categor"))
.sorted()
.map(e -> item.get(e) )
.filter(e -> !StringUtils.isEmpty(e))
.toList();


for (String colName : colNames) {
String val = getFromCsvRow(item, colName);
if (!StringUtils.isEmpty(val)) {
ret.add(val);
}
}
return ret;
}

Expand Down

0 comments on commit ff48af0

Please sign in to comment.