Open GoogleCodeExporter opened 9 years ago
Original comment by daevaorn
on 22 Feb 2009 at 10:23
Original comment by daevaorn
on 4 May 2009 at 11:32
Original comment by daevaorn
on 23 May 2009 at 7:06
Original comment by daevaorn
on 19 Sep 2009 at 9:14
What are your thought about this task? I mean that the search form and the
search view are a subject
of the final project's needs even if they could be as simple as issuing a
search query and fill the
results into the Django's list_detail.object_list generiv view.
Example:
{{{
from django.views.generic.list_detail import object_list
import xapian
class SearchForm(forms.Form):
q = forms.CharField(max_length=200)
def search_view(request, queryset=EmptyQuerySet(), extra_context={}, **kwargs):
if request.method == 'GET':
form = SearchForm(data=request.GET.copy())
if form.is_valid():
q = form.cleaned_data['q'].strip()
indexers = [Product.indexer, Client.indexer]
indexer = CompositeIndexer(*indexers)
# make a call for a possible spell correction of the search query by the full-text search
system
results = indexer.search(q).spell_correction()
corrected_query = results.get_corrected_query_string()
queryset = results.prefetch()
# prepare a list of normalized search terms to be used for highlighting
results._query_parser.set_stemming_strategy(xapian.QueryParser.STEM_ALL)
search_terms = list(results._query_parser.parse_query(results._query_str))
extra_context.update({'corrected_query': corrected_query,
'search_terms': search_terms,
'q': q,
})
else:
form = SearchForm()
return object_list(request, queryset,
extra_context=extra_context,
page=request.GET.get('p', None),
**kwargs)
}}}
However, this stemmed search terms for highlighting the search results trick
could be worth creating
a special decoration over the django.views.generic.list_detail.object_list ...
Original comment by esizi...@gmail.com
on 16 Feb 2010 at 9:56
Original issue reported on code.google.com by
daevaorn
on 22 Feb 2009 at 10:23