Skip to content

Commit

Permalink
Omnisearch
Browse files Browse the repository at this point in the history
  • Loading branch information
Open Opus committed Feb 27, 2020
1 parent d22a5f1 commit 7ff07ce
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions html/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ RewriteRule genre/list/composer/(.*).json dyn/genre/list.phtml?composer=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule patron/list.json dyn/patron/list.phtml [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule omnisearch/(.*)/(.*).json dyn/omnisearch/list.phtml?search=$1&offset=$2 [L]
</IfModule>
84 changes: 84 additions & 0 deletions html/dyn/omnisearch/list.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?
include_once ("../../../lib/inc.php");

$apireturn["request"]["type"] = "omnisearch";
$apireturn["request"]["search"] = $_REQUEST["search"];
$apireturn["request"]["offset"] = $_REQUEST["offset"];

if ($_REQUEST["search"])
{
$_REQUEST["search"] = trim (preg_replace ('/(\s+)/', ' +', preg_replace ('(\b[^\d\W]+\b)', '$0*', $_REQUEST["search"])));

if (strlen ($_REQUEST["search"]) > 3)
{
$match = "match (summary) against ('+". $_REQUEST["search"]. "'";
$fullmatch = $match. ")";
$wherematch = "{$match} IN BOOLEAN MODE)";
}
else
{
$goquery = false;
$apireturn["status"] = Array ("success"=>"false", "error"=>"Too short search term");
}
}

// listing results

$sql = "SELECT if(omnisearch.work_id is null, 1, 0) iscomposer, composer.id composer_id, name, complete_name, birth, death, epoch, portrait, title, ifnull(subtitle,'') subtitle, ifnull(searchterms,'') searchterms, work.popular popular, work.recommended recommended, work.id work_id, genre, ({$fullmatch}) as relevance FROM composer, omnisearch LEFT JOIN work ON omnisearch.work_id = work.id where {$wherematch} and composer.id = omnisearch.composer_id order by iscomposer desc, relevance desc, recommended desc, popular desc, name asc, title asc limit 20 offset {$_REQUEST["offset"]}";
$results = mysqlfetch ($mysql, $sql);

if (!$results)
{
// if no results, return an error

$apireturn["status"] = Array ("success"=>"false", "error"=>"Nothing found");
}
else
{
// there are results, go list'em

$apireturn["status"] = Array ("success"=>"true", "source"=>"db");
$apireturn["status"]["rows"] = sizeof ($results);

foreach ($results as $res)
{
$composer = Array (
"id" => $res["composer_id"],
"name" => $res["name"],
"complete_name" => $res["complete_name"],
"epoch" => $res["epoch"],
"birth" => $res["birth"],
"death" => $res["death"],
"portrait" => $res["portrait"],
);

if ($res["iscomposer"])
{
$work = [];
}
else
{
$work = Array (
"id" => $res["work_id"],
"title" => $res["title"],
"subtitle" => $res["subtitle"],
"genre" => $res["genre"],
"popular" => $res["popular"],
"recommended" => $res["recommended"],
"searchterms" => $res["searchterms"]
);
}

$apireturn["results"][] = Array (
"composer" => $composer,
"work" => $work
);
}

if (sizeof ($results) == 20)
{
$apireturn["next"] = $_REQUEST["offset"] + 20;
}
}

echo savecache ("/omnisearch/{$_REQUEST["search"]}/{$_REQUEST["offset"]}.json", apireturn ($apireturn));
2 changes: 1 addition & 1 deletion lib/ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// global constants

define ("SOFTWARENAME", "Open Opus");
define ("SOFTWAREVERSION", "1.19.11");
define ("SOFTWAREVERSION", "1.20");
define ("USERAGENT", SOFTWARENAME. "/" . SOFTWAREVERSION. " ( ". SOFTWAREMAIL. " )");
define ("API_RETURN", "json");
define ("MIN_SIMILAR", 20);
Expand Down

0 comments on commit 7ff07ce

Please sign in to comment.