Added settings handling in the backend and settings string display in the front-end
This commit is contained in:
@@ -128,4 +128,26 @@ public class SearchdomainController : ControllerBase
|
||||
|
||||
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 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using Server.Exceptions;
|
||||
using Shared.Models;
|
||||
|
||||
namespace Server.Helper;
|
||||
|
||||
@@ -27,12 +28,12 @@ public class DatabaseHelper(ILogger<DatabaseHelper> logger)
|
||||
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()
|
||||
{
|
||||
{ "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);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public class Searchdomain
|
||||
public AIProvider aIProvider;
|
||||
public string searchdomain;
|
||||
public int id;
|
||||
public SearchdomainSettings settings;
|
||||
public Dictionary<string, DateTimedSearchResult> searchCache; // Key: query, Value: Search results for that query (with timestamp)
|
||||
public List<Entity> entityCache;
|
||||
public List<string> modelsInUse;
|
||||
@@ -23,7 +24,7 @@ public class Searchdomain
|
||||
public SQLHelper helper;
|
||||
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;
|
||||
_provider = provider.ToLower();
|
||||
@@ -33,6 +34,7 @@ public class Searchdomain
|
||||
this._logger = logger;
|
||||
searchCache = [];
|
||||
entityCache = [];
|
||||
settings = searchdomainSettings;
|
||||
connection = new MySqlConnection(connectionString);
|
||||
connection.Open();
|
||||
helper = new SQLHelper(connection, connectionString);
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
<label class="form-label">Settings</label>
|
||||
<div class="col-md-6">
|
||||
<input
|
||||
id="searchdomainConfig"
|
||||
type="text"
|
||||
class="form-control"
|
||||
placeholder="JSON-string"
|
||||
@@ -380,6 +381,11 @@
|
||||
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) {
|
||||
document.querySelectorAll('.domain-item').forEach(item => {
|
||||
item.classList.remove('active');
|
||||
@@ -479,6 +485,9 @@
|
||||
function populateQueriesTable(filterText = '') {
|
||||
if (!queries) return;
|
||||
|
||||
let searchdomainConfigPromise = getSearchdomainConfig(getSelectedDomainKey());
|
||||
let configElement = document.getElementById('searchdomainConfig');
|
||||
|
||||
const tbody = document.querySelector('#queriesTable tbody');
|
||||
tbody.innerHTML = '';
|
||||
|
||||
@@ -507,6 +516,20 @@
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user