Esempio n. 1
0
        public void CreateBookIndex()
        {
            Client client = new Client("books-idx", _redisProvider.Database());

            // drop the index, if it doesn't exists, that's fine
            try
            {
                client.DropIndex();
            }
            catch
            {
                // ignored
            }

            var schema = new Schema();

            schema.AddSortableTextField("Title");
            schema.AddTextField("Subtitle");
            schema.AddTextField("Description");
            var options = new Client.ConfiguredIndexOptions(
                new Client.IndexDefinition(prefixes: new [] { "Book:" })
                );

            client.CreateIndex(schema, options);
        }
        /// <summary>
        /// Creates the book index
        /// </summary>
        /// <returns></returns>
        public async Task CreateBookIndex()
        {
            // drop the index, if it doesn't exists, that's fine
            try
            {
                await _redisProvider.Database.ExecuteAsync("FT.DROPINDEX", "books-idx");
            }
            catch (Exception)
            {
                // books-idx didn't exist - don't do anything
            }

            var schema = new Schema();

            schema.AddSortableTextField("title");
            schema.AddTextField("subtitle");
            schema.AddTextField("description");
            schema.AddTagField("id");
            schema.AddTextField("authors.[0]");
            schema.AddTextField("authors.[1]");
            schema.AddTextField("authors.[2]");
            schema.AddTextField("authors.[3]");
            schema.AddTextField("authors.[4]");
            schema.AddTextField("authors.[5]");
            schema.AddTextField("authors.[7]");
            var options = new Client.ConfiguredIndexOptions(
                new Client.IndexDefinition(prefixes: new [] { "Book:" })
                );
            await _searchClient.CreateIndexAsync(schema, options);
        }
        internal static void CreateIndex <T>(this Client client)
        {
            PropertyInfo[] props = Helpers.GetModelProperties <T>();

            Schema scheme = new Schema();

            foreach (PropertyInfo prop in props)
            {
                prop.BuildField(scheme);
            }

            Client.ConfiguredIndexOptions indexOptions = new Client.ConfiguredIndexOptions(Client.IndexOptions.DisableStopWords | Client.IndexOptions.UseTermOffsets);
            client.CreateIndex(scheme, indexOptions);
        }
Esempio n. 4
0
        public void CreateCartIndex()
        {
            var db     = _redisProvider.Database;
            var client = new Client("cart-idx", db);

            try
            {
                db.Execute("FT.DROPINDEX", "cart-idx");
            }
            catch (Exception)
            {
                //do nothing, the index didn't exist
            }
            var schema = new Schema();

            schema.AddSortableTextField("UserId");
            var options = new Client.ConfiguredIndexOptions(new Client.IndexDefinition(prefixes: new[] { "Cart:" }));

            client.CreateIndex(schema, options);
        }
        public void CreateUserIndex()
        {
            var db     = _redisProvider.Database;
            var client = new Client("user-idx", db);

            try
            {
                db.Execute("FT.DROPINDEX", "user-idx");
            }
            catch
            {
                // do nothing
            }

            var schema = new Schema();

            schema.AddTagField("Email");
            var options = new Client.ConfiguredIndexOptions(new Client.IndexDefinition(prefixes: new[] { "User:" }));

            client.CreateIndex(schema, options);
        }