Skip to content

Commit

Permalink
Merge pull request #327 from internetarchive/search-inside
Browse files Browse the repository at this point in the history
Add "Search inside" link above global search form
  • Loading branch information
mekarpeles authored Oct 3, 2016
2 parents e874771 + de778e9 commit 7418261
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 68 deletions.
5 changes: 4 additions & 1 deletion openlibrary/core/lending.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def get_loan(identifier, user_key=None):
if loan.is_expired():
loan.delete()
return
return _get_ia_loan(identifier, user_key and userkey2userid(user_key))
try:
return _get_ia_loan(identifier, user_key and userkey2userid(user_key))
except Exception as e:
return

def _get_ia_loan(identifier, userid):
ia_loan = ia_lending_api.get_loan(identifier, userid)
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ msgid "Hide options"
msgstr ""

#: templates/lib/search_foot.html:59 templates/lib/search_head.html:43
msgid "More options"
msgid "More search options"
msgstr ""

#: templates/lib/site_legal.html:5
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/i18n/te/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ msgid "Hide options"
msgstr ""

#: templates/lib/search_foot.html:59 templates/lib/search_head.html:43
msgid "More options"
msgid "More search options"
msgstr "మరిన్ని శోధనావిధానాలు"

#: templates/lib/site_legal.html:5
Expand Down
51 changes: 26 additions & 25 deletions openlibrary/plugins/openlibrary/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

class home(delegate.page):
path = "/"

def is_enabled(self):
return "lending_v2" in web.ctx.features

def GET(self):
try:
if 'counts_db' in config.admin:
Expand All @@ -31,11 +31,11 @@ def GET(self):
logger.error("Error in getting stats", exc_info=True)
stats = None
blog_posts = get_blog_feeds()

lending_list = config.get("home", {}).get("lending_list")
returncart_list = config.get("home", {}).get("returncart_list")
return render_template("home/index",

return render_template("home/index",
stats=stats,
blog_posts=blog_posts,
lending_list=lending_list,
Expand All @@ -44,14 +44,14 @@ def GET(self):
@public
def carousel_from_list(key, randomize=False, limit=60):
id = key.split("/")[-1] + "_carousel"

data = format_list_editions(key)
if randomize:
random.shuffle(data)
data = data[:limit]
add_checkedout_status(data)
return render_template("books/carousel", storify(data), id=id)

def add_checkedout_status(books):
"""OBSOLETE -- will be deleted.
"""
Expand All @@ -75,7 +75,7 @@ def render_returncart(limit=60, randomize=True):
# Remove all inlibrary books if we not in a participating library
if not inlibrary.get_library():
data = [d for d in data if 'inlibrary_borrow_url' not in d]

if randomize:
random.shuffle(data)
data = data[:limit]
Expand All @@ -84,18 +84,19 @@ def render_returncart(limit=60, randomize=True):
def get_returncart(limit):
if 'env' not in web.ctx:
delegate.fakeload()

items = web.ctx.site.store.items(type='ebook', name='borrowed', value='false', limit=limit)
identifiers = [doc['identifier'] for k, doc in items if 'identifier' in doc]
keys = web.ctx.site.things({"type": "/type/edition", "ocaid": identifiers})
books = web.ctx.site.get_many(keys)
return [format_book_data(book) for book in books if book.type.key == '/type/edition']

# cache the results of get_returncart in memcache for 60 sec
get_returncart = cache.memcache_memoize(get_returncart, "home.get_returncart", timeout=60)

@public
def readonline_carousel(id="read-carousel"):
"""Return template code for books pulled from search engine. TODO: If probs, use stock list."""
try:
data = random_ebooks()
if len(data) > 120:
Expand All @@ -104,13 +105,13 @@ def readonline_carousel(id="read-carousel"):
except Exception:
logger.error("Failed to compute data for readonline_carousel", exc_info=True)
return None

def random_ebooks(limit=2000):
solr = search.get_works_solr()
sort = "edition_count desc"
result = solr.select(
query='has_fulltext:true -public_scan_b:false',
rows=limit,
query='has_fulltext:true -public_scan_b:false',
rows=limit,
sort=sort,
fields=[
'has_fulltext',
Expand All @@ -131,16 +132,16 @@ def process_doc(doc):

d['url'] = key
d['title'] = doc.get('title', '')

if 'author_key' in doc and 'author_name' in doc:
d['authors'] = [{"key": key, "name": name} for key, name in zip(doc['author_key'], doc['author_name'])]

if 'cover_edition_key' in doc:
d['cover_url'] = h.get_coverstore_url() + "/b/olid/%s-M.jpg" % doc['cover_edition_key']

d['read_url'] = "//archive.org/stream/" + doc['ia'][0]
return d

return [process_doc(doc) for doc in result['docs'] if doc.get('ia')]

# cache the results of random_ebooks in memcache for 15 minutes
Expand All @@ -151,15 +152,15 @@ def format_list_editions(key):
"""
if 'env' not in web.ctx:
delegate.fakeload()

list = web.ctx.site.get(key)
if not list:
return []

editions = {}
for seed in list.seeds:
if not isinstance(seed, basestring):
if seed.type.key == "/type/edition":
if seed.type.key == "/type/edition":
editions[seed.key] = seed
else:
try:
Expand All @@ -168,7 +169,7 @@ def format_list_editions(key):
continue
editions[e.key] = e
return [format_book_data(e) for e in editions.values()]

# cache the results of format_list_editions in memcache for 5 minutes
format_list_editions = cache.memcache_memoize(format_list_editions, "home.format_list_editions", timeout=5*60)

Expand All @@ -180,10 +181,10 @@ def format_book_data(book):
d.key = book.key
d.url = book.url()
d.title = book.title or None

def get_authors(doc):
return [web.storage(key=a.key, name=a.name or None) for a in doc.get_authors()]

work = book.works and book.works[0]
if work:
d.authors = get_authors(work)
Expand All @@ -193,7 +194,7 @@ def get_authors(doc):
cover = book.get_cover()
if cover:
d.cover_url = cover.url("M")

overdrive = book.get("identifiers", {}).get('overdrive')
if overdrive:
d.overdrive_url = "http://www.overdrive.com/search?q={%s}" % overdrive
Expand All @@ -203,7 +204,7 @@ def get_authors(doc):
collections = ia.get_meta_xml(ia_id).get("collection", [])
if 'printdisabled' in collections or 'lendinglibrary' in collections:
d.daisy_url = book.url("/daisy")

if 'lendinglibrary' in collections:
d.borrow_url = book.url("/borrow")
elif 'inlibrary' in collections:
Expand Down
16 changes: 8 additions & 8 deletions openlibrary/templates/lib/search_foot.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

<form method="get" action="/search" class="siteSearch">
<div id="bottomOptions" class="searchOptions hidden">
<div class="searchPlus">
<a href="/search/inside">Full Text Search</a>?
</div>
<fieldset class="home">
<legend>More Search Options</legend>
<!-- HIDE THIS
Expand Down Expand Up @@ -43,7 +46,7 @@
</div>
</fieldset>
</div>

<fieldset class="home">
<legend>Site Search</legend>
<label for="qbtm" class="small hidden" id="btmSrchLabel">Keyword<br/></label>
Expand All @@ -52,15 +55,12 @@
</fieldset>
<div class="searchPlacement">
<div class="searchFilter">
<div class="searchCheckbox">
<input name="has_fulltext" type="checkbox" value="true" id="ftokensbtm" />
<label for="ftokensbtm">$_("Only eBooks")</label>
</div>
<div class="searchOpener">
<a href="javascript:;" id="searchFoot">$_("More options")</a>
<a href="javascript:;" id="searchFoot">$_("More search options")</a>
</div>
<div class="searchFullText">
<a href="/search/inside" data-ol-link-track="BottomSearch|FullText">$_("Search inside")</a>
<div class="searchCheckbox">
<input name="has_fulltext" type="checkbox" value="true" id="ftokensbtm" />
<label for="ftokensbtm">$_("Show only eBooks")</label>
</div>
</div>
</div>
Expand Down
17 changes: 10 additions & 7 deletions openlibrary/templates/lib/search_head.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

<h2 class="shift">Site Search</h2>
<div class="siteSearch" id="headerSearch">
<div class="searchFullText">
<span class="word-corner-badge">BETA</span><a href="/search/inside" data-ol-link-track="TopSearch|FullText">$_("Search inside all Internet Archive books")</a>
</div>
<form method="get" action="/search" class="siteSearch">
<fieldset class="home">
<legend>Site Search</legend>
Expand All @@ -21,15 +24,12 @@ <h2 class="shift">Site Search</h2>

<div class="searchPlacement">
<div class="searchFilter">
<div class="searchCheckbox">
<input name="has_fulltext" type="checkbox" value="true" id="ftokenstop" />
<label for="ftokenstop">$_("Only eBooks")</label>
</div>
<div class="searchOpener">
<a href="javascript:;" id="searchHead">$_("More options")</a>
<a href="javascript:;" id="searchHead">$_("More search options")</a>
</div>
<div class="searchFullText">
<a href="/search/inside" data-ol-link-track="TopSearch|FullText">$_("Search inside")</a>
<div class="searchCheckbox">
<input name="has_fulltext" type="checkbox" value="true" id="ftokenstop" />
<label for="ftokenstop">$_("Show only eBooks")</label>
</div>
</div>
</div>
Expand All @@ -43,6 +43,9 @@ <h2 class="shift">Site Search</h2>
<input type="text" name="$name" id="qtop-$name" placeholder="$placeholder" size="35"/>
</div>
</fieldset>
<div class="searchPlus">
<a href="/search/inside">Full Text Search</a>?
</div>
</div>
</form>
</div>
Expand Down
7 changes: 3 additions & 4 deletions openlibrary/templates/search/inside.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
$ num_found = results['hits'].get('total', 0)

<div id="contentHead">
<h1 class="header-inline">$_("Search Inside")</h1>
<div class="beta">(BETA)</div>
<h1><span class="word-corner-badge">BETA</span>$_("Search Inside")</h1>
$if q:
$if num_found:
<p class="sansserif darkgreen collapse"><strong>$commify(num_found) hit$("s" if num_found != 1 else "")</strong></p>
Expand All @@ -35,14 +34,14 @@ <h1 class="header-inline">$_("Search Inside")</h1>

<div id="contentBody">
<div class="section">
<form class="siteSearch olform" action="">
<form class="siteSearch searchInsideForm olform" action="">
<input type="text" class="larger" name="q" size="100" style="width: 505px;" value="$q"/>
<input type="submit" class="large" value="$_('Search')"/>
</form>
</div>

$if q and 'error' in results:
$results['error']
<div class="searchResultsError">$results['error']</div>
$if q and 'error' not in results:
<div id="searchResults">
<p>Search took $("%.2f" % search_secs) seconds</p>
Expand Down
37 changes: 16 additions & 21 deletions static/css/master.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ button.plain:hover {color:#35672e;}
.onTop{z-index:20000!important;}
.pagination span.ellipsis {display:block;float:left;color:#000;padding:8px;margin-right:10px;}
.breadcrumbs {font-family:"Lucida Grande", Verdana, Geneva, Helvetica, Arial, sans-serif;color: #615132;font-size:11px;padding-bottom:10px;}
.header-inline {display:inline-block;vertical-align:middle;}

.fixthis{background-color:pink!important;}
.adminOnly{background-color:#ffa337!important;padding:4px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;}
Expand Down Expand Up @@ -205,11 +204,6 @@ body#admin div#bottom {background-color: transparent;}
-webkit-transform: rotate(324deg) translate(-11px, -14px);
transform: rotate(324deg) translate(-10px, -16px);
}
.beta {
display: inline-block;
vertical-align: middle;
margin-left: 4px!important;
}

/* ERROR MESSAGES */
div.flash-messages {
Expand Down Expand Up @@ -483,10 +477,19 @@ body#user div.siteSearch {
background-color: #e2dcc5;
}
div#headerSearch {
top: 86px;
top: 64px;
padding: 9px;
outline:none;
}
.searchFullText {
margin-bottom: 6px;
}
.searchFullText a {
font-size: 0.6875em;
}
.searchFullText a:visited {
color: #036daa;
}
div#footerPosition {
position: relative;
width: 960px;
Expand Down Expand Up @@ -555,25 +558,17 @@ div#footerSearch div.searchFilter {
height: 19px;
}
div.searchFilter .searchOpener {
float: left;
margin-top: 4px;
margin-right: 6px;
position: absolute;
right: 0;
bottom: 0;
font-size: 0.6875em;
}
div.searchFilter .searchCheckbox {
float: left;
margin-top: 4px;
margin-right: 6px;
font-size: 0.6875em;
}
div.searchFilter .searchFullText {
float: left;
margin-top: 4px;
position: absolute;
left: 0;
bottom: 0;
font-size: 0.6875em;
}
div.searchFilter .searchFullText a:visited {
color: #036daa;
}
input.query {
width: 205px;
}
Expand Down

0 comments on commit 7418261

Please sign in to comment.