ravendb - How to change the collection name on an index -
when save document has generic type dataview<customer>, i'm manually setting collection name "customers". however, i'm having trouble making index using abstractindexcreationtask non-default collection name. here's index:
public class customers_search : abstractindexcreationtask<dataview<customer>, customers_search.result> { public class result { public string query { get; set; } } public customers_search() { map = customers => customer in customers customer.data != null select new { query = asdocument(customer.data).select(x => x.value) }; index(x => x.query, fieldindexing.analyzed); } } when gets deployed, looks this:
from customer in docs.dataviewofcustomer customer.data != null select new { query = customer.data.select(x => x.value) } this doesn't work obviously, , if change dataviewofcustomer "customers" works fine.
i'd rather not have use non-type-checked (string) indexes deploy. is there way set collection name abstractindexcreationtask class?
update
since data class generic, made generic index fixes names.
public class dataviewquery<tentity> : abstractindexcreationtask<dataview<tentity>, dataviewqueryresult> { private readonly string _entityname; private readonly string _indexname; // fix collection name index name public override string indexname { { return _indexname; } } // fix collection name index query public override void execute(idatabasecommands databasecommands, documentconvention documentconvention) { var conventions = documentconvention.clone(); conventions.findtypetagname = type => typeof(dataview<tentity>) == type ? _entityname : documentconvention.findtypetagname(type); base.execute(databasecommands, conventions); } public dataviewquery(string entityname) { _entityname = entityname; _indexname = string.format("{0}/{1}", entityname, "query"); map = items => item in items item.data != null select new { query = asdocument(item.data).select(x => x.value) }; index(x => x.query, fieldindexing.analyzed); } } public class dataviewqueryresult { public string query { get; set; } } then can create specific index has configuration in it.
// sets collection type (dataview<customer>) index public class customerquery : dataviewquery<customer> { // sets collection name index public customerquery() : base(entityname.customers) { } }
you need configure in conventions. property configure findtypetagname
Comments
Post a Comment