Skip to content

Commit 545f349

Browse files
committed
🔨 Match phrase for title search. Match exact string for ISBN
1 parent fea817c commit 545f349

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

db.sqlite3

0 Bytes
Binary file not shown.

library/libraryapp/documents.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BookDocument(DocType):
4444
'pk': fields.IntegerField(),
4545
}, include_in_root=True)
4646

47-
isbn = fields.StringField(
47+
isbn = fields.KeywordField(
4848
index='not_analyzed',
4949
)
5050

@@ -62,6 +62,3 @@ def get_instances_from_related(self, related_instance):
6262
"""If related_models is set, define how to retrieve the Book instance(s) from the related model."""
6363
if isinstance(related_instance, Author):
6464
return related_instance.book_set.all()
65-
66-
def prepare_exact_title(self, obj):
67-
return obj.title

library/libraryapp/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ def book_list(request):
6868

6969
title = form.cleaned_data['title']
7070
if title:
71-
search = search.query("fuzzy", title=title)
71+
search = search.query("match_phrase", title=title)
7272

7373
isbn = form.cleaned_data['isbn']
7474
if isbn:
75-
search = search.query("match", isbn=isbn)
75+
search = search.query("term", isbn=isbn)
7676

7777
authors = form.cleaned_data['authors']
7878
if authors:

0 commit comments

Comments
 (0)