Exemplo n.º 1
0
    def read(self, request):
        print "REST service: read"

        q = request.GET.get('query')
        profile = request.GET.get('profile')

        if (q == None):
            #none to search
            print "Blank search"
            xmldata = '<searchresponse><error>Blank search</error></searchresponse>'
            responseXML = HttpResponse(xmldata,
                                       mimetype='text/xml',
                                       content_type='text/xml;charset=UTF-8')
            return responseXML

        if (profile != None):
            print "Profile", profile
            # at this moment, we only admit a default profile

        print q
        q = q.strip(' ')
        q = q.strip('%20')
        #q = django.utils.http.urlquote(q)
        print q

        # I see 2 alternatives for the future, with profiles
        #   1st to move this to several independent python files, for loading it
        #       dinamicaly (like filters)
        #   2nd XML files describing the filters and parameters. It is slower, but
        #       new filters can be added by a REST interface
        service = Service()
        # set up services

        service.add_query_filter(TermExpansionFilter("--terms=for+kids"))
        service.add_query_filter(TermExpansionFilter("--terms=colouring+book"))

        service.add_search_suggestion(SuggestionFilter())
        #service.add_search_engine(SearchEngine('Pathfinder'))
        service.add_search_engine(SearchEngine('Yahoo'))

        query = Query(q)

        response = service.search(query)

        xmldata = responseToXML(response)

        responseXML = HttpResponse(xmldata,
                                   mimetype='text/xml',
                                   content_type='text/xml;charset=UTF-8')
        return responseXML
Exemplo n.º 2
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

from puppy.service import Service
from puppy.search import SearchEngine
from puppy.query.filter import TermExpansionFilter
from puppy.query.filter import BlackListFilter
from puppy.query.filter import TestEqualFilter

from puppy.model import Query

service = Service()

black_list_query = "--terms=+book"

service.add_query_filter(TermExpansionFilter("--terms=for+kids"))
service.add_query_filter(TestEqualFilter("--terms=for+kids+elmo"))
service.add_query_filter(TermExpansionFilter("--terms=colouring+book"))
service.add_query_filter(
    TestEqualFilter("--terms=for+kids+elmo+colouring+book"))
service.add_query_filter(BlackListFilter("--terms=+book"))

# This line fails, book is not longer in  the query list
#service.add_query_filter(TestEqualFilter("--terms=for+kids+elmo+colouring+book"))

service.add_search_engine(SearchEngine('Yahoo'))

query = Query('elmo')
service.search(query)
Exemplo n.º 3
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

from puppy.service import Service
from puppy.search import SearchEngine
from puppy.query.filter import TermExpansionFilter
from puppy.result.filter import BlackListResultFilter
from puppy.result.filter import ExclusionFilter
from puppy.model import Query


service = Service()

black_list_result = "--terms=verybadword"
exclusion_list_result = "--terms=badword"


service.add_search_engine(SearchEngine('EchoSearch'))

service.add_result_filter(ExclusionFilter(exclusion_list_result))

service.add_result_filter(BlackListResultFilter(black_list_result))


query = Query('elmo badword verybadword')
service.search(query)