mirror of
https://github.com/YGGverse/Yo.git
synced 2025-02-05 11:24:20 +00:00
implement highlight feature
This commit is contained in:
parent
8651eb4d97
commit
efc528c241
@ -47,11 +47,27 @@
|
||||
{
|
||||
"field_weights":
|
||||
{
|
||||
"url": 100,
|
||||
"title": 200,
|
||||
"description": 300,
|
||||
"keywords": 400,
|
||||
"body": 500
|
||||
"url":100,
|
||||
"title":200,
|
||||
"description":300,
|
||||
"keywords":400,
|
||||
"body":500
|
||||
}
|
||||
},
|
||||
"highlight":
|
||||
{
|
||||
"fields":
|
||||
[
|
||||
"url",
|
||||
"title",
|
||||
"description",
|
||||
"keywords",
|
||||
"body"
|
||||
],
|
||||
"options":
|
||||
{
|
||||
"around":5,
|
||||
"limit":140
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -169,6 +169,15 @@ foreach ($config->webui->search->options as $key => $value)
|
||||
}
|
||||
}
|
||||
|
||||
// Apply highlight options
|
||||
if ($config->webui->search->highlight->fields)
|
||||
{
|
||||
$query->highlight(
|
||||
(array) $config->webui->search->highlight->fields,
|
||||
(array) $config->webui->search->highlight->options
|
||||
);
|
||||
}
|
||||
|
||||
// Get found
|
||||
$found = empty($q) ? $total : $query->get()->getTotal();
|
||||
|
||||
@ -433,19 +442,38 @@ $results = $query->offset($p * $config->webui->pagination->limit - $config->webu
|
||||
|
||||
?>
|
||||
<img src="<?php echo $icon ?>" title="<?php echo $hostname ?>" alt="identicon" />
|
||||
<?php if (!empty($result->title)) { ?>
|
||||
<?php if (!empty($result->getHighlight()['title'])) { ?>
|
||||
<?php foreach ($result->getHighlight()['title'] as $title) { ?>
|
||||
<div>
|
||||
<h2><?php echo $title ?></h2>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } else if (!empty($result->title)) { ?>
|
||||
<div>
|
||||
<h2><?php echo $result->title ?></h2>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($result->description)) { ?>
|
||||
<?php if (!empty($result->getHighlight()['description'])) { ?>
|
||||
<?php foreach ($result->getHighlight()['description'] as $description) { ?>
|
||||
<div><?php echo $description ?></div>
|
||||
<?php } ?>
|
||||
<?php } else if (!empty($result->description)) { ?>
|
||||
<div><?php echo $result->description ?></div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($result->keywords)) { ?>
|
||||
<?php if (!empty($result->getHighlight()['keywords'])) { ?>
|
||||
<?php foreach ($result->getHighlight()['keywords'] as $keywords) { ?>
|
||||
<div><?php echo $keywords ?></div>
|
||||
<?php } ?>
|
||||
<?php } else if (!empty($result->keywords)) { ?>
|
||||
<div>
|
||||
<?php echo $result->keywords ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($result->getHighlight()['body'])) { ?>
|
||||
<?php foreach ($result->getHighlight()['body'] as $body) { ?>
|
||||
<div><?php echo $body ?></div>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<div>
|
||||
<a href="<?php echo $result->url ?>"><?php echo htmlentities(urldecode($result->url)) ?></a>
|
||||
<?php if (!in_array($result->get('code'), [0, 200])) { ?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user