Check-in by ben on 2025-04-30 01:22:43
Move "Web page" below Download in details. Add Similar Items
section to details. Add similar: special case to search.
INSERTED DELETED
7 2 src/details/index.dcgi.m4
40 5 src/search/index.dcgi.m4
47 7 TOTAL over 2 changed files
Index: src/details/index.dcgi.m4
==================================================================
--- src/details/index.dcgi.m4
+++ src/details/index.dcgi.m4
@@ -137,10 +137,12 @@
cgipath, url, server, port >>output
}
printf "[1|Download|%s/download/%s|%s|%s]\n", cgipath,
item_id, server, port >>output
+ printf "[h|Web page|URL:%s/details/%s|%s|%s]\n",
+ api_ssl_endpoint, uri_encode(id), server, port >>output
print "" >>output
print_html(output, descr)
print "" >>output
@@ -205,12 +207,15 @@
printf "[1|%s|%s/search/%%09uploader:%s|%s|%s]\n", label,
cgipath, uploader_email, server, port >>output
}
print "" >>output
- printf "[h|Item web page|URL:%s/details/%s|%s|%s]\n",
- api_ssl_endpoint, uri_encode(id), server, port >>output
+ print "# Similar Items" >>output
+ printf "[1|View similar items|%s/search/%%09similar:%s|%s|%s]\n",
+ cgipath, item_id, server, port >>output
+
+ print "" >>output
printf "[1|PHAROS|%s|%s|%s]\n", cgipath, server, port >>output
cache_end()
unlink(iaout)
return
Index: src/search/index.dcgi.m4
==================================================================
--- src/search/index.dcgi.m4
+++ src/search/index.dcgi.m4
@@ -9,12 +9,13 @@
incl(src/api.awk)
incl(src/cgi.awk)
incl(src/util.awk)
function main(search, cmd, count, creator, descr, field, fields, i,
- iaout, id, jsout, label, numfound, order, order_names, page, rows,
- searchstr, sort_param, title, type, url)
+ iaout, id, item, items, jsout, label, numfound, order,
+ order_names, page, rows, searchstr, sort_param, str, title, type,
+ url)
{
order_names["addeddate"] = "addeddate"
order_names["collection_size"] = "collection_size"
order_names["createddate"] = "createddate"
order_names["creator"] = "creatorSorter"
@@ -40,16 +41,53 @@
sort_param = parts[i]
order = substr(parts[i], 5)
}
}
}
+
+ iaout = gettemp()
+ jsout = gettemp()
# special case for when the search term is an archive.org details URL
if (match(search, /^https:\/\/(www\.)?archive\.org\/details\//)) {
id = substr(search, RLENGTH + 1)
search = "identifier:" id
}
+
+ # special case to list similar items
+ if (match(search, /^similar:/)) {
+ id = substr(search, RLENGTH + 1)
+
+ url = api_endpoint "/details/" id "?RelatedItemsGet=1"
+ api_request(url, "GET", iaout)
+
+ # scrape similar items
+ FS = "\t"
+ items = 0
+ delete item
+ str = ""
+ while ((getline <iaout) > 0) {
+ if (match($0, /<a href="\/details\/[^"]*"/)) {
+ str = substr($0, RSTART + 18, RLENGTH - 19)
+ items++
+ item[items] = str
+ }
+ }
+ close(iaout)
+
+ # truncate temporary file for re-use
+ printf "" >iaout
+ close(iaout)
+
+ for (i = 1; i <= items; i++) {
+ if (i == 1) {
+ search = "identifier:" item[i]
+ } else {
+ search = search "%20OR%20identifier:" item[i]
+ }
+ }
+ }
# remove quotes from search string, since it gets quoted later
gsub(/"/, "", search)
# default sort orders if none were specified
@@ -63,13 +101,10 @@
order = "nav_order desc"
sort_param = "sort" order
}
}
- iaout = gettemp()
- jsout = gettemp()
-
# get search results
field[1] = "creator"
field[2] = "description"
field[3] = "identifier"