made search easier
when no local results, automatically invoke google books searchpull/1/head
parent
e6eaa24440
commit
f1c74fe7da
|
@ -106,7 +106,7 @@ $j(document).ready(function() {
|
|||
loader: '<img src="/static/images/loading.gif" alt="loading..." />',
|
||||
callback: function(p) {
|
||||
page += 1;
|
||||
var url = "?q={{ q }}&page=" + page;
|
||||
var url = "?q={{ q }}&gbo={{ gbo }}&page=" + page;
|
||||
$j.get(url, function(html) {
|
||||
var view = $j(".listview").length > 0 ? "list" : "panel";
|
||||
var results = $j(html).find(".book");
|
||||
|
@ -159,8 +159,14 @@ $j(document).ready(function() {
|
|||
</div>
|
||||
{% endfor %}
|
||||
</div></div>
|
||||
{% else %}
|
||||
<div style="margin: 20px; font-size:14px">We couldn't find any matches in the Unglue.it database of free-licensed books.</div>
|
||||
{% endif %}
|
||||
{% if not results and not campaign_works %}
|
||||
<div style="margin: 20px; font-size:14px">Google Books couldn't find any matches either.</div>
|
||||
{% else %}
|
||||
<div class="content-block-heading">
|
||||
|
||||
<h2 class="content-heading"><a href="https://www.google.com/search?q={{q }}&tbm=bks">Google Books</a> search results</span></h2>
|
||||
|
||||
{% if not campaign_works %}
|
||||
|
@ -193,6 +199,7 @@ $j(document).ready(function() {
|
|||
{% endfor %}
|
||||
</div></div>
|
||||
<div id="results-bottom"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -2126,14 +2126,21 @@ def search(request):
|
|||
q = request.GET.get('q', '')
|
||||
request.session['q']=q
|
||||
page = int(request.GET.get('page', 1))
|
||||
|
||||
gbo = request.GET.get('gbo', 'n') # gbo is flag for google books only
|
||||
our_stuff = Q(is_free=True) | Q(campaigns__isnull=False )
|
||||
if q != '' and page==1:
|
||||
if q != '' and page==1 and not gbo=='y':
|
||||
work_query = Q(title__icontains=q) | Q(editions__authors__name__icontains=q) | Q(subjects__name__iexact=q)
|
||||
campaign_works = models.Work.objects.filter(our_stuff).filter(work_query).distinct()
|
||||
results = models.Work.objects.none()
|
||||
for work in campaign_works:
|
||||
results = models.Work.objects.none()
|
||||
break
|
||||
else:
|
||||
results = gluejar_search(q, user_ip=request.META['REMOTE_ADDR'], page=1)
|
||||
gbo = 'y'
|
||||
else:
|
||||
results = gluejar_search(q, user_ip=request.META['REMOTE_ADDR'], page=page-1)
|
||||
if gbo == 'n':
|
||||
page=page-1 # because page=1 is the unglue.it results
|
||||
results = gluejar_search(q, user_ip=request.META['REMOTE_ADDR'], page=page)
|
||||
campaign_works = None
|
||||
|
||||
# flag search result as on wishlist as appropriate
|
||||
|
@ -2146,6 +2153,7 @@ def search(request):
|
|||
works.append(result)
|
||||
context = {
|
||||
"q": q,
|
||||
"gbo": gbo,
|
||||
"results": works,
|
||||
"campaign_works": campaign_works
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue