Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick search improvements #2772

Open
wants to merge 36 commits into
base: Develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5233f78
comments
Apr 25, 2023
4b2e7b8
Changed the quick search behavior so that it allows title and author …
Apr 26, 2023
d13d465
proof of concept fuzzy matching
Apr 26, 2023
ada0cc4
fuzzy matching for all but cc
Apr 29, 2023
8e8c9a1
fuzzy matching for all categories but cc
Apr 29, 2023
4be089d
Merge remote-tracking branch 'origin/master'
Apr 29, 2023
61f1e20
fuzzy matching for all categories but cc
Apr 29, 2023
7a43e07
Merge branch 'master' of https://github.com/quarz12/calibre-web
Apr 29, 2023
f497cc0
removed todo
Apr 29, 2023
2e3c93b
removed debugging help
Apr 29, 2023
6b93829
Merge remote-tracking branch 'origin/master'
Apr 29, 2023
af40fee
I accidentally used pycharms auto-add-to-requirements feature which r…
May 3, 2023
9fc0d54
idea for weighted sorting
May 8, 2023
4ba3b4e
typing for query
quarz12 May 9, 2023
932c796
fixed an issue where the lowering and stripping of the search term wa…
May 10, 2023
97c94f2
moved sorting back to original place
May 10, 2023
45d8d63
sort using only authorsort and title
quarz12 May 11, 2023
c115fe9
use partial token set ratio instead
quarz12 May 11, 2023
086527f
test at home
quarz12 May 11, 2023
ad5313e
new idea
May 15, 2023
e45619f
progress building string of book
quarz12 May 17, 2023
a936a33
updated Books string repr
May 27, 2023
cb5e66f
add partial token set ratio to db
May 28, 2023
025a888
rolled back string repr of book, moved that part to a new method
May 28, 2023
caf6079
moved author filter to the rest of the filters, ignore words smaller …
May 28, 2023
56d4a3d
Merge branch 'master' into sorting
quarz12 May 28, 2023
c018ef7
Merge pull request #2 from quarz12/sorting
quarz12 May 28, 2023
b96d02c
now return empty list if all words of query are < 3 letters, only com…
May 30, 2023
5e0430e
message when query returns 0 results
May 31, 2023
896e8fd
minor cleanup, removed unused code
Jun 3, 2023
4b36261
removed unwanted refactoring
quarz12 Apr 13, 2024
2ac1566
Merge pull request #3 from quarz12/sorting
quarz12 Apr 13, 2024
518c56e
removed some more unwanted refactoring
quarz12 Apr 13, 2024
a295651
Merge branch 'master' of https://github.com/quarz12/calibre-web
quarz12 Apr 13, 2024
cca178f
Merge branch 'master' of https://github.com/quarz12/calibre-web
quarz12 Apr 13, 2024
b37554f
Merge branch 'master' of https://github.com/quarz12/calibre-web
quarz12 Apr 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
progress building string of book
  • Loading branch information
quarz12 committed May 17, 2023
commit e45619f2268cfffb218f5cd0c83206f7ce052133
24 changes: 11 additions & 13 deletions cps/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import traceback
from datetime import datetime
from urllib.parse import quote

import sqlalchemy
import unidecode

from sqlite3 import OperationalError as sqliteOperationalError
Expand All @@ -40,7 +38,6 @@
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import desc,asc
from sqlalchemy.pool import StaticPool
from sqlalchemy.sql.expression import and_, true, false, text, func, or_
from sqlalchemy.ext.associationproxy import association_proxy
Expand Down Expand Up @@ -384,9 +381,11 @@ def __init__(self, title, sort, author_sort, timestamp, pubdate, series_index, l
self.has_cover = (has_cover != None)

def __repr__(self):
return "<Books('{0},{1}{2}{3}{4}{5}{6}{7}{8}')>".format(self.title, self.sort, self.author_sort,
return "<Books('{0},{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}')>".format(self.title, self.sort, self.author_sort,
self.timestamp, self.pubdate, self.series_index,
self.last_modified, self.path, self.has_cover)
self.last_modified, self.path, self.has_cover,
[tag.name for tag in self.tags],
[series.name for series in self.series])

@property
def atom_timestamp(self):
Expand Down Expand Up @@ -586,7 +585,7 @@ def check_valid_db(cls, config_calibre_dir, app_db_path, config_calibre_uuid):
return False, False
try:
check_engine = create_engine('sqlite://',
echo=True,
echo=False,
isolation_level="SERIALIZABLE",
connect_args={'check_same_thread': False},
poolclass=StaticPool)
Expand Down Expand Up @@ -889,8 +888,8 @@ def check_exists_book(self, authr, title):
return self.session.query(Books) \
.filter(and_(Books.authors.any(and_(*q)), func.lower(Books.title).ilike("%" + title + "%"))).first()

def search_query(self, term, config, *join)->sqlalchemy.orm.Query:
term.strip().lower()
def search_query(self, term, config, *join):
term=term.strip().lower()
self.session.connection().connection.connection.create_function("lower", 1, lcase)
self.session.connection().connection.connection.create_function("partial_ratio", 2, partial_ratio)
q = list()
Expand Down Expand Up @@ -957,11 +956,10 @@ def get_search_results(self, term, config, offset=None, order=None, limit=None,
order = order[0] if order else [Books.sort]
pagination = None
result = self.search_query(term, config, *join).order_by(*order).all()
#sort here
for row in result:
print(row)

#result = self.search_query(term, config, *join).order_by(desc(func.sort(Books.tags))).all()#*order
sorted(result,key=lambda book:1)
for res in result:
print(res[0])
print(f"{res[0].title} {[tag.name for tag in res[0].tags]} {[series.name for series in res[0].series]}")
result_count = len(result)
if offset != None and limit != None:
offset = int(offset)
Expand Down