Improve search query formatting for metadata lookup
This commit is contained in:
committed by
aditya.chandel
parent
05460e7ff2
commit
3c7611495c
+15
-10
@@ -103,13 +103,6 @@ public class AmazonBookParser implements BookParser {
|
|||||||
log.debug("Skipping box set item (matched filtered phrase) in title: {}", extractAmazonBookId(item));
|
log.debug("Skipping box set item (matched filtered phrase) in title: {}", extractAmazonBookId(item));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (request.getAuthor() != null && !request.getAuthor().isBlank()) {
|
|
||||||
String itemText = item.text().toLowerCase();
|
|
||||||
if (!itemText.contains(request.getAuthor().toLowerCase())) {
|
|
||||||
log.debug("Skipping item as author '{}' not found in item text: {}", request.getAuthor(), extractAmazonBookId(item));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bookIds.add(extractAmazonBookId(item));
|
bookIds.add(extractAmazonBookId(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,11 +170,19 @@ public class AmazonBookParser implements BookParser {
|
|||||||
|
|
||||||
String title = fetchMetadataRequest.getTitle();
|
String title = fetchMetadataRequest.getTitle();
|
||||||
if (title != null && !title.isEmpty()) {
|
if (title != null && !title.isEmpty()) {
|
||||||
searchTerm.append(title.trim());
|
String cleanedTitle = Arrays.stream(title.split(" "))
|
||||||
|
.map(word -> word.replaceAll("[^a-zA-Z0-9]", "").trim())
|
||||||
|
.filter(word -> !word.isEmpty())
|
||||||
|
.collect(Collectors.joining(" "));
|
||||||
|
searchTerm.append(cleanedTitle);
|
||||||
} else {
|
} else {
|
||||||
String filename = BookUtils.cleanAndTruncateSearchTerm(BookUtils.cleanFileName(book.getFileName()));
|
String filename = BookUtils.cleanAndTruncateSearchTerm(BookUtils.cleanFileName(book.getFileName()));
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
searchTerm.append(filename.trim());
|
String cleanedFilename = Arrays.stream(filename.split(" "))
|
||||||
|
.map(word -> word.replaceAll("[^a-zA-Z0-9]", "").trim())
|
||||||
|
.filter(word -> !word.isEmpty())
|
||||||
|
.collect(Collectors.joining(" "));
|
||||||
|
searchTerm.append(cleanedFilename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +191,11 @@ public class AmazonBookParser implements BookParser {
|
|||||||
if (!searchTerm.isEmpty()) {
|
if (!searchTerm.isEmpty()) {
|
||||||
searchTerm.append(" ");
|
searchTerm.append(" ");
|
||||||
}
|
}
|
||||||
searchTerm.append(author.trim());
|
String cleanedAuthor = Arrays.stream(author.split(" "))
|
||||||
|
.map(word -> word.replaceAll("[^a-zA-Z0-9]", "").trim())
|
||||||
|
.filter(word -> !word.isEmpty())
|
||||||
|
.collect(Collectors.joining(" "));
|
||||||
|
searchTerm.append(cleanedAuthor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchTerm.isEmpty()) {
|
if (searchTerm.isEmpty()) {
|
||||||
|
|||||||
+1
@@ -370,6 +370,7 @@ public class GoodReadsParser implements BookParser {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info("GoodReads: No metadata previews found for title '{}'!", request.getTitle());
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
@@ -29,6 +29,10 @@ public class HardcoverParser implements BookParser {
|
|||||||
log.info("Hardcover: Fetching metadata for book {}", fetchMetadataRequest.getTitle());
|
log.info("Hardcover: Fetching metadata for book {}", fetchMetadataRequest.getTitle());
|
||||||
|
|
||||||
List<GraphQLResponse.Hit> hits = hardcoverBookSearchService.searchBooks(fetchMetadataRequest.getTitle());
|
List<GraphQLResponse.Hit> hits = hardcoverBookSearchService.searchBooks(fetchMetadataRequest.getTitle());
|
||||||
|
if (hits == null || hits.isEmpty()) {
|
||||||
|
log.info("Hardcover: No results found for title '{}'", fetchMetadataRequest.getTitle());
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
FuzzyScore fuzzyScore = new FuzzyScore(Locale.ENGLISH);
|
FuzzyScore fuzzyScore = new FuzzyScore(Locale.ENGLISH);
|
||||||
String searchAuthor = fetchMetadataRequest.getAuthor() != null ? fetchMetadataRequest.getAuthor() : "";
|
String searchAuthor = fetchMetadataRequest.getAuthor() != null ? fetchMetadataRequest.getAuthor() : "";
|
||||||
|
|||||||
Reference in New Issue
Block a user