def category(request): # Create a context dictionary which we can pass to the template rendering engine. context_dict = {} context_dict['result_list']=None context_dict['query']=None if request.method == 'POST': query = request.POST['query'].strip() if query: # Run our Bing function to get the results list! result_list = run_query(query) context_dict['result_list'] = run_query(query) context_dict['result_list'] = result_list context_dict['query'] = query try: # Can we find a category name slug with the given name? # If we can't, the .get() method raises a DoesNotExist exception. # So the .get() method returns one model instance or raises an exception. category_name_url = category.slug category_name = decode_url(category_name_url) context_dict['category_name'] = category_name context_dict['category_name_url'] = category_name_url # Retrieve all of the associated pages. # Note that filter returns >= 1 model instance. pages = Page.objects.filter(category=category) pages = Page.objects.filter(category=category).order_by('-views') # Adds our results list to the template context under name pages. context_dict['pages'] = pages # We also add the category object from the database to the context dictionary. # We'll use this in the template to verify that the category exists. context_dict['category'] = category except Category.DoesNotExist: # We get here if we didn't find the specified category. # Don't do anything - the template displays the "no category" message for us. pass if not context_dict['query']: context_dict['query'] = category.name return render(request, 'rango/category.html', context_dict)
def category(request, cat_name_slug): context_dict = {} context_dict['result_list'] = None context_dict['query'] = None catlist = Category.objects.order_by('views') context_dict['categories'] = catlist if request.method == "POST": query = request.POST['query'].strip() if query: #run bing function to get the result list result_list = run_query(query) context_dict['result_list'] = result_list context_dict['query'] = query try: category = Category.objects.get(slug=cat_name_slug) category.views += 1 category.save() #将所有的元素放在一个字典中 context_dict['category_name'] = category.name pages = Page.objects.filter(category=category) context_dict['pages'] = pages context_dict['category'] = category context_dict['category_name_slug'] = cat_name_slug except: pass if not context_dict['query']: context_dict['query'] = category.name return render(request, 'rango/category.html', context_dict)
def category(request, category_name_slug): context_dict = {} context_dict['result_list'] = None context_dict['query'] = None if request.method == 'POST': query = request.POST['query'].strip() if query: # Run our Bing function to get the results list! result_list = run_query(query) context_dict['result_list'] = result_list context_dict['query'] = query try: category = Category.objects.get(slug=category_name_slug) context_dict['category_name'] = category.name pages = Page.objects.filter(category=category).order_by('-views') context_dict['pages'] = pages context_dict['category'] = category except Category.DoesNotExist: pass if not context_dict['query']: context_dict['query'] = category.name return render(request, 'rango/category.html', context_dict)
def search(request): result_list = [] if request.method == 'POST': query = request.POST['query'].strip() if query: result_list = run_query(query) return render(request, 'rango/search.html', {'result_list': result_list})
def category(request, category_name_url): context = RequestContext(request) category_name = decode_url(category_name_url) category_list = get_category_list() context_dict = {'category_name': category_name, 'category_name_url': category_name_url, 'categories': category_list, } try: cat = Category.objects.get(name__iexact=category_name) pages = Page.objects.filter(category=cat).order_by('-views') context_dict['pages'] = pages context_dict['category'] = cat except Category.DoesNotExist: pass if request.method == 'POST': try: query = request.POST['query'].strip() if query: result_list = run_query(query) context_dict['result_list'] = result_list except Exception: pass return render_to_response('rango/category.html', context_dict, context)
def category(request, category_name_url): context = RequestContext(request) cat_list = get_category_list() category_name = decode_url(category_name_url) context_dict = { 'cat_list': cat_list, 'category_name': category_name, 'category_name_url': category_name_url } try: category = Category.objects.get(name=category_name) # Add category to the context so that we can access the id and likes context_dict['category'] = category pages = Page.objects.filter(category=category) context_dict['pages'] = pages except Category.DoesNotExist: pass if request.method == "POST": query = request.POST['query'].strip() if query: result_list = run_query(query) context_dict['result_list'] = result_list return render_to_response('myApp/category.html', context_dict, context)
def search(request): context = RequestContext(request) context_dict = {} if request.method=="POST": search_terms = request.POST['query'] if(search_terms): context_dict['result_list'] = bing_search.run_query(search_terms) return render_to_response('rango/search.html', context_dict, context)
def category(request, category_name_url): # Request our context from the request passed to us. # context = ContextRequest(request) context = RequestContext(request) # Change underscores in the category name to spaces. # URLs don't handle spaces well, so we encode them as underscores. # We can then simply replace the underscores with spaces again to get the name. # category_name = category_name_url.replace('_', ' ') category_name = decode_url(category_name_url) cat_list = get_category_list() result_list = [] if request.method == 'POST': query = request.POST['query'].strip() if query: # Run our Bing function to get the results list! result_list = run_query(query) # Create a context dictionary which we can pass to the template rendering engine. # We start by containing the name of the category passed by the user. # context_dict = {'pages': page_list} # context_dict = {'category_name': category_name} context_dict = { 'category_name': category_name, 'category_name_url': category_name_url, 'cat_list': cat_list, 'result_list': result_list } try: # Can we find a category with the given name? # If we can't, the .get() method raises a DoesNotExist exception. # So the .get() method returns one model instance or raises an exception. # category = Category.objects.get(category_name) category = Category.objects.get(name=category_name) # Retrieve all of the associated pages. # Note that filter returns >=1 model instance. # page = Category.ojbects.filter(category = category) pages = Page.objects.filter(category=category) # Add our results list to the template context under name pages. # context_dict['page'] = pages context_dict['pages'] = pages # We also add the category object from the database to the context dictionary # We'll use this in the template to verify that the category exists. context_dict['category'] = category except Category.DoesNotExist: # We get here if we didn't find the spcified category. # Don't do anything - the template displays the "no category " message for us. pass # Go render the response and return it to the client. return render_to_response('myApp/category.html', context_dict, context)
def search(request): result_list = [] context_dict = {} if request.method == 'POST': query = request.POST['query'] if query: result_list = run_query(query) context_dict['result_list'] = result_list return render(request, 'rango/search.html', context_dict)
def search(request): context = RequestContext(request) context_dict = {} if request.method=="POST": query = request.POST["query"].strip() if query: result_list = run_query(query) context_dict["result_list"] = result_list return render_to_response("rango/search.html", context_dict, context)
def search(request): context = RequestContext(request) categories = get_category_list() result_list = [] if request.method == "POST": query = request.POST['query'].strip() if query: result_list = run_query(query) print result_list return render_to_response('rango/search.html', dict(result_list=result_list, categories=categories), context)
def search(request): result_list = [] if request.method == 'POST': query = request.POST['query'].strip() if query: # Run our Bing function to get the results list! result_list = run_query(query) return render(request, 'rango/search.html', {'result_list': result_list})
def search(request): context = RequestContext(request) result_list = [] if request.method == 'POST': query = request.POST['query'].strip() if query: result_list = run_query(query) return render_to_response('rango/search.html', {'cat_list': get_category_list(), 'result_list': result_list}, context)
def main(argv): for query in argv: print "Searching for {0}".format(query) results = run_query(query) i = 1 for result in results: print "({0}) - {1} - {2}".format( i, result['title'], result['link'] ) i = i + 1
def testBingNews(self): rpp = 15 source = "news" query = "google" results = bing_search.run_query(query, source, rpp) counter = 0 for x in results: print counter counter += 1 self.assertEquals((counter == 15), True) print results
def search(request): context = RequestContext(request) result_list = [] if request.method == 'POST': query = request.POST['query'].strip() if query: # Run our Bing function to get the results list! result_list = run_query(query) return render_to_response('rango/search.html', {'result_list': result_list}, context)
def simpleSearch(request, context_dict): if request.method == "GET": query = request.GET['q'].strip() else: query = request.POST['query'].strip() rpp = 10; source = "web" result_list = run_query(query, source, rpp) context_dict["everythingElse"] = result_list context_dict["query"] = query return context_dict
def search(request): results_from_bing = [] results_from_healthgov = [] results_from_medline = [] context_dict = {} results_mashup = [] categories = Category.objects.filter(user=request.user) public_categories = Category.objects.filter(shared=True) query = None age = None gender = "male" display = True if request.method == 'POST': checked_box = request.POST.get('search-target', None) query = request.POST['query'].strip() # search for me if checked_box == "on": age = UserProfile.objects.get(user=request.user).age gender = UserProfile.objects.get(user=request.user).gender display = True else: age = request.POST['age'] gender = request.POST['gender'] display = False if query and age and gender: # Run our Bing function to get the results list! results_from_bing = bing_search.run_query(query) results_from_healthgov = healthfinder_search.run_query( query, age, gender) results_from_medline = medlinePlus.run_query(query) results_mashup = merge_by_relevance.merge(results_from_bing, results_from_medline, results_from_healthgov) context_dict['query'] = query context_dict['age'] = age context_dict['gender'] = gender context_dict['results_from_bing'] = results_from_bing context_dict['results_from_healthgov'] = results_from_healthgov context_dict['results_from_medline'] = results_from_medline context_dict['categories'] = categories context_dict['public_categories'] = public_categories context_dict['results_mashup'] = results_mashup context_dict['display'] = display return render(request, 'fhs/search.html', context_dict)
def show_category(request, category_name_slug): # Create a context dictionary which we can pass # to the template rendering engine. context_dict = {} try: # Can we find a category name slug with the given name? # If we can't, the .get() method raises a DoesNotExist exception. # So the .get() method returns one model instance or raises an exception. category = Category.objects.get(slug=category_name_slug) # Retrieve all of the associated pages. # Note that filter() will return a list of page objects or an empty list pages = Page.objects.filter(category=category).order_by('-views') # Adds our results list to the template context under name pages. context_dict['pages'] = pages # We also add the category object from # the database to the context dictionary. # We'll use this in the template to verify that the category exists. context_dict['category'] = category except Category.DoesNotExist: # We get here if we didn't find the specified category. # Don't do anything - # the template will display the "no category" message for us. context_dict['pages'] = None context_dict['category'] = None # New code added here to handle a POST request # create a default query based on the category name # to be shown in the search box context_dict['query'] = category.name result_list = [] if request.method == 'POST': query = request.POST['query'].strip() if query: # Run our Bing function to get the results list! result_list = run_query(query) context_dict['query'] = query context_dict['result_list'] = result_list # Go render the response and return it to the client. return render(request, 'rango/category.html', context_dict)
def search(request): results_from_bing = [] results_from_healthgov = [] results_from_medline = [] context_dict = {} results_mashup = [] categories = Category.objects.filter(user=request.user) public_categories = Category.objects.filter(shared=True) query = None age = None gender = "male" display = True if request.method == 'POST': checked_box = request.POST.get('search-target', None) query = request.POST['query'].strip() # search for me if checked_box == "on": age = UserProfile.objects.get(user = request.user).age gender = UserProfile.objects.get(user = request.user).gender display=True else: age = request.POST['age'] gender = request.POST['gender'] display=False if query and age and gender: # Run our Bing function to get the results list! results_from_bing = bing_search.run_query(query) results_from_healthgov = healthfinder_search.run_query(query, age, gender) results_from_medline = medlinePlus.run_query(query) results_mashup = merge_by_relevance.merge(results_from_bing, results_from_medline, results_from_healthgov) context_dict['query'] = query context_dict['age'] = age context_dict['gender'] = gender context_dict['results_from_bing'] = results_from_bing context_dict['results_from_healthgov'] = results_from_healthgov context_dict['results_from_medline'] = results_from_medline context_dict['categories'] = categories context_dict['public_categories'] = public_categories context_dict['results_mashup'] = results_mashup context_dict['display'] = display return render(request, 'fhs/search.html', context_dict)
def searchCustomTab(request): context_dict = views.getBaseTemplateData(request) dom = request.POST["dom"] query = request.POST["query"] source = "web" rpp = 10 env, created = Environment.objects.get_or_create(user=request.user, name="Global") whitelist = ListEntry.objects.filter(user=request.user, white=True, environment=env, domain=dom) nQuery = query + " site:" + dom r = run_query(nQuery, source, rpp) context_dict["query"] = query context_dict['t'] = r return render_to_response('searchdemon/customtab.html', context_dict, context_instance=RequestContext(request))
def testBingImage(self): rpp = 10 source = "image" query = "google" results = bing_search.run_query(query, source, rpp) counter = 0 for x in results: print x if ( x["contentType"] == u"image/jpg" or x["contentType"] == u"image/png" or x["contentType"] == u"image/gif" or x["contentType"] == u"image/jpeg" ): counter += 1 print "image" print counter self.assertEquals((counter == 10), True) print results
def search(request): context = RequestContext(request) # context_dict = [] result_list = [] if request.method == 'POST': query = request.POST['query'].strip() if query: # Run our Bing function to get the results list! result_list = run_query(query) # result_list['result_list'] = result_list # context_dict = {'result_list': result_list} cat_list = get_category_list() # result_list['cat_list'] = cat_list context_dict = {'result_list': result_list, 'cat_list': cat_list} # return render_to_response('myApp/search.html', {'result_list': result_list}, context) return render_to_response('myApp/search.html', context_dict, context)
def category(request, category_name_url): context = RequestContext(request) category_name = decode_url(category_name_url) context_dict = {'category_name' : category_name, 'category_name_url' : category_name_url} if request.method=="POST": search_terms = request.POST['query'] if(search_terms): context_dict['result_list'] = bing_search.run_query(search_terms) context_dict['categories'] = load_categories() try: category = Category.objects.get(name=category_name) context_dict['category'] = category pages = Page.objects.filter(category=category) context_dict['pages'] = pages context_dict['category']=category except Category.DoesNotExist: pass return render_to_response('rango/category.html', context_dict, context)
def show_category(request, category_name_slug): context_dict = {} query = None try: category = Category.objects.get(slug=category_name_slug) pages = Page.objects.filter(category=category) context_dict['pages'] = pages context_dict['category'] = category except Category.DoesNotExist: context_dict['category'] = None context_dict['pages'] = None result_list = [] if request.method == 'POST': query = request.POST['query'].strip() if query: result_list = run_query(query) context_dict['result_list'] = result_list return render(request, 'Rango/category.html', context_dict) return render(request, 'Rango/category.html', context_dict)
def category(request, category_name_url): context = RequestContext(request) category_name = decode_category_url(category_name_url) context_dict = {'cat_list': get_category_list(), 'category_name': category_name, 'category_name_url': category_name_url} try: category = Category.objects.get(name=category_name) pages = Page.objects.filter(category=category) context_dict['pages'] = pages context_dict['category'] = category except Category.DoesNotExist: pass else: if request.method == 'POST': query = request.POST['query'].strip() context_dict['result_list'] = run_query(query) context_dict['search_value'] = query else: context_dict['search_value'] = category_name return render_to_response('rango/category.html', context_dict, context)
def category(request, category_name_slug): context_dict = {} result_list = [] if request.method == 'POST': query = request.POST['query'].strip() if query: result_list = run_query(query) if result_list: context_dict['result_list'] = result_list try: category = Category.objects.get(slug=category_name_slug) context_dict['category_name'] = category.name view_time = category.views + 1 context_dict['views'] = view_time pages = Page.objects.filter(category=category).order_by('-views') context_dict['pages'] = pages context_dict['category'] = category context_dict['category_name_slug'] = category_name_slug except Category.DoesNotExist: raise Http404("Category does not exist") return render(request, 'rango/category.html', context_dict)
def category(request, category_name_slug): context_dict = {} context_dict['result_list'] = None context_dict['query'] = None if request.method == 'POST': query = request.POST['query'].strip() if query: result_list = run_query(query) context_dict['result_list'] = result_list context_dict['query'] = query c = get_object_or_404(Category, slug=category_name_slug) context_dict['category_name'] = c.name pages = Page.objects.filter(category=c).order_by('-views') context_dict['pages'] = pages context_dict['category'] = c context_dict['category_name_slug'] = c.slug if not context_dict['query']: context_dict['query'] = c.name return render(request, 'rango/category.html', context_dict)
def category(request, category_name_slug): context_dict = {} result_list = [] context_dict['query'] = None if request.method == 'POST': query = request.POST['query'] if query: result_list = run_query(query) context_dict['query'] = query context_dict['result_list'] = result_list category = get_object_or_404(Category, slug=category_name_slug) if not context_dict['query']: context_dict['query'] = category.name context_dict['category'] = category context_dict['category_name'] = category.name # Find all of the associated pages. # Note that filter returns >= 1 model instance. pages = Page.objects.filter(category=category).order_by('-views') context_dict['pages'] = pages # Contains several references context_dict['slug'] = category_name_slug context_dict['request'] = request return render(request, 'rango/category.html', context_dict)
def searchFunction(request, context_dict): resultCache = get_cache('default') if request.method == "POST": source = request.POST['source'] query = request.POST['query'].strip() repoid = request.POST['activeRepo'] repo = Repository.objects.get(id=repoid) elif request.method == "GET": #request is a GET in cases where the user has set SearchDemon to be their default search engine in Chrome/Firefox etc source = "web" query = request.GET['q'].strip() repo = context_dict["activeRepo"]["repo"] ignoreBlacklist = False ignoreEnviroment = False rpp = 10 specificRepo = False envTerm = True pat = re.compile("-([0-9]+)") pat2 = re.compile("-r(.+)") if pat.match("60") is not None: print pat.match("60").group(1) else: print "NOT MATCHED" words = query.split(" ") term = [] for g in words: print g print "hack2" if g == "-bloff": ignoreBlacklist = True elif g == "-envoff": ignoreEnviroment = True elif pat.match(g) is not None: print "MATCHED" rpp = int(pat.match(g).group(1)) elif pat2.match(g) is not None: print "MATCHED" rname = pat2.match(g).group(1) repo = Repository.objects.filter(users=request.user, name=rname)[0] #elif g.lower == repo.language.lower: #envTerm = False else: term.append(g) query = " ".join(term) ptest = Page.objects.filter(user=request.user, commit__repository=repo, query=query) context_dict["past"] = ptest if (Commit.objects.filter(repository=repo).count() == 0): commit, created = Commit.objects.get_or_create(repository=repo, sha="firstCommit", message="Joining SearchDemon commit!", date=repo.last_modified) else: commit = Commit.objects.filter(repository=repo).order_by('-date')[0] chit = resultCache.get(query.replace(" ", "")) env, created = Environment.objects.get_or_create(user=request.user, name="Global") whitelist = ListEntry.objects.filter(user=request.user, white=True, environment=env) blacklist = ListEntry.objects.filter(user=request.user, white=False, environment=env) nquery = "" nquery = nquery + query for entry in blacklist: nquery = nquery + " -site:" + entry.domain for entry in whitelist: nquery = nquery + " -site:" + entry.domain if query: if chit != None: result_list = chit else: result_list = run_query(nquery, source, rpp) resultCache.set(query.replace(" ", ""), result_list, 60) stackoverflow_list = stackoverflowSearch(query) newstacklist = [] c = 0 for x in stackoverflow_list: pageNum = c / 5 newstacklist.append({"fromStack": x, "page": pageNum}) c = c + 1 context_dict['stack'] = newstacklist p, creat = GithubSearchResult.objects.get_or_create(commit=commit, title=query, user=request.user, source=source, url="what") if creat == False: p.searches = p.searches + 1 p.save() everythingElse = [] for r in result_list: placed = False o = urlparse(r["link"]) r["domain"] = o[0] + "://" + o[1] if placed == False: everythingElse.append(r) newP = [] for x in whitelist: if x.domain.startswith("http://"): n = x.domain[7::] elif x.domain.startswith("https://"): n = x.domain[8::] else: n = x.domain newP.append({"name": x.title, "domain": x.domain}) latestQueries = GithubSearchResult.objects.filter(commit__repository=repo, user=request.user).order_by('-modified')[:5] latestClicks = Page.objects.filter(commit__repository=repo, user=request.user).order_by('-modified')[:5] context_dict["latestRepoStuff"] = {"queries": latestQueries, "clicks": latestClicks} context_dict['preferred'] = newP context_dict['everythingElse'] = everythingElse context_dict["query"] = query context_dict['source'] = source context_dict['result_list'] = result_list activeRepo = {"repo": repo, "icon": views.envIcons[repo.environment.name]} context_dict['activeRepo'] = activeRepo return context_dict