mirror of
https://gitlab.com/Alamantus/Readlebee.git
synced 2025-05-11 12:41:17 +02:00
Fix Open Library search results de-duplication
This commit is contained in:
parent
bf33ff8e3e
commit
3f9ca67918
1 changed files with 13 additions and 7 deletions
|
@ -173,7 +173,7 @@ class SearchController {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(`http://openlibrary.org/search.json?${searchBy}=${encodeURIComponent(this.term)}`)
|
return fetch(`https://openlibrary.org/search.json?${searchBy}=${encodeURIComponent(this.term)}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.hasOwnProperty('docs')) {
|
if (!response.hasOwnProperty('docs')) {
|
||||||
|
@ -187,13 +187,19 @@ class SearchController {
|
||||||
return booksController.handleOpenLibraryEntity(doc);
|
return booksController.handleOpenLibraryEntity(doc);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let results = [];
|
||||||
// Filter out duplicate items with the same title and author
|
// Filter out duplicate items with the same title and author
|
||||||
const results = docs.filter((doc, index, allDocs) => {
|
docs.forEach(doc => {
|
||||||
return typeof allDocs.find((filterResult, filterIndex) => {
|
const existingDoc = results.find((filterResult) => {
|
||||||
return index !== filterIndex && filterResult.title === doc.title
|
return filterResult.title === doc.title && filterResult.description === doc.description;
|
||||||
&& filterResult.description === doc.description;
|
});
|
||||||
}) === 'undefined';
|
|
||||||
}).map(result => {
|
if (!existingDoc) {
|
||||||
|
results.push(doc);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
results = results.map(result => {
|
||||||
// Find any duplicates in case they have different cover data
|
// Find any duplicates in case they have different cover data
|
||||||
const duplicates = docs.filter(doc => {
|
const duplicates = docs.filter(doc => {
|
||||||
return doc.name.toLowerCase() === result.name.toLowerCase() && doc.description === result.description;
|
return doc.name.toLowerCase() === result.name.toLowerCase() && doc.description === result.description;
|
||||||
|
|
Loading…
Add table
Reference in a new issue