Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 15, 2010 21:54:52

m.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Developing a search engine


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:


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
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 15, 2010 21:56:26

m.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Developing a search engine


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:


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
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 16, 2010 01:57:12

Sam L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Developing a search engine


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/#searchOtherwise, 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
>        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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 16, 2010 02:29:50

Christophe P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Developing a search engine


On Dec 15, 2010, at 5:57 PM, Sam Lai wrote:
> If you're using MySQL, Django can interface with its FTS component -
>http://docs.djangoproject.com/en/dev/ref/models/querysets/#searchPostgreSQL also has a very good built-in full text search function. You'll
need to write a tiny bit of raw SQL, but you can use it with the new .raw()
query sets.http://www.postgresql.org/docs/9.0/interactive/textsearch.html--
-- Christophe Pettus
x...@thebuild.com

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 12th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support