Skip to content

Commit

Permalink
First check
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvenga committed Nov 12, 2022
1 parent ac8dc39 commit 5cd9578
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Engines/ScoutPhpmorphyEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function search(Builder $builder)

public function paginate(Builder $builder, $perPage, $page)
{

$index = $this->buildIndexQuery($builder)
->selectRaw('`index`, `key`, COUNT(*) AS `count_lines`, SUM(`count_words`) AS `sum_count_words`')
->groupBy('index', 'key')
Expand All @@ -70,7 +71,6 @@ public function mapIds($results)

public function map(Builder $builder, $results, $model)
{
dd($builder);

if ($results->isEmpty()) {
return $model->newCollection();
Expand Down
20 changes: 17 additions & 3 deletions src/Models/Word.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Word extends Model

public function getTable()
{
return config('scout-phpmorphy.table_prefix').'words';
return config('scout-phpmorphy.table_prefix') . 'words';
}

protected $fillable = [
Expand Down Expand Up @@ -46,8 +46,7 @@ public static function getOrCreateItems($array): Collection
public static function getItems($array): Collection
{
$items = new Collection;

if (! empty($array)) {
if (! empty($array)) {
$items = self::query()
->when(array_filter($array, fn ($word) => $word['is_dictionary']),
fn (Builder $query, $words) => $query->whereIn('word', collect($words)->pluck('word')))
Expand All @@ -62,6 +61,21 @@ function (Builder $query, $words) {
->get();
}

/*
if (!empty($array)) {
$items = self::query();
foreach ($array as $word) {
$word['word'] = trim($word['word']);
if (!empty($word['word'])) {
$items = $items->orWhere('word', 'LIKE', $word['word'] . '%');
}
}
$items = $items->get();
}
*/

return $items;
}
}

0 comments on commit 5cd9578

Please sign in to comment.