Skip to content

Commit

Permalink
fixed multiple admin crawl
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxinio-berincini committed Oct 16, 2023
1 parent 3564c29 commit 5be8b20
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/main/java/com/example/searchengine/SearchEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,18 @@ public void lucky(@RequestParam(name = "q") String q, HttpServletResponse respon

@PostMapping("/admin/crawl")
public ResponseEntity<String> startCrawl() {
crawler.crawl(startUrl);
return new ResponseEntity<>("Crawling finished successfully", HttpStatus.OK);
try{
// create a new crawler to initialize the executor service
if (properties.getCrawler().equals("multithread")) {
this.crawler= new MultithreadCrawler(indexFileName);
}
crawler.crawl(startUrl);
return new ResponseEntity<>("Crawling finished successfully", HttpStatus.OK);
} catch (Exception e) {
// Log the error for debugging
e.printStackTrace();
return new ResponseEntity<>("Error during crawling: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@PostMapping("/admin/regenerate-flipped-index")
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
server.port = 8080
crawl = false
crawler = simple
crawler = multithread

0 comments on commit 5be8b20

Please sign in to comment.