kb: search as you type
This commit is contained in:
parent
cf197f50c9
commit
191c544d6b
|
@ -24,11 +24,15 @@ from .models import Page
|
|||
|
||||
class PageIndex(indexes.SearchIndex, indexes.Indexable):
|
||||
title = indexes.CharField(model_attr='title', boost=1.5)
|
||||
text = indexes.CharField(document=True, model_attr='content')
|
||||
text = indexes.CharField(document=True)
|
||||
text_auto = indexes.EdgeNgramField()
|
||||
slug = indexes.CharField(model_attr='slug', indexed=False)
|
||||
|
||||
def get_model(self):
|
||||
return Page
|
||||
|
||||
def prepare_text(self, obj):
|
||||
return HTMLParser().unescape(strip_tags(obj.content))
|
||||
return obj.title + ' ' + HTMLParser().unescape(strip_tags(obj.content))
|
||||
|
||||
def prepare_text_auto(self, obj):
|
||||
return self.prepare_text(obj)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
{% load i18n %}
|
||||
<div>
|
||||
<form class="kb-search" action="{% url 'kb-page-search-json' %}">
|
||||
<input name="q"/> <button>{% trans 'Search' %}</button>
|
||||
</form>
|
||||
<input autocomplete="off" data-autocomplete-json="{% url 'kb-page-search-json' %}" name="q"/>
|
||||
<ul class="result">
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -86,7 +86,7 @@ zone = csrf_exempt(KbZone.as_view())
|
|||
def page_search_json(request):
|
||||
query = request.GET.get('q')
|
||||
searchqueryset = SearchQuerySet()
|
||||
sqs = searchqueryset.auto_query(query)
|
||||
sqs = searchqueryset.autocomplete(text_auto=query)
|
||||
sqs.load_all()
|
||||
|
||||
result = []
|
||||
|
|
|
@ -35,11 +35,11 @@ $(function() {
|
|||
});
|
||||
return false;
|
||||
});
|
||||
$('.kb').delegate('.kb-search', 'submit', function() {
|
||||
var q = $(this).find('input').val();
|
||||
$('.kb').delegate('input', 'keyup', function() {
|
||||
var q = $(this).val();
|
||||
var search_result_ul = $(this).parent().find('ul.result');
|
||||
search_result_ul.empty();
|
||||
$.getJSON($(this).attr('action'),
|
||||
$.getJSON($(this).data('autocomplete-json'),
|
||||
{'q': q},
|
||||
function (response) {
|
||||
console.log('success!', response);
|
||||
|
|
Loading…
Reference in New Issue