]> git.phdru.name Git - m_librarian.git/commitdiff
Sort results
authorOleg Broytman <phd@phdru.name>
Sat, 14 May 2016 16:18:23 +0000 (19:18 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 14 May 2016 16:18:23 +0000 (19:18 +0300)
m_librarian/search.py
scripts/ml-search.py

index ad36cd0f2eff1bf5945fecaa837eb798ecec01c4..c4b53256d59ce17e12844fc36f31b7f16503e2d7 100644 (file)
@@ -44,28 +44,34 @@ def _search_substring(table, case_sensitive, values, expressions):
                                  expressions)
 
 
-def _search(table, search_type, case_sensitive, values, expressions):
+def _search(table, search_type, case_sensitive, values,
+            expressions, orderBy=None):
     _search_f = globals()['_search_%s' % search_type]
     conditions = _search_f(table, case_sensitive, values, expressions)
-    return table.select(conditions)
+    return table.select(conditions, orderBy=orderBy)
 
 
 def search_authors(search_type, case_sensitive, values,
-                   expressions):
-    return _search(Author, search_type, case_sensitive, values, expressions)
+                   expressions, orderBy=None):
+    return _search(Author, search_type, case_sensitive, values,
+                   expressions, orderBy)
 
 
-def search_books(search_type, case_sensitive, values):
-    return _search(Book, search_type, case_sensitive, values, [])
+def search_books(search_type, case_sensitive, values, orderBy=None):
+    return _search(Book, search_type, case_sensitive, values,
+                   [], orderBy)
 
 
-def search_extensions(search_type, case_sensitive, values):
-    return _search(Extension, search_type, case_sensitive, values, [])
+def search_extensions(search_type, case_sensitive, values, orderBy=None):
+    return _search(Extension, search_type, case_sensitive, values,
+                   [], orderBy)
 
 
-def search_genres(search_type, case_sensitive, values):
-    return _search(Genre, search_type, case_sensitive, values, [])
+def search_genres(search_type, case_sensitive, values, orderBy=None):
+    return _search(Genre, search_type, case_sensitive, values,
+                   [], orderBy)
 
 
-def search_languages(search_type, case_sensitive, values):
-    return _search(Language, search_type, case_sensitive, values, [])
+def search_languages(search_type, case_sensitive, values, orderBy=None):
+    return _search(Language, search_type, case_sensitive, values,
+                   [], orderBy)
index 2915f51e42cfb795f3e0f1069be8edcc11850143..04a8b53ace74b5898b8dbb7bba13c1260a43d94a 100755 (executable)
@@ -43,7 +43,8 @@ def _search_authors(case_sensitive, args):
     if case_sensitive is None:
         case_sensitive = _guess_case_sensitivity(values)
     for author in search_authors(args.search_type, case_sensitive, values,
-                                 expressions):
+                                 expressions,
+                                 orderBy=('surname', 'name', 'misc_name')):
         names = filter(None, (author.surname, author.name, author.misc_name))
         fullname = u' '.join(names)
         print fullname.encode(default_encoding), \
@@ -57,7 +58,8 @@ def _search_extensions(case_sensitive, args):
             case_sensitive = _guess_case_sensitivity(values)
     else:
         values = {}
-    for ext in search_extensions(args.search_type, case_sensitive, values):
+    for ext in search_extensions(args.search_type, case_sensitive, values,
+                                 orderBy='name'):
         print ext.name.encode(default_encoding), \
             (u"(%s: %d)" % (_('books'), ext.count)).encode(default_encoding)
 
@@ -71,7 +73,8 @@ def _search_genres(case_sensitive, args):
             values[column] = unicode(value, default_encoding)
     if case_sensitive is None:
         case_sensitive = _guess_case_sensitivity(values)
-    for genre in search_genres(args.search_type, case_sensitive, values):
+    for genre in search_genres(args.search_type, case_sensitive, values,
+                               orderBy='name'):
         names = filter(None, (genre.name, genre.title))
         fullname = u' '.join(names)
         print fullname.encode(default_encoding), \
@@ -85,7 +88,8 @@ def _search_languages(case_sensitive, args):
             case_sensitive = _guess_case_sensitivity(values)
     else:
         values = {}
-    for lang in search_languages(args.search_type, case_sensitive, values):
+    for lang in search_languages(args.search_type, case_sensitive, values,
+                                 orderBy='name'):
         print lang.name.encode(default_encoding), \
             (u"(%s: %d)" % (_('books'), lang.count)).encode(default_encoding)