Browse Source

don't always rebuild elasticsearch index on startup (#1372)

pull/1374/head
Jason Dove 2 years ago committed by GitHub
parent
commit
d64d8b0454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ErsatzTV.Infrastructure/Search/ElasticSearchIndex.cs
  2. 4
      ErsatzTV.Infrastructure/Search/LuceneSearchIndex.cs

12
ErsatzTV.Infrastructure/Search/ElasticSearchIndex.cs

@ -38,8 +38,12 @@ public class ElasticSearchIndex : ISearchIndex @@ -38,8 +38,12 @@ public class ElasticSearchIndex : ISearchIndex
// do nothing
}
// not really used by elasticsearch
public Task<bool> IndexExists() => Task.FromResult(false);
public async Task<bool> IndexExists()
{
_client ??= new ElasticsearchClient(Uri);
ExistsResponse exists = await _client.Indices.ExistsAsync(IndexName);
return exists.IsValidResponse;
}
public int Version => 36;
@ -47,7 +51,7 @@ public class ElasticSearchIndex : ISearchIndex @@ -47,7 +51,7 @@ public class ElasticSearchIndex : ISearchIndex
ILocalFileSystem localFileSystem,
IConfigElementRepository configElementRepository)
{
_client = new ElasticsearchClient(Uri);
_client ??= new ElasticsearchClient(Uri);
ExistsResponse exists = await _client.Indices.ExistsAsync(IndexName);
if (!exists.IsValidResponse)
{
@ -167,7 +171,7 @@ public class ElasticSearchIndex : ISearchIndex @@ -167,7 +171,7 @@ public class ElasticSearchIndex : ISearchIndex
var searchResult = new SearchResult(items.Map(i => new SearchItem(i.Type, i.Id)).ToList(), totalCount);
if (limit > 0)
if (limit is > 0 and < 10_000)
{
searchResult.PageMap = await GetSearchPageMap(query, limit);
}

4
ErsatzTV.Infrastructure/Search/LuceneSearchIndex.cs

@ -228,7 +228,7 @@ public sealed class LuceneSearchIndex : ISearchIndex @@ -228,7 +228,7 @@ public sealed class LuceneSearchIndex : ISearchIndex
TopFieldDocs topDocs = searcher.Search(query, null, hitsLimit, sort, true, true);
IEnumerable<ScoreDoc> selectedHits = topDocs.ScoreDocs.Skip(skip);
if (limit > 0)
if (limit is > 0 and < 10_000)
{
selectedHits = selectedHits.Take(limit);
}
@ -237,7 +237,7 @@ public sealed class LuceneSearchIndex : ISearchIndex @@ -237,7 +237,7 @@ public sealed class LuceneSearchIndex : ISearchIndex
selectedHits.Map(d => ProjectToSearchItem(searcher.Doc(d.Doc))).ToList(),
topDocs.TotalHits);
if (limit > 0)
if (limit is > 0 and < 10_000)
{
searchResult.PageMap = GetSearchPageMap(searcher, query, null, sort, limit);
}

Loading…
Cancel
Save