from newtagging import managers
from catalogue.fields import JSONField, OverwritingFileField
from catalogue.utils import create_zip, split_tags
-from catalogue.tasks import touch_tag
+from catalogue.tasks import touch_tag, index_book
from shutil import copy
from glob import glob
import re
return result.wait()
def search_index(self, book_info=None):
- if settings.SEARCH_INDEX_PARALLEL:
- if instance(settings.SEARCH_INDEX_PARALLEL, int):
- idx = search.ReusableIndex(threads=4)
- else:
- idx = search.ReusableIndex()
+ if settings.CELERY_ALWAYS_EAGER:
+ idx = search.ReusableIndex()
else:
idx = search.Index()
idx.open()
try:
idx.index_book(self, book_info)
+ idx.index_tags()
finally:
idx.close()
book.build_mobi()
if not settings.NO_SEARCH_INDEX and search_index:
- book.search_index(book_info)
+ index_book.delay(book.id, book_info)
book_descendants = list(book.children.all())
descendants_tags = set()
#
from datetime import datetime
from celery.task import task
-
+import catalogue.models
@task
def touch_tag(tag):
}
type(tag).objects.filter(pk=tag.pk).update(**update_dict)
+
+
+@task
+def index_book(book_id, book_info=None):
+ return catalogue.models.Book.objects.get(id=book_id).search_index(book_info)
if you cannot rely on atexit, use ReusableIndex.close_reusable() yourself.
"""
index = None
- pool = None
- pool_jobs = None
def open(self, analyzer=None, threads=4):
if ReusableIndex.index is not None:
self.index = ReusableIndex.index
else:
print("opening index")
- ReusableIndex.pool = ThreadPool(threads, initializer=lambda: JVM.attachCurrentThread() )
- ReusableIndex.pool_jobs = []
Index.open(self, analyzer)
ReusableIndex.index = self.index
atexit.register(ReusableIndex.close_reusable)
- def index_book(self, *args, **kw):
- job = ReusableIndex.pool.apply_async(log_exception_wrapper(Index.index_book), (self,) + args, kw)
- ReusableIndex.pool_jobs.append(job)
+ # def index_book(self, *args, **kw):
+ # job = ReusableIndex.pool.apply_async(log_exception_wrapper(Index.index_book), (self,) + args, kw)
+ # ReusableIndex.pool_jobs.append(job)
@staticmethod
def close_reusable():
if ReusableIndex.index is not None:
- print("wait for indexing to finish")
- for job in ReusableIndex.pool_jobs:
- job.get()
- sys.stdout.write('.')
- sys.stdout.flush()
- print("done.")
- ReusableIndex.pool.close()
-
ReusableIndex.index.optimize()
ReusableIndex.index.close()
ReusableIndex.index = None
from django.contrib.auth.decorators import login_required
from django.views.decorators import cache
from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect
+from django.utils.translation import ugettext as _
from catalogue.utils import get_random_hash
from catalogue.models import Book, Tag, Fragment, TAG_CATEGORIES
def hint(request):
prefix = request.GET.get('term', '')
if len(prefix) < 2:
- return JSONResponse(dumps(None))
+ return JSONResponse([])
JVM.attachCurrentThread()
s = MultiSearch()
# jezeli tagi dot tylko ksiazki, to wazne zeby te nowe byly w tej samej ksiazce
# jesli zas dotycza themes, to wazne, zeby byly w tym samym fragmencie.
+ # import pdb; pdb.set_trace()
+
tags = s.hint_tags(prefix)
books = s.hint_books(prefix)
return JSONResponse(
[{'label': t.name,
- 'category': category_name(t.category),
+ 'category': _(category_name(t.category)),
'id': t.id,
'url': t.get_absolute_url()}
for t in tags] + \
[{'label': b.title,
- 'category': category_name('book'),
+ 'category': _(category_name('book')),
'id': b.id,
'url': b.get_absolute_url()}
for b in books])
'css/book_box.css',
'css/catalogue.css',
'css/sponsors.css',
+
+ 'css/ui-lightness/jquery-ui-1.8.16.custom.css',
],
'output_filename': 'css/all.min?.css',
},
'js/jquery.countdown-es.js', 'js/jquery.countdown-lt.js',
'js/jquery.countdown-ru.js', 'js/jquery.countdown-fr.js',
+ 'js/jquery-ui-1.8.16.custom.min.js',
+
'js/locale.js',
'js/dialogs.js',
'js/sponsors.js',
'js/pdcounter.js',
+ 'js/search.js',
+
#~ 'js/jquery.autocomplete.js',
#~ 'js/jquery.labelify.js', 'js/catalogue.js',
),
--- /dev/null
+
+var __bind = function (self, fn) {
+ return function() { fn.apply(self, arguments); };
+};
+
+(function($){
+ $.widget("wl.search", {
+ options: {
+ minLength: 0,
+ },
+
+ _create: function() {
+ var opts = {
+ minLength: this.options.minLength,
+ select: __bind(this, this.enter),
+ focus: function() { return false; },
+ source: this.element.data('source'),
+ };
+ this.element.autocomplete(opts).data("autocomplete")._renderItem = __bind(this, this.render_item);
+ },
+
+ enter: function(event, ui) {
+ if (ui.item.url != undefined) {
+ location.href = ui.item.url;
+ } else {
+ this.element.closest('form').submit();
+ }
+ },
+
+ render_item: function (ul, item) {
+ return $("<li></li>").data('item.autocomplete', item)
+ .append('<a href="'+item.url+'">'+item.label+ ' ('+item.category+')</a>')
+ .appendTo(ul);
+ },
+
+ destroy: function() {
+
+ },
+
+
+
+ });
+
+ $(function() {
+ $("#search input[name=q]").search();
+
+ });
+
+})(jQuery);
<form id="search">
<span id="search-field" class="grid-line">
- <input title="np. Leśmian" name="q" autocomplete="off">
+ <input title="np. Leśmian" name="q" autocomplete="off" data-source="/fullsearch/hint/">
</span><span id="search-button">
<button type='submit'><span class="mono">{% trans "Search" %}</span></button>
</span>
# API
(r'^api/', include('api.urls')),
- url(r'^newsearch/', include('search.urls')),
+ url(r'^fullsearch/', include('search.urls')),
# Static files
url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve',