Skip to content

Commit

Permalink
Added other Malfuzat Versions
Browse files Browse the repository at this point in the history
  • Loading branch information
intisor authored Oct 8, 2024
1 parent 8975332 commit 7673477
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ namespace MalfuzatExplorer.Controllers
{
public class HomeController : Controller
{
private string pdfPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Malfuzat", "Malfuzat-1.pdf");

private string[] pdfFiles = new string[]
{
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Malfuzat", "Malfuzat-1.pdf"),
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Malfuzat", "Malfuzat-2.pdf"),
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Malfuzat", "Malfuzat-3.pdf"),
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Malfuzat", "Malfuzat-4.pdf")
};

public IActionResult Index()
{
Expand Down Expand Up @@ -55,6 +60,8 @@ public async Task<List<string>> SearchPdfForQueryAsync(string query)
List<string> results = new List<string>();
try
{
foreach (var pdfPath in pdfFiles)
{
if (!System.IO.File.Exists(pdfPath))
{
throw new FileNotFoundException("PDF file not found.");
Expand All @@ -70,12 +77,12 @@ public async Task<List<string>> SearchPdfForQueryAsync(string query)
string pageText = PdfTextExtractor.GetTextFromPage(document.GetPage(i));
if (pageText.Contains(query, StringComparison.OrdinalIgnoreCase))
{
string result = $"Found on leaf {i}: " + await GetContextAroundQueryAsync(pageText, query);

results.Add(result);
string result = $"Found in {Path.GetFileNameWithoutExtension(pdfPath)} on leaf {i}: " + await GetContextAroundQueryAsync(pageText, query);
results.Add(result);
}
}
}
}
}
catch (Exception ex)

Check warning on line 87 in Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used

Check warning on line 87 in Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used
{
Expand Down

0 comments on commit 7673477

Please sign in to comment.