RavenDB 2630 doesnot create index

18 views
Skip to first unread message

Valentyn Ponomarenko

unread,
May 25, 2013, 12:08:05 PM5/25/13
to rav...@googlegroups.com
I run following simple code which created couple of documents and index. Documents created sucessfully, but index doesn't...
At least, I don see it in RavenDB studio.

namespace RavenDBIndexTesting
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var documentStore = new DocumentStore {Url = "http://localhost:8300/"};
            documentStore.Initialize();

            using (var session = documentStore.OpenSession("TEST"))
            {
                    foreach (var i in new[] {1, 2, 3, 4, 5, 6,})
                    {
                        var post = new
                            {
                                Name = String.Format("Valentyn Ponomarenko{0}", i),
                                Text = String.Format("This is sample of the post text.{0}", i)
                            };

                        // Saving changes using the session API

                        session.Store(post);//, @"post\" + Guid.NewGuid());
                        // Operations against session

                    }

                    // Flush those changes
                    session.SaveChanges();
                }

                var postIndex = new IndexDefinitionBuilder<Post>()
                    {
                        Map = posts => from post in posts
                                       select new {post.Name}

                        //Index(x => x.Name,
                        //                FieldIndexing.Analyzed);
                    };

                documentStore.DatabaseCommands.PutIndex(@"TEST/PostIndex", postIndex);

                //IndexCreation.CreateIndexes(typeof(PostIndex).Assembly, documentStore);
                //documentStore.ExecuteIndex(new PostIndex());
            }
        }

        public class Post
        {
            public string Name { get; set; }
            public string Text { get; set; }
        }

        public class PostIndex : AbstractIndexCreationTask<Post>
        {
            public override string IndexName
            {
                get { return "PostIndex1"; }
            }

            public PostIndex()
            {
                Map = posts => from post in posts
                               select new {post.Name};

                Index(x => x.Name, FieldIndexing.Analyzed);
            }
        }
    }
}

Kijana Woodard

unread,
May 25, 2013, 12:29:57 PM5/25/13
to rav...@googlegroups.com
But IndexCreation.CreateIndexes worked?


--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Valentyn Ponomarenko

unread,
May 25, 2013, 12:39:59 PM5/25/13
to rav...@googlegroups.com
Looks like I'm wrong - it creates index but in System database. Why ?

суббота, 25 мая 2013 г., 19:29:57 UTC+3 пользователь Kijana Woodard написал:

Kijana Woodard

unread,
May 25, 2013, 12:53:57 PM5/25/13
to rav...@googlegroups.com
Specify the database in the connection string or when you OpenSession.

Valentyn Ponomarenko

unread,
May 25, 2013, 1:01:43 PM5/25/13
to rav...@googlegroups.com
I can put connection string to *.config file, because I need to connect to multiply database. 
The only way I see is documentStore.DefaultDatabase = DATABASE;

Are there any other way to set currect database ?




суббота, 25 мая 2013 г., 19:53:57 UTC+3 пользователь Kijana Woodard написал:

Kijana Woodard

unread,
May 25, 2013, 1:32:01 PM5/25/13
to rav...@googlegroups.com
store.OpenSession("db-name")

Valentyn Ponomarenko

unread,
May 25, 2013, 1:42:19 PM5/25/13
to rav...@googlegroups.com
The Session are create Index. 
To create Index you need DocumentStore which doesn't not about Database opened in session

var documentStore = new DocumentStore {Url = "http://localhost:8300"};
IndexCreation.CreateIndexes(typeof(PostIndex).Assembly, documentStore);

суббота, 25 мая 2013 г., 20:32:01 UTC+3 пользователь Kijana Woodard написал:

Kijana Woodard

unread,
May 25, 2013, 10:05:24 PM5/25/13
to rav...@googlegroups.com

Kijana Woodard

unread,
May 25, 2013, 10:06:49 PM5/25/13
to rav...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages