super(JQueryAutoCompleteSearchWidget, self).__init__(*args, **kwargs)
def render_js(self, field_id, options):
- return u"""
- $('#%s')
- .autocomplete($.extend({
- minLength: 0,
- select: autocomplete_result_handler,
- focus: function (ui, item) { return false; }
- }, %s))
- .data("autocomplete")._renderItem = autocomplete_format_item;
- """ % (field_id, options)
-
+ return u""
+
class JQueryAutoCompleteField(forms.CharField):
def __init__(self, source, options={}, *args, **kwargs):
class JQueryAutoCompleteSearchField(forms.CharField):
- def __init__(self, source, options={}, *args, **kwargs):
+ def __init__(self, options={}, *args, **kwargs):
if 'widget' not in kwargs:
- options['source'] = source
kwargs['widget'] = JQueryAutoCompleteSearchWidget(options)
super(JQueryAutoCompleteSearchField, self).__init__(*args, **kwargs)
class SearchForm(forms.Form):
- q = JQueryAutoCompleteSearchField('/newsearch/hint/') # {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"})
- tags = forms.CharField(widget=forms.HiddenInput, required=False)
+ q = JQueryAutoCompleteSearchField() # {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"})
- book = forms.IntegerField(widget=forms.HiddenInput, min_value=0, required=False)
-
- def __init__(self, *args, **kwargs):
- tags = kwargs.pop('tags', [])
- book = kwargs.pop('book', None)
+ def __init__(self, source, *args, **kwargs):
+ kwargs['auto_id'] = False
super(SearchForm, self).__init__(*args, **kwargs)
self.fields['q'].widget.attrs['title'] = _('title, author, theme/topic, epoch, kind, genre, phrase')
- #self.fields['q'].widget.attrs['style'] = ''
- self.fields['tags'].initial = '/'.join(tag.url_chunk for tag in Tag.get_tag_list(tags))
- if book is not None:
- self.fields['book'].initial = book.id
+ self.fields['q'].widget.attrs['autocomplete'] = _('off')
+ self.fields['q'].widget.attrs['data-source'] = _(source)
+ self.fields['q'].widget.attrs['id'] = _('search')
class UserSetsForm(forms.Form):
urlpatterns = patterns('',
url(r'^$', 'django.views.generic.simple.direct_to_template', {
'template': 'lessons/document_list.html',
- 'extra_context': {
- 'form': forms.SearchForm(),
- },
}, name='lessons_document_list'),
url(r'^(?P<slug>[a-zA-Z0-9_-]+)/$', 'lessons.views.document_detail', name='lessons_document_detail'),
--- /dev/null
+
+from catalogue.forms import SearchForm
+from django.core.urlresolvers import reverse
+
+
+def search_form(request):
+ return { 'search_form': SearchForm(reverse('search.views.hint'), request.GET) }
# remove duplicate sections
sections = {}
-
+
for s in sect:
si = s[POSITION][POSITION_INDEX]
# skip existing
if si in sections:
if sections[si]['score'] >= s[SCORE]:
continue
-
+
m = {'score': s[SCORE],
- 'header_index': s[POSITION][POSITION_INDEX]
+ 'section_number': s[POSITION][POSITION_INDEX] + 1,
}
m.update(s[OTHER])
sections[si] = m
-
+
hits = sections.values()
for f in frags:
# return None
-
def get_snippets(self, scoreDoc, query, field='content'):
"""
Returns a snippet for found scoreDoc.
import search
idx = search.ReusableIndex()
idx.open()
- for b in Book.objects.all():
+
+ if args:
+ books = []
+ for a in args:
+ books += Book.objects.filter(slug=a).all()
+ else:
+ books = Book.objects.all()
+
+ for b in books:
print b.title
idx.index_book(b, None)
print 'Reindexing tags.'
idx.index_tags()
- idx.close()
\ No newline at end of file
+ idx.close()
# 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.
-
tags = s.hint_tags(prefix)
books = s.hint_books(prefix)
for b in books])
-def foo(s, q, tag_list=None):
- hint = s.hint()
- try:
- tag_list = Tag.get_tag_list(tag_list)
- hint.tags(tag_list)
- except:
- tag_list = None
-
- q = StringReader(q)
- return (q, hint)
-
-
def main(request):
results = {}
JVM.attachCurrentThread() # where to put this?
{'tags': tag_list, 'prefix': query,
'results': results},
context_instance=RequestContext(request))
-
- # return render_to_response('newsearch/search.html', {'results': results,
- # 'did_you_mean': (query is not None) and
- # did_you_mean(query, srch.get_tokens(query, field='SIMPLE')),
- # 'fuzzy': fuzzy},
- # context_instance=RequestContext(request))
'django.core.context_processors.media',
'django.core.context_processors.request',
'wolnelektury.context_processors.extra_settings',
+ 'search.context_processors.search_form',
)
MIDDLEWARE_CLASSES = [
<form id="search-area" action="/fullsearch/">
<span id="search-field" class="grid-line">
- <input id="search" title="np. Leśmian" name="q" autocomplete="off" data-source="/fullsearch/hint/">
+ {{search_form.q}}
+<!-- <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>
{% else %}
{# it's a section #}
+ <a href="{% url book_text result.book.slug %}#f{{hit.section_number}}">{{hit.header_index}}</a>
{% if hit.snippets %}
{% for snip in hit.snippets %}
{{snip|safe}}<br/>