Added basic support of search for objects.
This commit is contained in:
parent
80485a98ab
commit
5c4f0eb5d9
|
@ -362,4 +362,61 @@ function embedEventCalendar(array $arguments):string {
|
|||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for embedding search results from MD.
|
||||
*
|
||||
* @param array $arguments Arguments / GET parameters for urls to query.
|
||||
* @param array $settings Settings variable.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function searchMDObjects(array $arguments, array $settings):string {
|
||||
|
||||
$toIgnore = ["t=", "output=", "mod="];
|
||||
$srcArgs = "done=yes";
|
||||
foreach ($arguments as $arg) {
|
||||
if (startsWithAny($arg, $toIgnore)) continue;
|
||||
$srcArgs .= "&" . $arg;
|
||||
}
|
||||
$srcArgs .= "&output=json&mod=complete";
|
||||
|
||||
$contents = json_decode(queryCachePage($settings['mdVersion'] . "?$srcArgs", "search", $settings), true);
|
||||
|
||||
$output = '
|
||||
<div class="searchGrid">
|
||||
';
|
||||
|
||||
foreach ($contents as $object) {
|
||||
$output .= '
|
||||
<div class="objTile">
|
||||
';
|
||||
|
||||
if (isset($object['image']) > 0) {
|
||||
$output .= '
|
||||
<img src="' . $settings['mdVersion'] . $object['image'] . '" />';
|
||||
}
|
||||
|
||||
$output .= '
|
||||
<div>
|
||||
|
||||
<h4>' . $object['objekt_name'] . '</h4>
|
||||
|
||||
<div>
|
||||
<a href="./object.php?id=' . $object['objekt_id'] . '" class="toTranslate" data-content="More"></a>
|
||||
<a href="' . $settings['mdVersion'] . '?t=objekt&oges=' . $object['objekt_id'] . '" class="toTranslate" data-content="MoreAtMuseumDigital">' . $object['objekt_name'] . '</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
$output .= '
|
||||
</div>
|
||||
';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
function searchInPages(string $searchTerm) {
|
||||
function searchInPages(string $searchTerm):array {
|
||||
|
||||
$files = scanDirConts(__DIR__ . "/../data/static");
|
||||
|
||||
|
@ -34,19 +34,55 @@ function searchInPages(string $searchTerm) {
|
|||
|
||||
$curResults['title'] = $contents['title'];
|
||||
// Sanitize content for snippets.
|
||||
$snippet = preg_replace('/[\[{\(].*[\]}\)]/U' , '', strip_tags($contents['content']));
|
||||
$snippet = preg_replace('/[\[{\(].*[\]}\)]/U', '', strip_tags($contents['content']));
|
||||
$curResults['snippet'] = createTextSnippet($snippet, 180);
|
||||
$results[$file] = $curResults;
|
||||
|
||||
}
|
||||
|
||||
usort($results, function($a, $b) {
|
||||
if ($a == $b) return 0;
|
||||
return ($a > $b) ? -1 : 1;
|
||||
if ($a['priority'] == $b['priority']) return 0;
|
||||
return ($a['priority'] > $b['priority']) ? -1 : 1;
|
||||
});
|
||||
|
||||
return $results;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for generating and listing search results.
|
||||
*
|
||||
* @param string $searchTerm Search term.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function displaySearchResults(string $searchTerm):string {
|
||||
|
||||
$searchResults = searchInPages($searchTerm);
|
||||
$output = '
|
||||
<ul id="pagesSearchList">';
|
||||
|
||||
foreach ($searchResults as $file => $item) {
|
||||
$output .= '
|
||||
<li>
|
||||
|
||||
<a href="./?id=' . str_replace(".json", "", $file) . '"><h4>' . $item['title'] . '</h4></a>
|
||||
<p>' . (string)($item['snippet']) . '</p>
|
||||
<dl class="searchMetadataLine">
|
||||
<dt class="toTranslate" data-content="Hits"></dt>
|
||||
<dd>' . (string)($item['inTitle'] + $item['inDescription']) . '</dd>
|
||||
</dl>
|
||||
|
||||
</li>
|
||||
';
|
||||
}
|
||||
|
||||
$output .= "
|
||||
</ul>";
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
|
@ -29,6 +29,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
"Times" : "Times",
|
||||
"Search" : "Search",
|
||||
"SearchingFor" : "Searching for",
|
||||
"Hits" : "Hits:",
|
||||
"ResultsInPages" : "Results in texts",
|
||||
"... who" : "... who",
|
||||
"... where" : "... where",
|
||||
"... when" : "... when",
|
||||
|
@ -50,6 +52,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
"Times" : "Zeiten",
|
||||
"Search" : "Suche",
|
||||
"SearchingFor" : "Suche nach",
|
||||
"Hits" : "Treffer:",
|
||||
"ResultsInPages" : "Treffer in Texten",
|
||||
"... who" : "... wer",
|
||||
"... where" : "... wo",
|
||||
"... when" : "... wann",
|
||||
|
|
16
search.php
16
search.php
|
@ -51,9 +51,19 @@ if (!isset($_GET['q'])) {
|
|||
}
|
||||
else {
|
||||
|
||||
echo '<h1><span class="toTranslate" data-content="SearchingFor"></span> "' . $_GET['q'] . '"</h1>';
|
||||
$resultsInPages = searchInPages($_GET['q']);
|
||||
print_r($resultsInPages);
|
||||
echo '
|
||||
<h1><span class="toTranslate" data-content="SearchingFor"></span> "' . $_GET['q'] . '"</h1>
|
||||
|
||||
<section>
|
||||
<h2><span class="toTranslate" data-content="ResultsInPages"></span></h2>
|
||||
' . displaySearchResults($_GET['q']) . '
|
||||
</section>
|
||||
|
||||
<section id="mdSearchObjs">
|
||||
<h2><span class="toTranslate" data-content="ResultsInObjects"></span></h2>
|
||||
' . searchMDObjects(["sv=" . $_GET['q']], $settings) . '
|
||||
</section>
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
*/
|
||||
|
||||
html { margin: 0; padding: 0; }
|
||||
body { margin: 0; padding: 0; font-family: sourceSansPro; font-size: 1.15em; line-height: 1.5; }
|
||||
body { margin: 0; padding: 0; font-family: sourceSansPro;
|
||||
font-size: 1.15em; line-height: 1.5; }
|
||||
|
||||
* { box-sizing: border-box; z-index: 1; }
|
||||
a { color: inherit; text-decoration: none; }
|
||||
|
@ -35,8 +36,10 @@ a.buttonLike,
|
|||
select,
|
||||
button,
|
||||
textarea,
|
||||
input { padding: .6em .8em; background: #FAFAFA; border: 1px solid #CFD8DC; font-family: roboto; font-size: inherit;
|
||||
border-radius: .3em; transition: background .1s, box-shadow .1s; box-sizing: border-box; }
|
||||
input { padding: .6em .8em; background: #FAFAFA; border: 1px solid #CFD8DC;
|
||||
font-family: roboto; font-size: inherit;
|
||||
border-radius: .3em; box-sizing: border-box;
|
||||
transition: background .1s, box-shadow .1s; }
|
||||
button { padding: .6em; }
|
||||
select { padding: .3em .8em; }
|
||||
textarea { line-height: 1.4em; }
|
||||
|
@ -135,6 +138,10 @@ main { padding: .5em 5em 3em 0; text-align: justify; }
|
|||
body > footer { margin: 1em 5vw 2em 5vw; padding: 1em 0; background: #FFF; color: #666;
|
||||
border-top: 1px solid #AAA; }
|
||||
|
||||
/****************************
|
||||
* Specialized pages.
|
||||
*/
|
||||
|
||||
/************
|
||||
* Editing Static Pages
|
||||
*/
|
||||
|
@ -152,6 +159,21 @@ body > footer { margin: 1em 5vw 2em 5vw; padding: 1em 0; background: #FFF; color
|
|||
|
||||
#pageTools > * { padding: 0 1rem; }
|
||||
|
||||
/************
|
||||
* Search pages
|
||||
*/
|
||||
|
||||
#pagesSearchList,
|
||||
#pagesSearchList li { margin: 0; padding: 0; list-style: none; }
|
||||
#pagesSearchList li { margin: .5em 0; padding: .5em 0;
|
||||
border-bottom: 1px solid #D6D6D6; transition: border-bottom .4s; }
|
||||
#pagesSearchList li:hover { border-bottom-color: #666; }
|
||||
|
||||
#pagesSearchList h4 { margin: 0; padding: 0; }
|
||||
#pagesSearchList dl { color: #666; font-size: .9em; }
|
||||
#pagesSearchList dt,
|
||||
#pagesSearchList dd { display: inline-block; margin: 0; padding: 0; }
|
||||
|
||||
/************
|
||||
* Login Page
|
||||
*/
|
||||
|
@ -175,6 +197,7 @@ body > footer { margin: 1em 5vw 2em 5vw; padding: 1em 0; background: #FFF; color
|
|||
/************
|
||||
* Larger screens.
|
||||
*/
|
||||
|
||||
@media screen and (min-width: 95em) {
|
||||
#mainHeader,
|
||||
body > nav,
|
||||
|
|
|
@ -3,6 +3,14 @@
|
|||
* Styles for data embedded from museum-digital.
|
||||
*/
|
||||
|
||||
/**********
|
||||
* Objects in search results.
|
||||
*/
|
||||
|
||||
.searchGrid { }
|
||||
.searchGrid .objTile { margin-bottom: 1em; vertical-align: top; }
|
||||
.searchGrid .objTile img { max-height: 180px; }
|
||||
|
||||
/**********
|
||||
* Simple tiles for displaying an object.
|
||||
*/
|
||||
|
|
Reference in New Issue
Block a user