Added settings handling in the backend and settings string display in the front-end

This commit is contained in:
2025-12-18 20:19:13 +01:00
parent bb8543dab2
commit affdeb00b3
6 changed files with 70 additions and 4 deletions

View File

@@ -128,4 +128,26 @@ public class SearchdomainController : ControllerBase
return Ok(new SearchdomainSearchesResults() { Searches = searchCache, Success = true }); return Ok(new SearchdomainSearchesResults() { Searches = searchCache, Success = true });
} }
[HttpGet("GetSettings")]
public ActionResult<SearchdomainSettingsResults> GetSettings(string searchdomain)
{
Searchdomain searchdomain_;
try
{
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
}
catch (SearchdomainNotFoundException)
{
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
return Ok(new SearchdomainSettingsResults() { Settings = null, Success = false, Message = "Searchdomain not found" });
}
catch (Exception ex)
{
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]);
return Ok(new SearchdomainSettingsResults() { Settings = null, Success = false, Message = ex.Message });
}
SearchdomainSettings settings = searchdomain_.settings;
return Ok(new SearchdomainSettingsResults() { Settings = settings, Success = true });
}
} }

View File

@@ -1,6 +1,7 @@
using System.Data.Common; using System.Data.Common;
using System.Text; using System.Text;
using Server.Exceptions; using Server.Exceptions;
using Shared.Models;
namespace Server.Helper; namespace Server.Helper;
@@ -27,12 +28,12 @@ public class DatabaseHelper(ILogger<DatabaseHelper> logger)
helper.ExecuteSQLNonQuery(query.ToString(), parameters); helper.ExecuteSQLNonQuery(query.ToString(), parameters);
} }
public static int DatabaseInsertSearchdomain(SQLHelper helper, string name) public static int DatabaseInsertSearchdomain(SQLHelper helper, string name, SearchdomainSettings settings = new())
{ {
Dictionary<string, dynamic> parameters = new() Dictionary<string, dynamic> parameters = new()
{ {
{ "name", name }, { "name", name },
{ "settings", "{}"} // TODO add settings. It's not used yet, but maybe it's needed someday... { "settings", settings}
}; };
return helper.ExecuteSQLCommandGetInsertedID("INSERT INTO searchdomain (name, settings) VALUES (@name, @settings)", parameters); return helper.ExecuteSQLCommandGetInsertedID("INSERT INTO searchdomain (name, settings) VALUES (@name, @settings)", parameters);
} }

View File

@@ -14,6 +14,7 @@ public class Searchdomain
public AIProvider aIProvider; public AIProvider aIProvider;
public string searchdomain; public string searchdomain;
public int id; public int id;
public SearchdomainSettings settings;
public Dictionary<string, DateTimedSearchResult> searchCache; // Key: query, Value: Search results for that query (with timestamp) public Dictionary<string, DateTimedSearchResult> searchCache; // Key: query, Value: Search results for that query (with timestamp)
public List<Entity> entityCache; public List<Entity> entityCache;
public List<string> modelsInUse; public List<string> modelsInUse;
@@ -23,7 +24,7 @@ public class Searchdomain
public SQLHelper helper; public SQLHelper helper;
private readonly ILogger _logger; private readonly ILogger _logger;
public Searchdomain(string searchdomain, string connectionString, AIProvider aIProvider, Dictionary<string, Dictionary<string, float[]>> embeddingCache, ILogger logger, string provider = "sqlserver", bool runEmpty = false) public Searchdomain(string searchdomain, string connectionString, AIProvider aIProvider, Dictionary<string, Dictionary<string, float[]>> embeddingCache, ILogger logger, string provider = "sqlserver", bool runEmpty = false, SearchdomainSettings searchdomainSettings = new())
{ {
_connectionString = connectionString; _connectionString = connectionString;
_provider = provider.ToLower(); _provider = provider.ToLower();
@@ -33,6 +34,7 @@ public class Searchdomain
this._logger = logger; this._logger = logger;
searchCache = []; searchCache = [];
entityCache = []; entityCache = [];
settings = searchdomainSettings;
connection = new MySqlConnection(connectionString); connection = new MySqlConnection(connectionString);
connection.Open(); connection.Open();
helper = new SQLHelper(connection, connectionString); helper = new SQLHelper(connection, connectionString);

View File

@@ -53,6 +53,7 @@
<label class="form-label">Settings</label> <label class="form-label">Settings</label>
<div class="col-md-6"> <div class="col-md-6">
<input <input
id="searchdomainConfig"
type="text" type="text"
class="form-control" class="form-control"
placeholder="JSON-string" placeholder="JSON-string"
@@ -380,6 +381,11 @@
return document.querySelector('.domain-item.active').id.split("_")[2] - 0; return document.querySelector('.domain-item.active').id.split("_")[2] - 0;
} }
function getSearchdomainConfig(domainKey) {
return fetch(`/Searchdomain/GetSettings?searchdomain=${encodeURIComponent(domains[domainKey])}`)
.then(r => r.json());
}
function selectDomain(domainKey) { function selectDomain(domainKey) {
document.querySelectorAll('.domain-item').forEach(item => { document.querySelectorAll('.domain-item').forEach(item => {
item.classList.remove('active'); item.classList.remove('active');
@@ -479,6 +485,9 @@
function populateQueriesTable(filterText = '') { function populateQueriesTable(filterText = '') {
if (!queries) return; if (!queries) return;
let searchdomainConfigPromise = getSearchdomainConfig(getSelectedDomainKey());
let configElement = document.getElementById('searchdomainConfig');
const tbody = document.querySelector('#queriesTable tbody'); const tbody = document.querySelector('#queriesTable tbody');
tbody.innerHTML = ''; tbody.innerHTML = '';
@@ -507,6 +516,20 @@
tbody.appendChild(row); tbody.appendChild(row);
}); });
searchdomainConfigPromise.then(searchdomainConfig => {
if (searchdomainConfig != null && searchdomainConfig.Settings != null)
{
configElement.value = JSON.stringify(searchdomainConfig.Settings, null, 2);
} else {
configElement.value = 'Error fetching searchdomain config';
console.log(searchdomainConfig);
// TODO add toast
console.error('Failed to fetch searchdomain config');
}
});
} }
function flagSearchdomainAsErroneous(domainKey) { function flagSearchdomainAsErroneous(domainKey) {

View File

@@ -16,4 +16,10 @@ public struct DateTimedSearchResult(DateTime dateTime, List<ResultItem> results)
public List<DateTime> AccessDateTimes { get; set; } = [dateTime]; public List<DateTime> AccessDateTimes { get; set; } = [dateTime];
[JsonPropertyName("Results")] [JsonPropertyName("Results")]
public List<ResultItem> Results { get; set; } = results; public List<ResultItem> Results { get; set; } = results;
} }
public struct SearchdomainSettings(bool cacheReconciliation = false)
{
[JsonPropertyName("CacheReconciliation")]
public bool CacheReconciliation { get; set; } = cacheReconciliation;
}

View File

@@ -54,3 +54,15 @@ public class SearchdomainSearchesResults
[JsonPropertyName("Searches")] [JsonPropertyName("Searches")]
public required Dictionary<string, DateTimedSearchResult> Searches { get; set; } public required Dictionary<string, DateTimedSearchResult> Searches { get; set; }
} }
public class SearchdomainSettingsResults
{
[JsonPropertyName("Success")]
public required bool Success { get; set; }
[JsonPropertyName("Message")]
public string? Message { get; set; }
[JsonPropertyName("Settings")]
public required SearchdomainSettings? Settings { get; set; }
}