Now always ignoring short words in the search query to be able to always use index. Adding small search help docs.
This commit is contained in:
parent
5d94761fae
commit
a24d9c0670
|
@ -7,6 +7,9 @@ use Doctrine\ORM\{Mapping\ClassMetadata, QueryBuilder};
|
||||||
|
|
||||||
class TorrentSearcher
|
class TorrentSearcher
|
||||||
{
|
{
|
||||||
|
/** Minimal word length to be used when searching in the database. */
|
||||||
|
public const MIN_PART_LENGTH = 3;
|
||||||
|
|
||||||
private const ORDER_DISABLED_FIELDS = ['infoHash'];
|
private const ORDER_DISABLED_FIELDS = ['infoHash'];
|
||||||
|
|
||||||
/** @var TorrentRepository */
|
/** @var TorrentRepository */
|
||||||
|
@ -73,6 +76,20 @@ class TorrentSearcher
|
||||||
$query = trim($query);
|
$query = trim($query);
|
||||||
$query = preg_replace('/\s+/', ' ', $query);
|
$query = preg_replace('/\s+/', ' ', $query);
|
||||||
|
|
||||||
return explode(' ', $query);
|
$parts = explode(' ', $query);
|
||||||
|
|
||||||
|
return $this->removeShortParts($parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string[] $words
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
private function removeShortParts(array $words): array
|
||||||
|
{
|
||||||
|
return array_filter($words, function (string $word) {
|
||||||
|
return mb_strlen($word) >= self::MIN_PART_LENGTH;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,17 +44,24 @@
|
||||||
<main id="content" role="main" class="container">
|
<main id="content" role="main" class="container">
|
||||||
{% if is_granted('ROLE_USER') %}
|
{% if is_granted('ROLE_USER') %}
|
||||||
<div class id="form-search">
|
<div class id="form-search">
|
||||||
<form class="" action="{{ path('torrents_search') }}" method="get">
|
<form class="" action="{{ path('torrents_search') }}" method="get">
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<input name="query" class="form-control" type="text" placeholder="Torrent" aria-label="Search"
|
<input name="query" class="form-control" type="text" placeholder="Torrent" aria-label="Search"
|
||||||
value="{% if searchQuery is defined %}{{ searchQuery }}{% endif %}"
|
value="{% if searchQuery is defined %}{{ searchQuery }}{% endif %}"
|
||||||
{# @var app \Symfony\Bridge\Twig\AppVariable #}
|
{# @var app \Symfony\Bridge\Twig\AppVariable #}
|
||||||
{% if 'index' == app.request.get('_route') %}autofocus{% endif %} />
|
{% if 'index' == app.request.get('_route') %}autofocus{% endif %} />
|
||||||
<div class="input-group-append">
|
<div class="input-group-append">
|
||||||
<button class="btn btn-outline-primary my-2 my-sm-0" type="submit"><i class="fas fa-search"></i> Search</button>
|
<button class="btn btn-outline-primary my-2 my-sm-0" type="submit"><i class="fas fa-search"></i> Search</button>
|
||||||
</div>
|
<button class="btn btn-outline-info" type="button" data-toggle="collapse" data-target="#search-rules" aria-expanded="false" aria-controls="search-rules">
|
||||||
|
<i class="fa fa-question-circle"></i>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="alert alert-info collapse" role="alert" id="search-rules">
|
||||||
|
{{ include('search_rules_help.html.twig') }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
19
templates/search_rules_help.html.twig
Normal file
19
templates/search_rules_help.html.twig
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<p>
|
||||||
|
Use words consisting of <strong>{{ constant('\\App\\Search\\TorrentSearcher::MIN_PART_LENGTH') }}+</strong> characters.
|
||||||
|
Shorter words will be <u>ignored</u>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
The search will find torrents containing <strong>all</strong> words you used <u>regardless of their order and case</u>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Examples: <br/>
|
||||||
|
Use <code>pirates silicon valley</code> if you want to find "Pirates of Silicon Valley". Note that <code>of</code> will be ignored even
|
||||||
|
if you use it in the query. <br/>
|
||||||
|
Use <code>some series s08e10</code> if you want to find specific episode of some season of TV show. <br/>
|
||||||
|
Use <code>some series season</code> if you want to find full season. <br/>
|
||||||
|
It's also useful to use popular keywords if you want to find specific quality or format: <br/>
|
||||||
|
<code>some show 2160 265</code> should be enough to find what you need in 4k encoded with H.265 (HEVC).
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Use your imagination <i class="fas fa-smile-wink"></i>
|
||||||
|
</p>
|
Loading…
Reference in a new issue