mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-13 03:36:35 +00:00
Save best-guess search results on import
This commit is contained in:
parent
ebabbf475a
commit
fa396d4bc8
3 changed files with 41 additions and 5 deletions
|
@ -76,9 +76,10 @@ def import_data(source, job_id):
|
|||
item.save()
|
||||
continue
|
||||
|
||||
if item.book:
|
||||
if item.book or item.book_guess:
|
||||
item.save()
|
||||
|
||||
if item.book:
|
||||
# shelves book and handles reviews
|
||||
handle_imported_book(
|
||||
source, job.user, item, job.include_reviews, job.privacy
|
||||
|
|
25
bookwyrm/migrations/0083_importitem_book_guess.py
Normal file
25
bookwyrm/migrations/0083_importitem_book_guess.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Generated by Django 3.2.4 on 2021-08-10 20:49
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0082_auto_20210806_2324"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="importitem",
|
||||
name="book_guess",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="book_guess",
|
||||
to="bookwyrm.book",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -71,7 +71,13 @@ class ImportItem(models.Model):
|
|||
index = models.IntegerField()
|
||||
data = models.JSONField()
|
||||
book = models.ForeignKey(Book, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
book_guess = models.ForeignKey(Book, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
book_guess = models.ForeignKey(
|
||||
Book,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="book_guess",
|
||||
)
|
||||
fail_reason = models.TextField(null=True)
|
||||
|
||||
def resolve(self):
|
||||
|
@ -81,7 +87,11 @@ class ImportItem(models.Model):
|
|||
else:
|
||||
# don't fall back on title/author search is isbn is present.
|
||||
# you're too likely to mismatch
|
||||
self.book = self.get_book_from_title_author()
|
||||
book, confidence = self.get_book_from_title_author()
|
||||
if confidence > 0.999:
|
||||
self.book = book
|
||||
else:
|
||||
self.book_guess = book
|
||||
|
||||
def get_book_from_isbn(self):
|
||||
"""search by isbn"""
|
||||
|
@ -97,12 +107,12 @@ class ImportItem(models.Model):
|
|||
"""search by title and author"""
|
||||
search_term = construct_search_term(self.title, self.author)
|
||||
search_result = connector_manager.first_search_result(
|
||||
search_term, min_confidence=0.999
|
||||
search_term, min_confidence=0.1
|
||||
)
|
||||
if search_result:
|
||||
# raises ConnectorException
|
||||
return search_result.connector.get_or_create_book(search_result.key)
|
||||
return None
|
||||
return None, 0
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
|
|
Loading…
Reference in a new issue