public static AddCommand Create <TEntity>(IRedisearchSerializer serializer, TEntity entity, double score, string language) where TEntity : RedisearchSerializable <TEntity>, new() { var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); var indexName = schemaMetadata.IndexName; var entityId = string.Concat(schemaMetadata.DocumentIdPrefix, schemaMetadata.PrimaryKey.GetPrimaryKeyFromEntity(entity)); if (string.IsNullOrEmpty(language)) { language = schemaMetadata.Language; } var parameters = new List <object> { indexName, entityId, score, RedisearchIndexCache.GetBoxedLiteral("LANGUAGE"), RedisearchIndexCache.GetBoxedLiteral(language), RedisearchIndexCache.GetBoxedLiteral("FIELDS") }; foreach (var fieldPairs in serializer.Serialize(entity)) { parameters.Add(fieldPairs.Key); parameters.Add(fieldPairs.Value); } return(new AddCommand(parameters)); }
internal static IEnumerable <SearchResult <TEntity> > LoadSearchResults(IRedisearchSerializer serializer, RedisResult[] response, bool withScoresFlag, bool withPayloadsFlag) { int step = 2; int scoreOffset = 0; int contentOffset = 1; int payloadOffset = 0; if (withScoresFlag) { step += 1; scoreOffset = 1; contentOffset += 1; } if (withPayloadsFlag) { payloadOffset = scoreOffset + 1; step += 1; contentOffset += 1; } // the first item is the total number of the response var results = new List <SearchResult <TEntity> >((int)response[0]); for (int i = 1; i < response.Length; i += step) { double score = 1.0; byte[] payload = null; if (withScoresFlag) { score = (double)response[i + scoreOffset]; } if (withPayloadsFlag) { payload = (byte[])response[i + payloadOffset]; } var fieldsArray = (RedisValue[])response[i + contentOffset]; var entity = serializer.Deserialize <TEntity>(InitializeFieldsFrom(fieldsArray)); results.Add(new SearchResult <TEntity>( entity, withScoresFlag ? (double?)score : null, withPayloadsFlag ? payload : null)); } return(results); }
internal static IEnumerable <SearchResult <TEntity> > LoadMGetResults(IRedisearchSerializer serializer, RedisResult[] response) { var results = new List <SearchResult <TEntity> >(); foreach (RedisValue[] entityAsFields in response.Where(r => !r.IsNull)) { var entity = serializer.Deserialize <TEntity>(InitializeFieldsFrom(entityAsFields)); results.Add(new SearchResult <TEntity>( entity, null, null)); } return(results); }
public override async Task <IEnumerable <SearchResult <TEntity> > > ExecuteAsync <TEntity>(IDatabase database, IRedisearchSerializer serializer) { var response = (RedisResult[])await database.ExecuteAsync(Command, Arguments).ConfigureAwait(false); return(SearchResult <TEntity> .LoadSearchResults( serializer, response, WithScores, WithPayloads)); }
public override IEnumerable <SearchResult <TEntity> > Execute <TEntity>(IDatabase database, IRedisearchSerializer serializer) { var response = (RedisResult[])database.Execute(Command, Arguments); return(SearchResult <TEntity> .LoadSearchResults( serializer, response, WithScores, WithPayloads)); }
public abstract Task <IEnumerable <SearchResult <TEntity> > > ExecuteAsync <TEntity>(IDatabase database, IRedisearchSerializer serializer) where TEntity : RedisearchSerializable <TEntity>, new();
public RediSearchClient(IRedisearchSerializer redisearchSerializer, IConnectionMultiplexer redisConnection) { _serializer = redisearchSerializer ?? throw new ArgumentNullException(nameof(redisearchSerializer)); _redisConnection = redisConnection ?? throw new ArgumentNullException(nameof(redisConnection)); }