Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
D
Distributed-Search-Engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tammam.alsoleman
Distributed-Search-Engine
Commits
d5f76f36
Commit
d5f76f36
authored
Jan 22, 2026
by
tammam.alsoleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final Edit
parent
e55a9da1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
15 deletions
+28
-15
Application.java
src/main/java/com/distributed/search/Application.java
+1
-1
FrontendApplication.java
...main/java/com/distributed/search/FrontendApplication.java
+2
-2
SearchClient.java
src/main/java/com/distributed/search/grpc/SearchClient.java
+25
-12
No files found.
src/main/java/com/distributed/search/Application.java
View file @
d5f76f36
...
...
@@ -20,7 +20,7 @@ import java.util.Scanner;
* Main Entry point for the Distributed Search Engine.
*/
public
class
Application
implements
Watcher
{
private
static
final
String
ZOOKEEPER_ADDRESS
=
"192.168.
39
.250:2181"
;
// Change if ZK is on another machine
private
static
final
String
ZOOKEEPER_ADDRESS
=
"192.168.
233
.250:2181"
;
// Change if ZK is on another machine
private
static
final
int
SESSION_TIMEOUT
=
3000
;
private
static
final
int
DEFAULT_PORT
=
8080
;
private
static
final
String
STORAGE_DIR
=
"storage"
;
// Folder containing .txt files
...
...
src/main/java/com/distributed/search/FrontendApplication.java
View file @
d5f76f36
...
...
@@ -21,7 +21,7 @@ import java.nio.file.Paths;
import
java.util.concurrent.Executors
;
public
class
FrontendApplication
implements
Watcher
{
private
static
final
String
ZOOKEEPER_ADDRESS
=
"192.168.
39
.250:2181"
;
// Use your ZK IP
private
static
final
String
ZOOKEEPER_ADDRESS
=
"192.168.
233
.250:2181"
;
// Use your ZK IP
private
static
final
int
PORT
=
8080
;
// Main Web Port
private
final
LeaderHttpRegistry
leaderHttpRegistry
;
private
final
HttpClient
httpClient
;
...
...
@@ -112,7 +112,7 @@ public class FrontendApplication implements Watcher {
// Send headers first (200 OK, 0 means chunked/unknown length)
exchange
.
sendResponseHeaders
(
200
,
0
);
is
.
transferTo
(
os
);
//
Copy
data directly
is
.
transferTo
(
os
);
//
send
data directly
os
.
flush
();
}
...
...
src/main/java/com/distributed/search/grpc/SearchClient.java
View file @
d5f76f36
...
...
@@ -50,7 +50,9 @@ public class SearchClient {
if
(
stubs
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
long
startTime
=
System
.
currentTimeMillis
();
// Phase 1: Aggregate Global Counts
Map
<
String
,
Integer
>
globalTermCounts
=
new
HashMap
<>();
int
filesPerWorker
=
(
int
)
Math
.
ceil
((
double
)
allFiles
.
size
()
/
stubs
.
size
());
...
...
@@ -62,10 +64,7 @@ public class SearchClient {
if
(
count
<=
0
)
break
;
StatRequest
request
=
StatRequest
.
newBuilder
()
.
addAllTerms
(
terms
)
.
setStartIndex
(
currentFileIndex
)
.
setCount
(
count
)
.
build
();
.
addAllTerms
(
terms
).
setStartIndex
(
currentFileIndex
).
setCount
(
count
).
build
();
try
{
StatResponse
response
=
stubs
.
get
(
address
).
getDocumentStats
(
request
);
response
.
getTermToDocumentCountMap
().
forEach
((
term
,
docCount
)
->
...
...
@@ -85,26 +84,40 @@ public class SearchClient {
// --- Phase 2: Final Scoring ---
List
<
SearchResponse
.
DocumentResult
>
finalResults
=
new
ArrayList
<>();
currentFileIndex
=
0
;
// Helper variables to track the winning node (for the single log line)
String
bestWorkerNode
=
"None"
;
double
highestScoreFound
=
-
1.0
;
for
(
String
address
:
workerList
)
{
int
count
=
Math
.
min
(
filesPerWorker
,
allFiles
.
size
()
-
currentFileIndex
);
if
(
count
<=
0
)
break
;
CalculationRequest
request
=
CalculationRequest
.
newBuilder
()
.
addAllTerms
(
terms
)
.
putAllGlobalIdfs
(
globalIdfs
)
.
setStartIndex
(
currentFileIndex
)
.
setCount
(
count
)
.
build
();
.
addAllTerms
(
terms
).
putAllGlobalIdfs
(
globalIdfs
)
.
setStartIndex
(
currentFileIndex
).
setCount
(
count
).
build
();
try
{
SearchResponse
response
=
stubs
.
get
(
address
).
getFinalScores
(
request
);
finalResults
.
addAll
(
response
.
getResultsList
());
List
<
SearchResponse
.
DocumentResult
>
resultsFromWorker
=
response
.
getResultsList
();
// Logic to identify the node with the top result
for
(
SearchResponse
.
DocumentResult
res
:
resultsFromWorker
)
{
if
(
res
.
getScore
()
>
highestScoreFound
)
{
highestScoreFound
=
res
.
getScore
();
bestWorkerNode
=
address
;
}
}
finalResults
.
addAll
(
resultsFromWorker
);
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"Worker "
+
address
+
" Phase 2 error"
);
}
currentFileIndex
+=
count
;
}
long
endTime
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
">>> Distributed Search took: "
+
(
endTime
-
startTime
)
+
" ms"
);
// --- return the sorted list ---
finalResults
.
sort
((
a
,
b
)
->
Double
.
compare
(
b
.
getScore
(),
a
.
getScore
()));
System
.
out
.
println
(
String
.
format
(
">>> SEARCH LOG: Best result from [%s] | Score: [%.6f] | Cluster Latency: [%d ms]"
,
bestWorkerNode
,
highestScoreFound
,
(
endTime
-
startTime
)));
return
finalResults
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment