Browse Source

Setting search scope.

pull/728/head
Sebastian 5 years ago
parent
commit
9799a5197a
  1. 13
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs
  2. 6
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs
  3. 18
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/FullText/MongoTextIndex.cs

13
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs

@ -34,8 +34,9 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
private readonly QueryReferrers queryReferrers; private readonly QueryReferrers queryReferrers;
private readonly QueryScheduled queryScheduled; private readonly QueryScheduled queryScheduled;
private readonly string name; private readonly string name;
private readonly ReadPreference readPreference;
public MongoContentCollection(string name, IMongoDatabase database, IAppProvider appProvider) public MongoContentCollection(string name, IMongoDatabase database, IAppProvider appProvider, ReadPreference readPreference)
: base(database) : base(database)
{ {
this.name = name; this.name = name;
@ -47,6 +48,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
queryReferences = new QueryReferences(queryByIds); queryReferences = new QueryReferences(queryByIds);
queryReferrers = new QueryReferrers(); queryReferrers = new QueryReferrers();
queryScheduled = new QueryScheduled(); queryScheduled = new QueryScheduled();
this.readPreference = readPreference;
} }
public IMongoCollection<MongoContentEntity> GetInternalCollection() public IMongoCollection<MongoContentEntity> GetInternalCollection()
@ -59,6 +62,14 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
return name; return name;
} }
protected override MongoCollectionSettings CollectionSettings()
{
return new MongoCollectionSettings
{
ReadPreference = readPreference
}
}
protected override Task SetupCollectionAsync(IMongoCollection<MongoContentEntity> collection, protected override Task SetupCollectionAsync(IMongoCollection<MongoContentEntity> collection,
CancellationToken ct) CancellationToken ct)
{ {

6
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs

@ -39,10 +39,12 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
Guard.NotNull(appProvider, nameof(appProvider)); Guard.NotNull(appProvider, nameof(appProvider));
collectionAll = collectionAll =
new MongoContentCollection("States_Contents_All3", database, appProvider); new MongoContentCollection("States_Contents_All3", database, appProvider,
ReadPreference.Primary);
collectionPublished = collectionPublished =
new MongoContentCollection("States_Contents_Published3", database, appProvider); new MongoContentCollection("States_Contents_Published3", database, appProvider,
ReadPreference.Secondary);
this.appProvider = appProvider; this.appProvider = appProvider;
} }

18
backend/src/Squidex.Domain.Apps.Entities.MongoDb/FullText/MongoTextIndex.cs

@ -82,7 +82,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.FullText
public async Task<List<DomainId>?> SearchAsync(IAppEntity app, GeoQuery query, SearchScope scope) public async Task<List<DomainId>?> SearchAsync(IAppEntity app, GeoQuery query, SearchScope scope)
{ {
var byGeo = var byGeo =
await Collection.Find( await GetCollection(scope).Find(
Filter.And( Filter.And(
Filter.Eq(x => x.AppId, app.Id), Filter.Eq(x => x.AppId, app.Id),
Filter.Eq(x => x.SchemaId, query.SchemaId), Filter.Eq(x => x.SchemaId, query.SchemaId),
@ -126,7 +126,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.FullText
private async Task<List<DomainId>> SearchBySchemaAsync(string queryText, IAppEntity app, TextFilter filter, SearchScope scope, int limit) private async Task<List<DomainId>> SearchBySchemaAsync(string queryText, IAppEntity app, TextFilter filter, SearchScope scope, int limit)
{ {
var bySchema = var bySchema =
await Collection.Find( await GetCollection(scope).Find(
Filter.And( Filter.And(
Filter.Eq(x => x.AppId, app.Id), Filter.Eq(x => x.AppId, app.Id),
Filter.In(x => x.SchemaId, filter.SchemaIds), Filter.In(x => x.SchemaId, filter.SchemaIds),
@ -143,7 +143,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.FullText
private async Task<List<DomainId>> SearchByAppAsync(string queryText, IAppEntity app, SearchScope scope, int limit) private async Task<List<DomainId>> SearchByAppAsync(string queryText, IAppEntity app, SearchScope scope, int limit)
{ {
var bySchema = var bySchema =
await Collection.Find( await GetCollection(scope).Find(
Filter.And( Filter.And(
Filter.Eq(x => x.AppId, app.Id), Filter.Eq(x => x.AppId, app.Id),
Filter.Exists(x => x.SchemaId), Filter.Exists(x => x.SchemaId),
@ -168,5 +168,17 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.FullText
return Filter.Eq(x => x.ServePublished, true); return Filter.Eq(x => x.ServePublished, true);
} }
} }
private IMongoCollection<MongoTextIndexEntity> GetCollection(SearchScope scope)
{
if (scope == SearchScope.All)
{
return Collection;
}
else
{
return Collection.WithReadPreference(ReadPreference.Secondary);
}
}
} }
} }

Loading…
Cancel
Save