def __init__(self, service, source = 'Web', resultsPerPage = 10, **args): """ Args: source - should be 'Web', 'Image', 'News', 'RelatedSearch', 'SpellingSuggestions' """ SearchEngine.__init__(self, service, **args) self.source = source self.resultsPerPage = resultsPerPage
def __init__(self, service, source = 'Web', adult = 'Strict', market = 'en-US', resultsPerPage = 8, filters = None, sortBy = None, newsCategory = None, sites=None, **args): """ Arguments for all source types: (1) source(str) - Should be 'Web', 'Image', 'News', 'RelatedSearch', 'SpellingSuggestions' (2) adult(str) - Strict is the default, not recommended to change this, can also be 'Moderate' or 'Off' (3) market(str) - For UK: en-GB, For Netherlands: nl-NL etc (4) resultsPerPage(int) - How many results per page Arguments for Image and Video searches only: (1) filters(str) - Filter options split up by '+' you can only have one of each type see Bing API documentation for examples of the valid filters. Example: "Style:Photo+Aspect:Tall'" gets tall photos. Arguments for Video and News searches only: (1) sortBy(str) - You can select to sort by either 'Date' or 'Relevance' Arguments for News searches only: (1) newsCategory(str) - What sort of news is wanted, see BingAPI for list of options, for example: 'rt_ScienceAndTechnology' to find news under this category. Only available with the en-US market, 'cause the rest of the world do not like categories. """ SearchEngine.__init__(self, service, **args) # This will also handle any unsupported parameters # The search sources have different limits sources_to_limits = {"Image" : 50, "Web" : 50, "News" : 15, "RelatedSearch" : 50, "Video" : 50, "SpellingSuggestions" : 50} self.engineName = "Bing V3_json" # Used for error identification # If there is not entry in the sources dictionary with their limits raise an Error if source in sources_to_limits: self.source = source else: raise SearchEngineError(self.engineName, "Invalid source type: %s is not supported" % source) # For some reason Spelling Suggestions (named wrongly in their documentation) is only available as Atom if self.source != "SpellingSuggestions": self.format = "json" else: self.format = "atom" # Quick bit of validation, if greater than the sources limit or 0 or less use a default if resultsPerPage > sources_to_limits[source] or resultsPerPage <= 0: self.resultsPerPage = 8 else: self.resultsPerPage = resultsPerPage self.adult = adult self.market = market self.filters = filters self.sortBy = sortBy self.newsCategory = newsCategory self.sites = sites
def __init__(self, service, source = 'web', adult = 'Strict', market = 'en-GB', resultsPerPage = 10, lat = None, lon = None, radius = 5, sites=None, **args): SearchEngine.__init__(self, service, **args) sitesearch.__init__(self, sites) self.sites = sites self.source = source self.adult = adult self.market = market self.resultsPerPage = resultsPerPage self.lat = lat self.lon = lon self.radius = radius
def __init__(self, service, source = 'Web', adult = 'Strict', market = 'en-GB', resultsPerPage = 8, filters = None, sortBy = None, newsCategory = None, sites=None, **args): SearchEngine.__init__(self, service, **args) sitesearch.__init__(self, sites) self.source = source self.adult = adult self.market = market self.resultsPerPage = resultsPerPage self.filters = filters self.sortBy = sortBy self.newsCategory = newsCategory
def __init__(self, service, resultsPerPage = 8, order=None, tags=None, filter=None, genres=None, types=None, bpmFilter=None, durationFilter=None, createdFilter=None, **args): SearchEngine.__init__(self, service, **args) self.resultsPerPage = resultsPerPage self.order = order self.tags = tags self.filter = filter self.genres = genres self.types = types self.bpmFilter = bpmFilter self.durationFilter = durationFilter self.createdFilter = createdFilter
def __init__(self, service, source='web', adult='Strict', market='en-GB', resultsPerPage=10, lat=None, lon=None, radius=5, sites=None, **args): SearchEngine.__init__(self, service, **args) sitesearch.__init__(self, sites) self.sites = sites self.source = source self.adult = adult self.market = market self.resultsPerPage = resultsPerPage self.lat = lat self.lon = lon self.radius = radius
def __init__(self, service, source='Web', adult='Strict', market='en-GB', resultsPerPage=8, filters=None, sortBy=None, newsCategory=None, sites=None, **args): SearchEngine.__init__(self, service, **args) sitesearch.__init__(self, sites) self.source = source self.adult = adult self.market = market self.resultsPerPage = resultsPerPage self.filters = filters self.sortBy = sortBy self.newsCategory = newsCategory
def __init__(self, service, resultsPerPage=8, order=None, tags=None, filter=None, genres=None, types=None, bpmFilter=None, durationFilter=None, createdFilter=None, **args): SearchEngine.__init__(self, service, **args) self.resultsPerPage = resultsPerPage self.order = order self.tags = tags self.filter = filter self.genres = genres self.types = types self.bpmFilter = bpmFilter self.durationFilter = durationFilter self.createdFilter = createdFilter
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
def __init__(self, service, source = 'Definitions', resultsPerPage = 8, sourceDictionaries = None, **args): SearchEngine.__init__(self, service, **args) self.source = source self.resultsPerPage = resultsPerPage self.sourceDictionaries = sourceDictionaries
#!/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)
def __init__(self, service, source='web', resultsPerPage=10, **args): SearchEngine.__init__(self, service, **args) self.source = source self.resultsPerPage = resultsPerPage
#!/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)
def __init__(self, service, source = 'web', resultsPerPage = 10, **args): SearchEngine.__init__(self, service, **args) self.source = source self.resultsPerPage = resultsPerPage
def __init__(self, service, source='Web', adult='Strict', market='en-US', resultsPerPage=8, filters=None, sortBy=None, newsCategory=None, sites=None, **args): """ Arguments for all source types: (1) source(str) - Should be 'Web', 'Image', 'News', 'RelatedSearch', 'SpellingSuggestions' (2) adult(str) - Strict is the default, not recommended to change this, can also be 'Moderate' or 'Off' (3) market(str) - For UK: en-GB, For Netherlands: nl-NL etc (4) resultsPerPage(int) - How many results per page Arguments for Image and Video searches only: (1) filters(str) - Filter options split up by '+' you can only have one of each type see Bing API documentation for examples of the valid filters. Example: "Style:Photo+Aspect:Tall'" gets tall photos. Arguments for Video and News searches only: (1) sortBy(str) - You can select to sort by either 'Date' or 'Relevance' Arguments for News searches only: (1) newsCategory(str) - What sort of news is wanted, see BingAPI for list of options, for example: 'rt_ScienceAndTechnology' to find news under this category. Only available with the en-US market, 'cause the rest of the world do not like categories. """ SearchEngine.__init__( self, service, **args) # This will also handle any unsupported parameters # The search sources have different limits sources_to_limits = { "Image": 50, "Web": 50, "News": 15, "RelatedSearch": 50, "Video": 50, "SpellingSuggestions": 50 } self.engineName = "Bing V3_json" # Used for error identification # If there is not entry in the sources dictionary with their limits raise an Error if source in sources_to_limits: self.source = source else: raise SearchEngineError( self.engineName, "Invalid source type: %s is not supported" % source) # For some reason Spelling Suggestions (named wrongly in their documentation) is only available as Atom if self.source != "SpellingSuggestions": self.format = "json" else: self.format = "atom" # Quick bit of validation, if greater than the sources limit or 0 or less use a default if resultsPerPage > sources_to_limits[source] or resultsPerPage <= 0: self.resultsPerPage = 8 else: self.resultsPerPage = resultsPerPage self.adult = adult self.market = market self.filters = filters self.sortBy = sortBy self.newsCategory = newsCategory self.sites = sites