On 16 December 2010 08:56, marcoarreguin <marcoarreg...@gmail.com> wrote: > I'm trying to make a search engine with my database, parsing de text > that the user write in the textbox to make a list with the cleaned > words, in just one table of the DB in the fields: title, descripcion > and tags, I have something like this but I don't know how to finish > it:
You're trying to do what's called full text search (FTS), and databases out of the box are horrible at doing that (i.e. without the FTS components). You'll run into all kinds of issues trying to construct the query, and the performance will be bad. If you're using MySQL, Django can interface with its FTS component - http://docs.djangoproject.com/en/dev/ref/models/querysets/#search Otherwise, I suggest using one of the open source search engines (Solr, Whoosh, Xapian etc.) and using Haystack to connect it to Django. Whoosh is a nice, easy choice and works for sites with small amounts of traffic. http://haystacksearch.org/ > > from django.http import HttpResponse > from django.shortcuts import render_to_response > from myproject.parsing.models import Stores > from pyparsing import * > from django.db.models import Q > > def search_form(request): > return render_to_response('search_form.html') > > def search(request): > errors= [] > if 'q' in request.GET: > q = request.GET['q'] > if not q: > errors.append('Write something') > else: > qclean= parseText(q) > for Word in qclean: > Foundstores = > Stores.objects.filter(Q(name__icontains=Word) | > Q(description__icontains=Word) | Q(tags__icontains=Word)) > > #But remeber that I have more than one word, > so I need to concatenate all the querysets of each one of the words in > qclean > > return render_to_response('search_results.html', {'Found': > Foundstores, 'query': qclean}) > > return render_to_response('search_form.html', {'errors': errors}) > > > > def parseText(texto): > parser=OneOrMore(Word(alphas)) > #articles in spanish > arreglo=("de","en","la") > for articulo in arreglo: > parser.ignore(CaselessLiteral(articulo)) > salida=parser.parseString(texto) > return salida > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.