diff --git a/PrototypWPFHAG/SearchWindow.xaml b/PrototypWPFHAG/SearchWindow.xaml
index a8b50c6..af178ae 100644
--- a/PrototypWPFHAG/SearchWindow.xaml
+++ b/PrototypWPFHAG/SearchWindow.xaml
@@ -1,204 +1,124 @@
-
-
-
-
-
-
-
-
-
+ x:Class="PrototypWPFHAG.SearchWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="clr-namespace:PrototypWPFHAG"
+ Title="PDF-Verwaltung (Admin)" Height="600" Width="1000"
+ WindowTitleBrush="FireBrick"
+ Icon="pack://application:,,,/Images/databaseicon.png"
+ ResizeMode="CanResizeWithGrip">
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
-
-
-
-
-
-
-
+
+
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
\ No newline at end of file
+
+
diff --git a/PrototypWPFHAG/SearchWindow.xaml.cs b/PrototypWPFHAG/SearchWindow.xaml.cs
index c09d822..c419f35 100644
--- a/PrototypWPFHAG/SearchWindow.xaml.cs
+++ b/PrototypWPFHAG/SearchWindow.xaml.cs
@@ -1,14 +1,17 @@
using MahApps.Metro.Controls;
+using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Web;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Documents;
namespace PrototypWPFHAG
@@ -60,7 +63,7 @@ namespace PrototypWPFHAG
}
else
{
- await SearchByTextAsync();
+ await SearchBySimilarityAsync();
}
}
catch (Exception ex)
@@ -90,7 +93,6 @@ namespace PrototypWPFHAG
var json = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize(json);
- // Extrahiere das Array "documents"
var documents = result.GetProperty("documents");
if (documents.GetArrayLength() == 0)
{
@@ -98,22 +100,24 @@ namespace PrototypWPFHAG
return;
}
- // Nimm das erste Element des Arrays
var document = documents[0];
- // UI aktualisieren
+ // Korrigierte UI-Aktualisierung
await Dispatcher.InvokeAsync(() =>
{
- SearchResultsListBox.ItemsSource = new List
+ SearchResultsListBox.ItemsSource = new List // Änderung von SearchResult zu DocumentDetail
{
- new SearchResult
+ new DocumentDetail
{
Id = document.GetProperty("id").GetInt32(),
- Filename = document.GetProperty("filename").GetString(),
+ DocumentName = document.GetProperty("document_name").GetString(), // Korrekter Property-Name
Content = document.GetProperty("content").GetString()
}
};
ContentTextBox.Text = document.GetProperty("content").GetString();
+
+ // Wichtig: DisplayMemberPath korrekt setzen
+ SearchResultsListBox.DisplayMemberPath = "DocumentName";
});
}
catch (Exception ex)
@@ -121,6 +125,7 @@ namespace PrototypWPFHAG
MessageBox.Show($"Fehler: {ex.Message}");
}
}
+
private async Task SearchByTextAsync()
{
try
@@ -137,7 +142,7 @@ namespace PrototypWPFHAG
MessageBox.Show($"Gefundene Dokumente: {documents?.Count}", "Debug");
SearchResultsListBox.ItemsSource = documents;
- SearchResultsListBox.DisplayMemberPath = "Filename";
+ SearchResultsListBox.DisplayMemberPath = "name";
}
catch (Exception ex)
{
@@ -145,7 +150,27 @@ namespace PrototypWPFHAG
}
}
+ private async Task SearchBySimilarityAsync()
+ {
+ try
+ {
+ var encodedQuery = Uri.EscapeDataString(SearchTextBox.Text);
+ var response = await _httpClient.GetAsync($"/documents/similarity?query={encodedQuery}");
+ var json = await response.Content.ReadAsStringAsync();
+ var result = JsonSerializer.Deserialize(json, new JsonSerializerOptions
+ {
+ PropertyNameCaseInsensitive = true
+ });
+
+ SearchResultsListBox.ItemsSource = result?.Documents;
+ SearchResultsListBox.DisplayMemberPath = "DocumentName";
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"Fehler: {ex.Message}");
+ }
+ }
private void PdfDropCanvas_DragEnter(object sender, DragEventArgs e)
{
@@ -192,6 +217,9 @@ namespace PrototypWPFHAG
[JsonPropertyName("document")]
public DocumentDetail Document { get; set; }
+
+ [JsonPropertyName("documents")]
+ public List Documents { get; set; }
}
public class DocumentDetail
@@ -199,11 +227,33 @@ namespace PrototypWPFHAG
[JsonPropertyName("id")]
public int Id { get; set; }
- [JsonPropertyName("filename")]
- public string Filename { get; set; }
+ [JsonPropertyName("document_name")]
+ public string DocumentName { get; set; }
[JsonPropertyName("content")]
public string Content { get; set; }
+
+ [JsonPropertyName("distance")]
+ public double Distance { get; set; }
+
+ // Für die TextBox-Bindung
+ private bool _isSelected;
+ public bool IsSelected
+ {
+ get => _isSelected;
+ set
+ {
+ _isSelected = value;
+ OnPropertyChanged();
+ }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
}
public class ApiError
{
@@ -303,7 +353,7 @@ namespace PrototypWPFHAG
var deletedIds = new List();
var errorIds = new List();
- foreach (var item in SearchResultsListBox.SelectedItems.Cast().ToList())
+ foreach (var item in SearchResultsListBox.SelectedItems.Cast().ToList())
{
try
{
@@ -334,7 +384,7 @@ namespace PrototypWPFHAG
}
else
{
- await SearchByTextAsync(); // Neu laden der Textsuche
+ await SearchBySimilarityAsync(); // Neu laden der Textsuche
}
// Feedback an Benutzer
@@ -352,40 +402,17 @@ namespace PrototypWPFHAG
private async void SearchResultsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
- if (SearchResultsListBox.SelectedItem is SearchResult selectedDocument)
+ if (SearchResultsListBox.SelectedItem is DocumentDetail selected)
{
try
{
- var response = await _httpClient.GetAsync($"/documents/by-id/{selectedDocument.Id}");
- var json = await response.Content.ReadAsStringAsync();
- var result = JsonSerializer.Deserialize(json);
+ var response = await _httpClient.GetAsync($"/documents/{selected.Id}/markdown");
+ var content = await response.Content.ReadAsStringAsync();
+ var result = JsonSerializer.Deserialize(content);
- // Sicherstellen, dass das "documents" Array existiert
- if (!result.TryGetProperty("documents", out var documents))
- {
- ContentTextBox.Text = "Ungültiges Antwortformat";
- return;
- }
-
- // Sicherstellen, dass das Array mindestens ein Element hat
- if (documents.GetArrayLength() == 0)
- {
- ContentTextBox.Text = "Dokument nicht gefunden";
- return;
- }
-
- var document = documents[0];
-
- // Sicherstellen, dass alle benötigten Felder existieren
- if (!document.TryGetProperty("content", out var contentProp))
- {
- ContentTextBox.Text = "Dokumentinhalt fehlt";
- return;
- }
-
- ContentTextBox.Text = contentProp.GetString();
-
- Debug.WriteLine($"API-Antwort: {json}");
+ ContentTextBox.Text = result.GetProperty("document")
+ .GetProperty("content")
+ .GetString();
}
catch (Exception ex)
{