This commit is contained in:
Stefan Hardegger
2025-07-29 11:02:46 +02:00
parent c08082c0d6
commit 5746001c4a
7 changed files with 103 additions and 6 deletions

View File

@@ -77,7 +77,7 @@ public class TypesenseService {
new Field().name("authorName").type("string").facet(true).sort(true),
new Field().name("seriesId").type("string").facet(true).optional(true),
new Field().name("seriesName").type("string").facet(true).sort(true).optional(true),
new Field().name("tagNames").type("string[]").facet(true).optional(true),
new Field().name("tagNames").type("string[]").facet(true),
new Field().name("rating").type("int32").facet(true).sort(true).optional(true),
new Field().name("wordCount").type("int32").facet(true).sort(true).optional(true),
new Field().name("volume").type("int32").facet(true).sort(true).optional(true),
@@ -232,6 +232,9 @@ public class TypesenseService {
.maxFacetValues(100)
.sortBy(buildSortParameter(normalizedQuery, sortBy, sortDir));
logger.debug("Typesense search parameters - facetBy: {}, maxFacetValues: {}",
searchParameters.getFacetBy(), searchParameters.getMaxFacetValues());
// Add filters
List<String> filterConditions = new ArrayList<>();
@@ -269,6 +272,7 @@ public class TypesenseService {
.documents()
.search(searchParameters);
logger.debug("Search result facet counts: {}", searchResult.getFacetCounts());
List<StorySearchDto> results = convertSearchResult(searchResult);
Map<String, List<FacetCountDto>> facets = processFacetCounts(searchResult);
@@ -375,7 +379,10 @@ public class TypesenseService {
.map(tag -> tag.getName())
.collect(Collectors.toList());
document.put("tagNames", tagNames);
logger.debug("Story '{}' has {} tags: {}", story.getTitle(), tagNames.size(), tagNames);
} else {
document.put("tagNames", new ArrayList<>());
logger.debug("Story '{}' has no tags, setting empty array", story.getTitle());
}
document.put("rating", story.getRating() != null ? story.getRating() : 0);
@@ -406,15 +413,34 @@ public class TypesenseService {
List<FacetCountDto> facetValues = new ArrayList<>();
if (facetCounts.getCounts() != null) {
for (Object countObj : facetCounts.getCounts()) {
if (countObj instanceof Map) {
Map<String, Object> countMap = (Map<String, Object>) countObj;
String value = (String) countMap.get("value");
Integer count = (Integer) countMap.get("count");
if (countObj instanceof org.typesense.model.FacetCountsCounts) {
org.typesense.model.FacetCountsCounts facetCount = (org.typesense.model.FacetCountsCounts) countObj;
String value = facetCount.getValue();
Integer count = facetCount.getCount();
if (value != null && count != null && count > 0) {
facetValues.add(new FacetCountDto(value, count));
}
} else if (countObj instanceof Map) {
// Fallback for Map-based responses
Map<String, Object> countMap = (Map<String, Object>) countObj;
String value = (String) countMap.get("value");
Object countValue = countMap.get("count");
if (value != null && countValue != null) {
Integer count = null;
if (countValue instanceof Integer) {
count = (Integer) countValue;
} else if (countValue instanceof Number) {
count = ((Number) countValue).intValue();
}
if (count != null && count > 0) {
facetValues.add(new FacetCountDto(value, count));
}
}
}
}
}
@@ -432,6 +458,12 @@ public class TypesenseService {
}
}
// DEBUG: Log final facet processing results
logger.info("FACET DEBUG: Final facetMap contents: {}", facetMap);
if (facetMap.isEmpty()) {
logger.info("FACET DEBUG: No facets were processed - investigating why");
}
return facetMap;
}