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 SchemaMetadata(string indexName, string documentIdPrefix, PropertyMetadata[] properties, PrimaryKey primaryKey, string language) { IndexName = RedisearchIndexCache.GetBoxedIndexName(indexName); DocumentIdPrefix = RedisearchIndexCache.GetBoxedLiteral(documentIdPrefix); Properties = properties; PrimaryKey = primaryKey; Language = RedisearchIndexCache.GetBoxedLiteral(language); }
public static CreateIndexCommand Create <TEntity>() where TEntity : RedisearchSerializable <TEntity>, new() { var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); var parameters = new List <object> { RedisearchIndexCache.GetBoxedIndexName(schemaMetadata.IndexName), RedisearchIndexCache.GetBoxedLiteral("SCHEMA") }; foreach (var propertyMetadata in schemaMetadata.Properties.Where(pm => !pm.IsIgnored)) { AddPropertyParametersTo(parameters, propertyMetadata); } return(new CreateIndexCommand(parameters)); }
private static void AddPropertyParametersTo(List <object> parameters, PropertyMetadata propertyMetadata) { parameters.Add(propertyMetadata.PropertyName); switch (propertyMetadata.RedisearchType) { case RedisearchPropertyType.Fulltext: parameters.Add(RedisearchIndexCache.GetBoxedLiteral("TEXT")); if (propertyMetadata.NoStem) { parameters.Add(RedisearchIndexCache.GetBoxedLiteral("NOSTEM")); } parameters.Add(RedisearchIndexCache.GetBoxedLiteral("WEIGHT")); parameters.Add((RedisValue)propertyMetadata.Weight); if (propertyMetadata.Sortable) { parameters.Add(RedisearchIndexCache.GetBoxedLiteral("SORTABLE")); } break; case RedisearchPropertyType.Numeric: parameters.Add(RedisearchIndexCache.GetBoxedLiteral("NUMERIC")); if (propertyMetadata.Sortable) { parameters.Add(RedisearchIndexCache.GetBoxedLiteral("SORTABLE")); } break; case RedisearchPropertyType.Geo: parameters.Add(RedisearchIndexCache.GetBoxedLiteral("GEO")); break; default: throw new ArgumentOutOfRangeException(); } if (propertyMetadata.NotIndexed) { parameters.Add(RedisearchIndexCache.GetBoxedLiteral("NOINDEX")); } }
internal List <object> CreateSearchArgs() { var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); var args = new List <object> { schemaMetadata.IndexName, BuildQueryString() }; if (Options.Verbatim) { args.Add(RedisearchIndexCache.GetBoxedLiteral("VERBATIM")); } if (Options.DisableStopwordFiltering) { args.Add(RedisearchIndexCache.GetBoxedLiteral("NOSTOPWORDS")); } if (Options.WithScores) { args.Add(RedisearchIndexCache.GetBoxedLiteral("WITHSCORES")); } if (Options.WithPayloads) { args.Add(RedisearchIndexCache.GetBoxedLiteral("WITHPAYLOADS")); } if (Options.WithScoreKeys) { args.Add(RedisearchIndexCache.GetBoxedLiteral("WITHSCOREKEYS")); } if (_ids != null && _ids.Length != 0) { args.Add(RedisearchIndexCache.GetBoxedLiteral("INKEYS")); args.Add(_ids.Length); foreach (var id in _ids) { args.Add(id); } } if (Options.Slop > -1) { args.Add(RedisearchIndexCache.GetBoxedLiteral("SLOP")); args.Add(Options.Slop); } if (Options.InOrder) { args.Add(RedisearchIndexCache.GetBoxedLiteral("INORDER")); } args.Add(RedisearchIndexCache.GetBoxedLiteral("LANGUAGE")); args.Add(string.IsNullOrEmpty(Options.Language) ? schemaMetadata.Language : RedisearchIndexCache.GetBoxedLiteral(Options.Language)); if (_sortingBy != null) { args.Add(RedisearchIndexCache.GetBoxedLiteral("SORTBY")); args.Add(_sortingBy); args.Add(_sortingOrder == SortingOrder.Ascending ? RedisearchIndexCache.GetBoxedLiteral("ASC") : RedisearchIndexCache.GetBoxedLiteral( "DESC")); } if (_paging.Offset != 0 || _paging.Count != 10) { args.Add(RedisearchIndexCache.GetBoxedLiteral("LIMIT")); args.Add(_paging.Offset); args.Add(_paging.Count); } return(args); }