Skip to content

Commit

Permalink
SQLite indexer
Browse files Browse the repository at this point in the history
Implemented support for building index in sqlite for the serverless GUI
  • Loading branch information
vandresen committed Aug 23, 2023
1 parent e2028c3 commit 6ddad76
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 24 deletions.
20 changes: 16 additions & 4 deletions DatabaseManager.BlazorComponents/Pages/DataIndex/CreateIndex.razor
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ else
<button class="btn btn-success" @onclick="StartIndex">Start Indexing >>></button>
</div>
<div class="col">
<p>Target Database: @singleton.TargetConnector</p>
<p>Target Database: @target</p>
</div>
</div>

Expand All @@ -65,6 +65,7 @@ else
private List<string> options { get; set; } = new List<string>();
private string source { get; set; } = "Choose Connector";
public string SqlText { get; set; }
public string target { get; set; }
List<string> taxonomies;
CreateIndexParameters iParameters = new CreateIndexParameters();
private string statusMessage = "Not started";
Expand All @@ -76,14 +77,25 @@ else
{
if (string.IsNullOrEmpty(singleton.TargetConnector))
{
await displayMessage.DisplayErrorMessage("Please select a data connector");
navigationManager.NavigateTo("/");
if (SD.Sqlite)
{
target = "SQLite";
}
else
{
await displayMessage.DisplayErrorMessage("Please select a data connector");
navigationManager.NavigateTo("/");
}
}
else
{
target = singleton.TargetConnector;
}
List<IndexFileList> fileList = await createIndex.GetTaxonomies();
var files = fileList.Select(s => s.Name);
taxonomies = files.ToList();

source = singleton.TargetConnector;
if (SD.Sqlite == false) source = singleton.TargetConnector;

connectParameters = await dataSources.GetSources();
foreach (ConnectParameters conn in connectParameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public DataIndexerServerLess(IHttpClientFactory clientFactory, SingletonServices

public async Task Create(CreateIndexParameters iParameters)
{
if (string.IsNullOrEmpty(SD.IndexAPIBase)) url = $"api/createindex";
if (SD.Sqlite == true) url = SD.IndexAPIBase.BuildFunctionUrl("/BuildIndex", $"", SD.IndexKey);
else if (string.IsNullOrEmpty(SD.IndexAPIBase)) url = $"api/createindex";
else url = SD.IndexAPIBase.BuildFunctionUrl("/api/BuildIndex", $"", SD.IndexKey);
Console.WriteLine(url);
ResponseDto response = await this.SendAsync<ResponseDto>(new ApiRequest()
Expand Down
10 changes: 7 additions & 3 deletions DatabaseManager.Services.IndexSqlite/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,20 @@ private static async Task<IResult> CreateIndexDatabase(IIndexAccess idxAccess)

private static async Task<IResult> BuildIndex(BuildIndexParameters idxParms, IIndexAccess idxAccess, IDataSourceService dataSource)
{
ResponseDto response = new();
try
{
if (string.IsNullOrEmpty(idxParms.TaxonomyFile)) return Results.BadRequest("Taxonomy file is missing");
if (string.IsNullOrEmpty(idxParms.Taxonomy)) return Results.BadRequest("Taxonomy file is missing");
await idxAccess.BuildIndex(idxParms);
return Results.Ok();
response.IsSuccess = true;
}
catch (Exception ex)
{
return Results.Problem(ex.Message);
response.IsSuccess = false;
string newString = $"BuildIndex: Could not build index, {ex}";
response.ErrorMessages.Insert(0, newString);
}
return Results.Ok(response);
}

private static async Task<IResult> GetDmIndexes(int? id, IIndexAccess idxAccess)
Expand Down
28 changes: 14 additions & 14 deletions DatabaseManager.Services.IndexSqlite/Helpers/IndexManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ namespace DatabaseManager.Services.IndexSqlite.Helpers
{
public class IndexManagement
{
private readonly string azureConnectionString;
//private readonly string azureConnectionString;
//private readonly IFileStorageServiceCommon _fileStorage;
private readonly string taxonomyShare = "taxonomy";
//private readonly string taxonomyShare = "taxonomy";
//private DbUtilities _dbConn;
//private readonly DapperDataAccess _dp;
//private readonly IIndexDBAccess _indexData;

public IndexManagement(string azureConnectionString)
{
this.azureConnectionString = azureConnectionString;
//public IndexManagement(string azureConnectionString)
//{
//this.azureConnectionString = azureConnectionString;
//var builder = new ConfigurationBuilder();
//IConfiguration configuration = builder.Build();
//_fileStorage = new AzureFileStorageServiceCommon(configuration);
//_fileStorage.SetConnectionString(azureConnectionString);
//_dbConn = new DbUtilities();
//_dp = new DapperDataAccess();
//_indexData = new IndexDBAccess(_dp);
}
//}


//public async Task<string> GetTaxonomyFile(string taxonomyFile)
Expand Down Expand Up @@ -126,13 +126,13 @@ public IndexManagement(string azureConnectionString)
// return result;
//}

public async Task CreateIndex(BuildIndexParameters indexParm)
{
if (string.IsNullOrEmpty(indexParm.TaxonomyFile))
{
Exception error = new Exception($"Taxonomy not selected");
throw error;
}
//public async Task CreateIndex(BuildIndexParameters indexParm)
//{
//if (string.IsNullOrEmpty(indexParm.Taxonomy))
//{
// Exception error = new Exception($"Taxonomy not selected");
// throw error;
//}
//Sources sr = new Sources(azureConnectionString);
//ConnectParameters target = await sr.GetSourceParameters(indexParm.TargetName);
//ConnectParameters source = await sr.GetSourceParameters(indexParm.SourceName);
Expand All @@ -148,7 +148,7 @@ public async Task CreateIndex(BuildIndexParameters indexParm)
// }
//}
//index.CloseIndex();
}
//}

//private static IndexFileDefinition ProcessIndexFileTokens(JToken token)
//{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class BuildIndexParameters
public string StorageAccount { get; set; }
public string SourceName { get; set; }
public string TargetName { get; set; }
public string TaxonomyFile { get; set; }
public string Taxonomy { get; set; }
public string Filter { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ private IndexFileData GetIndexData(JToken token)

private async Task<int> Initialize(ConnectParameters target, ConnectParameters source, BuildIndexParameters idxParms)
{
_taxonomy = await _fs.ReadFile("taxonomy", idxParms.TaxonomyFile);
_taxonomy = await _fs.ReadFile("taxonomy", idxParms.Taxonomy);
if (source.SourceType == "DataBase")
{
_sourceAccess = new DBDataAccess();
Expand Down
Binary file modified DatabaseManager.Services.IndexSqlite/mydatabase.db
Binary file not shown.

0 comments on commit 6ddad76

Please sign in to comment.