-
-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathEntries.php
More file actions
80 lines (61 loc) · 1.86 KB
/
Entries.php
File metadata and controls
80 lines (61 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Statamic\Search\Searchables;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Statamic\Contracts\Entries\Entry as EntryContract;
use Statamic\Facades\Entry;
class Entries extends Provider
{
public static function handle(): string
{
return 'collection';
}
public static function referencePrefix(): string
{
return 'entry';
}
public function provide(): Collection|LazyCollection
{
$query = Entry::query();
if (! $this->usesWildcard()) {
$query->whereIn('collection', $this->keys);
}
if ($site = $this->index->locale()) {
$query->where('site', $site);
}
$this->applyQueryScope($query);
if ($filter = $this->filter()) {
return $query
->lazy(config('statamic.search.chunk_size'))
->filter($filter)
->values()
->map->reference();
}
$query->whereStatus('published');
return $query->pluck('reference');
}
public function contains($searchable): bool
{
if (! $searchable instanceof EntryContract) {
return false;
}
if (! $this->usesWildcard() && ! in_array($searchable->collectionHandle(), $this->keys)) {
return false;
}
if (($site = $this->index->locale()) && $site !== $searchable->locale()) {
return false;
}
if ($filter = $this->filter()) {
return $filter($searchable);
}
$query = Entry::query()
->whereStatus('published')
->where('id', $searchable->id());
$this->applyQueryScope($query);
return $query->exists();
}
public function find(array $ids): Collection
{
return Entry::query()->whereIn('id', $ids)->get();
}
}