Skip to content

Commit 5a5bec7

Browse files
committed
Update query-engine
Add graph display
1 parent 38e794f commit 5a5bec7

6 files changed

Lines changed: 433 additions & 10 deletions

File tree

services/query-engine/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ RUN chmod +x /usr/local/bin/docker-entrypoint.sh
4848

4949
WORKDIR /var/www
5050

51+
# Ensure Laravel cache data directory exists
52+
RUN mkdir -p storage/framework/cache/data && \
53+
chown -R $user:www-data storage/framework/cache
54+
5155
RUN chown -R $user:www-data storage bootstrap/cache && \
5256
chmod -R ug+rwX storage bootstrap/cache
5357

services/query-engine/app/Http/Controllers/QuerySearchController.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,114 @@
77

88
class QuerySearchController extends Controller
99
{
10+
public function get_page_connections(Request $request)
11+
{
12+
$url = $request->input('url');
13+
if (!$url) {
14+
return response()->json(['error' => 'URL is required'], 400);
15+
}
16+
17+
error_log('URL: ' . $url);
18+
19+
// Fetch page outlinks
20+
$outlinksData = DB::connection('mongodb')
21+
->table('outlinks')
22+
->where('id', $url)
23+
->first();
24+
25+
// if (!$outlinksData) {
26+
// return response()->json([
27+
// 'status' => 'error',
28+
// 'message' => 'URL not found in outlinks database'
29+
// ], 404);
30+
// }
31+
32+
$outlinks = $outlinksData->links ?? [];
33+
34+
// Fetch metadata for each outlink
35+
$enrichedOutlinks = [];
36+
if (count($outlinks) > 0) {
37+
$metadataCollection = DB::connection('mongodb')
38+
->table('metadata')
39+
->whereIn('_id', $outlinks)
40+
->get();
41+
42+
$metadataMap = [];
43+
foreach ($metadataCollection as $metadata) {
44+
$metadataMap[$metadata->id] = $metadata;
45+
}
46+
47+
foreach ($outlinks as $link) {
48+
if (isset($metadataMap[$link])) {
49+
$enrichedOutlinks[] = [
50+
'url' => $link,
51+
'title' => $metadataMap[$link]->title ?? 'Page Not Indexed',
52+
];
53+
} else {
54+
$enrichedOutlinks[] = [
55+
'url' => $link,
56+
'title' => 'Page Not Indexed'
57+
];
58+
}
59+
}
60+
}
61+
62+
// Fetch page backlinks
63+
$backlinksData = DB::connection('mongodb')
64+
->table('backlinks')
65+
->where('id', $url)
66+
->first();
67+
68+
// if (!$backlinksData) {
69+
// return response()->json([
70+
// 'status' => 'error',
71+
// 'message' => 'URL not found in backlinks database'
72+
// ], 404);
73+
// }
74+
75+
$backlinks = $backlinksData->links ?? [];
76+
77+
// Fetch metadata for each backlink
78+
$enrichedBacklinks = [];
79+
if (count($backlinks) > 0) {
80+
$metadataCollection = DB::connection('mongodb')
81+
->table('metadata')
82+
->whereIn('_id', $backlinks)
83+
->get();
84+
85+
$metadataMap = [];
86+
foreach ($metadataCollection as $metadata) {
87+
$metadataMap[$metadata->id] = $metadata;
88+
}
89+
90+
foreach ($backlinks as $link) {
91+
if (isset($metadataMap[$link])) {
92+
$enrichedBacklinks[] = [
93+
'url' => $link,
94+
'title' => $metadataMap[$link]->title ?? 'Page Not Indexed',
95+
];
96+
} else {
97+
$enrichedBacklinks[] = [
98+
'url' => $link,
99+
'title' => 'Page Not Indexed'
100+
];
101+
}
102+
}
103+
}
104+
105+
// Get url metadata
106+
$urlMetadata = DB::connection('mongodb')
107+
->table('metadata')
108+
->where('_id', $url)
109+
->first();
110+
111+
return view('page-connections', [
112+
'url' => $url,
113+
'title' => $urlMetadata->title ?? 'Page Not Indexed',
114+
'outlinks' => $enrichedOutlinks,
115+
'backlinks' => $enrichedBacklinks,
116+
]);
117+
}
10118
public function getTopImages($query, $page = 1, $perPage = 5)
11119
{
12120
// Split the query string

services/query-engine/resources/css/app.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,35 @@ footer a {
192192
/* Moves the button down */
193193
}
194194

195+
.btn-connection {
196+
background-color: var(--accent-2);
197+
border-left: solid white 0.2rem;
198+
border-top: solid white 0.2rem;
199+
border-right: solid var(--accent) 0.2rem;
200+
border-bottom: solid var(--accent) 0.2rem;
201+
box-shadow: 0 0 0 0.2rem black;
202+
color: var(--bg);
203+
@apply text-sm font-bold drop-shadow-lg px-2;
204+
}
205+
206+
.btn-connection:hover {
207+
cursor: pointer;
208+
background-color: var(--accent);
209+
}
210+
211+
.btn-connection:active {
212+
cursor: pointer;
213+
background-color: var(--accent);
214+
border-left: solid var(--accent) 0.2rem;
215+
border-top: solid var(--accent) 0.2rem;
216+
border-right: solid var(--accent-2) 0.2rem;
217+
border-bottom: solid var(--accent-2) 0.2rem;
218+
box-shadow: inset 0.2rem 0.2rem 0 black;
219+
/* Moves shadow inside */
220+
transform: translate(2px, 2px);
221+
/* Moves the button down */
222+
}
223+
195224
#search-bar {
196225
background-color: var(--text);
197226
color: var(--bg);
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
<a href="https://{{ $url }}">
2-
<li class="result-container">
3-
<h3 class="result-title">{{ $title }}</h3>
4-
<p class="result-text">{{ Str::limit($text, 200) }}</p>
5-
<p class="result-url">{{ $url }}</p>
6-
</li>
7-
</a>
1+
<li class="result-container relative">
2+
<!-- Full clickable area -->
3+
<div class="flex flex-col">
4+
<a href="https://{{ $url }}" class="mb-2">
5+
<div class="flex justify-between items-start">
6+
<h3 class="result-title">{{ $title }}</h3>
7+
</div>
8+
<p class="result-text mt-2">{{ Str::limit($text, 200) }}</p>
9+
<p class="result-url text-sm text-gray-500 mt-1">{{ $url }}</p>
10+
</a>
11+
<a href="/api/page-connections/?url={{ $url }}" target="_blank" class="btn-connection"
12+
title="Open page's connections">
13+
View Page's Links
14+
<i class="fa-solid fa-arrow-up-right-from-square"></i>
15+
</a>
16+
</div>
17+
</li>

0 commit comments

Comments
 (0)