Index field Enum

116 views
Skip to first unread message

Alexander Sidorov

unread,
Feb 3, 2012, 9:21:18 AM2/3/12
to rav...@googlegroups.com
Is there any special about using Enum as index field? My index works well till I end some enum field to IndexResult, add it to Map select statement and Store it. After that I get strange exception (very long exception message with index definition string). What am I doing wrong?

Oren Eini (Ayende Rahien)

unread,
Feb 3, 2012, 12:58:18 PM2/3/12
to rav...@googlegroups.com
It should work.
Without knowing the actual details of the error, we can't help your further.

Alexander Sidorov

unread,
Feb 5, 2012, 1:43:45 PM2/5/12
to rav...@googlegroups.com
Please look at the following failing test:

    public class Tests
    {
        [Test]
        public void QueryById()
        {
            var documentStore = new DocumentStore() { Url = "http://localhost:8081", Conventions = { DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites } };
            documentStore.Initialize();

            IndexCreation.CreateIndexes(typeof(SomeDocumentIndex).Assembly, documentStore);
        }
    }

    public class SomeDocument
    {
        public string Id { get; set; }
        public string Text { get; set; }
    }

    public enum SomeEnum
    {
        Value1 = 1,
        Value2 = 2
    }

    public class SomeDocumentIndex : AbstractIndexCreationTask<SomeDocument, SomeDocumentIndex.IndexResult>
    {
        public class IndexResult
        {
            public string Id { get; set; }
            public SomeEnum SomeEnum { get; set; }
        }
           
        public SomeDocumentIndex()
        {
            Map = docs => from doc in docs
                                      select new { Id = doc.Id, SomeEnum = SomeEnum.Value1 };

            Store(x => x.SomeEnum, FieldStorage.Yes);
        }
    }

2012/2/4 Oren Eini (Ayende Rahien) <aye...@ayende.com>

Oren Eini (Ayende Rahien)

unread,
Feb 6, 2012, 7:37:34 AM2/6/12
to rav...@googlegroups.com
The problem is that SomeEnum doesn't exists on the server.
Use a string instead. At any rate, this will be the behavior of the next build.

Alexander Sidorov

unread,
Feb 6, 2012, 8:07:18 AM2/6/12
to rav...@googlegroups.com
What do you mean by "use string instead"? Could you please provide an example?

2012/2/6 Oren Eini (Ayende Rahien) <aye...@ayende.com>

Oren Eini (Ayende Rahien)

unread,
Feb 6, 2012, 8:20:36 AM2/6/12
to rav...@googlegroups.com
  public SomeDocumentIndex()
        {
            Map = docs => from doc in docs
                                      select new { Id = doc.Id, SomeEnum = "Value1" };

            Store(x => x.SomeEnum, FieldStorage.Yes);
Reply all
Reply to author
Forward
0 new messages