Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Heyheylibrary
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TheJoeCoder
Heyheylibrary
Commits
f8e3e3c3
Verified
Commit
f8e3e3c3
authored
3 months ago
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
Implement the same fuzzy search system in OPAC
parent
59fe81ca
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#319
passed
3 months ago
Stage: build
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
librarian/views.py
+1
-3
1 addition, 3 deletions
librarian/views.py
opac/views.py
+28
-2
28 additions, 2 deletions
opac/views.py
with
29 additions
and
5 deletions
librarian/views.py
+
1
−
3
View file @
f8e3e3c3
...
...
@@ -634,12 +634,10 @@ def search_all(request):
*
[
Q
(
"
term
"
,
**
{
f
:
query
})
for
f
in
term_fields
],
])
print
(
query_conditions
)
qur
=
srch
.
query
(
query_conditions
).
execute
()
print
(
qur
.
to_dict
())
# Get results
# TODO this does 1 query per result, which is inefficient.
results
=
[]
for
hit
in
qur
:
if
hit
.
meta
.
index
==
"
books
"
:
...
...
This diff is collapsed.
Click to expand it.
opac/views.py
+
28
−
2
View file @
f8e3e3c3
...
...
@@ -40,10 +40,36 @@ def search_all(request):
"""
query
=
request
.
GET
.
get
(
"
q
"
)
fields
=
[
"
first_name
"
,
"
last_name
"
,
"
title
"
,
"
description
"
,
"
isbn10
"
,
"
isbn13
"
]
fuzzy_search_fields
=
[
"
first_name
"
,
"
last_name
"
,
"
title
"
,
"
description
"
]
term_fields
=
[]
if
query
.
isdigit
():
# If the query is a number, search for ISBNs and years
term_fields
+=
[
"
published_year
"
,
"
isbn10
"
,
"
isbn13
"
,
]
# Create the search object
search
=
Search
(
index
=
[
"
books
"
,
"
authors
"
])
qry
=
search
.
query
(
"
multi_match
"
,
query
=
query
,
fields
=
fields
).
execute
()
# Build the query from the fields
query_conditions
=
Q
(
"
bool
"
,
should
=
[
*
[
Q
(
"
fuzzy
"
,
**
{
f
:
query
})
for
f
in
fuzzy_search_fields
],
*
[
Q
(
"
term
"
,
**
{
f
:
query
})
for
f
in
term_fields
],
])
# Query using the search object
qry
=
search
.
query
(
query_conditions
).
execute
()
# Gather results
# TODO this does 1 query per result, which is inefficient.
results
=
[]
for
result
in
qry
:
if
result
.
meta
.
index
==
"
books
"
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment