graphs
This commit is contained in:
+4
-37
@@ -6,6 +6,7 @@ use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Lucent\Edge\Edge;
|
||||
use Lucent\Primitive\Collection;
|
||||
use Lucent\Query\DatabaseGraph\DatabaseGraph;
|
||||
use Lucent\Query\Filter\AndFilter;
|
||||
use Lucent\Query\Filter\OrFilter;
|
||||
use Lucent\Record\InputFormatter;
|
||||
@@ -24,6 +25,7 @@ final class Query
|
||||
public function __construct(
|
||||
public readonly FilterParser $filterParser,
|
||||
public readonly InputFormatter $inputFormatter,
|
||||
public readonly DatabaseGraph $databaseGraph,
|
||||
)
|
||||
{
|
||||
$this->options = new QueryOptions();
|
||||
@@ -156,47 +158,12 @@ final class Query
|
||||
private
|
||||
function getChildren(array $ids): array
|
||||
{
|
||||
$subquery = DB::table('edges AS g')
|
||||
->select(DB::raw('g.source,g.target,g.rank,g.sourceSchema,g.targetSchema,g.field, 1 as depth '))
|
||||
->whereIn('source', $ids);
|
||||
|
||||
if (!empty($this->options->childrenFields)) {
|
||||
$subquery->whereIn('field', $this->options->childrenFields);
|
||||
}
|
||||
|
||||
$subquery->limit($this->options->childrenLimit)
|
||||
->unionAll(
|
||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||
->whereRaw("g.source = sg.target")
|
||||
->where("depth", "<", $this->options->childrenDepth)
|
||||
->orderBy("rank")
|
||||
);
|
||||
|
||||
return DB::table('search_graph')
|
||||
// ->select(DB::raw("*, 1 as depth "))
|
||||
->withRecursiveExpression('search_graph', $subquery)
|
||||
->get()->toArray();
|
||||
return $this->databaseGraph->getChildren($ids, $this->options);
|
||||
}
|
||||
|
||||
private function getParents(array $ids): array
|
||||
{
|
||||
$subquery = DB::table('edges AS g')
|
||||
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
||||
->limit($this->options->parentsLimit)
|
||||
->whereIn('g.target', $ids)
|
||||
->unionAll(
|
||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||
->whereRaw("g.target = sg.source")
|
||||
->where("depth", "<", $this->options->parentsDepth)
|
||||
->orderBy("rank")
|
||||
);
|
||||
|
||||
return DB::table('search_graph')
|
||||
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
|
||||
->withRecursiveExpression('search_graph', $subquery)
|
||||
->get()->toArray();
|
||||
return $this->databaseGraph->getParents($ids, $this->options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user