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..." />',
|
loader: '<img src="/static/images/loading.gif" alt="loading..." />',
|
||||||
callback: function(p) {
|
callback: function(p) {
|
||||||
page += 1;
|
page += 1;
|
||||||
var url = "?q={{ q }}&page=" + page;
|
var url = "?q={{ q }}&gbo={{ gbo }}&page=" + page;
|
||||||
$j.get(url, function(html) {
|
$j.get(url, function(html) {
|
||||||
var view = $j(".listview").length > 0 ? "list" : "panel";
|
var view = $j(".listview").length > 0 ? "list" : "panel";
|
||||||
var results = $j(html).find(".book");
|
var results = $j(html).find(".book");
|
||||||
|
@ -159,8 +159,14 @@ $j(document).ready(function() {
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div></div>
|
</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 %}
|
{% 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">
|
<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>
|
<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 %}
|
{% if not campaign_works %}
|
||||||
|
@ -193,6 +199,7 @@ $j(document).ready(function() {
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div></div>
|
</div></div>
|
||||||
<div id="results-bottom"></div>
|
<div id="results-bottom"></div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2126,14 +2126,21 @@ def search(request):
|
||||||
q = request.GET.get('q', '')
|
q = request.GET.get('q', '')
|
||||||
request.session['q']=q
|
request.session['q']=q
|
||||||
page = int(request.GET.get('page', 1))
|
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 )
|
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)
|
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()
|
campaign_works = models.Work.objects.filter(our_stuff).filter(work_query).distinct()
|
||||||
|
for work in campaign_works:
|
||||||
results = models.Work.objects.none()
|
results = models.Work.objects.none()
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
results = gluejar_search(q, user_ip=request.META['REMOTE_ADDR'], page=page-1)
|
results = gluejar_search(q, user_ip=request.META['REMOTE_ADDR'], page=1)
|
||||||
|
gbo = 'y'
|
||||||
|
else:
|
||||||
|
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
|
campaign_works = None
|
||||||
|
|
||||||
# flag search result as on wishlist as appropriate
|
# flag search result as on wishlist as appropriate
|
||||||
|
@ -2146,6 +2153,7 @@ def search(request):
|
||||||
works.append(result)
|
works.append(result)
|
||||||
context = {
|
context = {
|
||||||
"q": q,
|
"q": q,
|
||||||
|
"gbo": gbo,
|
||||||
"results": works,
|
"results": works,
|
||||||
"campaign_works": campaign_works
|
"campaign_works": campaign_works
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue