public void TestIndexDefinition() { Client cl = GetClient(); Schema sc = new Schema().AddTextField("title", 1.0); ConfiguredIndexOptions options = new ConfiguredIndexOptions( new IndexDefinition(prefixes: new string[] { cl.IndexName })); Assert.True(cl.CreateIndex(sc, options)); RedisKey hashKey = (string)cl.IndexName + ":foo"; Db.KeyDelete(hashKey); Db.HashSet(hashKey, "title", "hello world"); try { #pragma warning disable 0618 Assert.True(cl.AddHash(hashKey, 1, false)); #pragma warning restore 0618 } catch (RedisServerException e) { Assert.StartsWith("ERR unknown command `FT.ADDHASH`", e.Message); return; // Starting from RediSearch 2.0 this command is not supported anymore } SearchResult res = cl.Search(new Query("hello world").SetVerbatim()); Assert.Equal(1, res.TotalResults); Assert.Equal(hashKey, res.Documents[0].Id); }
/// <summary> /// Create the index definition in redis /// </summary> /// <param name="schema">a schema definition <seealso cref="Schema"/></param> /// <param name="options">index option flags <seealso cref="IndexOptions"/></param> /// <returns>true if successful</returns> public async Task <bool> CreateIndexAsync(Schema schema, ConfiguredIndexOptions options) { var args = new List <object> { _boxedIndexName }; options.SerializeRedisArgs(args); args.Add("SCHEMA".Literal()); foreach (var f in schema.Fields) { f.SerializeRedisArgs(args); } return((string)await _db.ExecuteAsync("FT.CREATE", args).ConfigureAwait(false) == "OK"); }
/// <summary> /// Create the index definition in redis /// </summary> /// <param name="schema">a schema definition <seealso cref="Schema"/></param> /// <param name="options">index option flags <seealso cref="IndexOptions"/></param> /// <returns>true if successful</returns> public bool CreateIndex(Schema schema, ConfiguredIndexOptions options) { var args = new List <object> { _boxedIndexName }; options.SerializeRedisArgs(args); args.Add("SCHEMA".Literal()); foreach (var f in schema.Fields) { f.SerializeRedisArgs(args); } return((string)DbSync.Execute("FT.CREATE", args) == "OK"); }