ravendb - Searching by Entity Name and Last Modified Date -
i have number of commands stored in ravendb , implement icommand. want able search on metadata of last modified , raven-entity-name. doing multi map on each command below:
public class commandauditsearch_index : abstractmultimapindexcreationtask<commandauditsearch_index.results> { public class results { public string commandtype { get; set; } public datetime lastmodified { get; set; } } public commandauditsearch_index() { addmap<newemployeestartcommand>(employees => employees.select(x => new { commandtype = metadatafor(x).value<string>("raven-entity-name"), lastmodified = metadatafor(x).value<datetime>("last-modified") })); addmap<employeeleavercommand>(employees => employees.select(x => new { commandtype = metadatafor(x).value<string>("raven-entity-name"), lastmodified = metadatafor(x).value<datetime>("last-modified") })); index(results => results.commandtype, fieldindexing.analyzed); } }
i query follows:
session.query<commandauditsearch_index.results, commandauditsearch_index>() .where(x => x.commandtype == commandtype && x.lastmodified >= datetime.today).oftype<icommand>().tolist();
i know there index built raven tag (entity name) , last modified date cant seem figure out how results index above gives me.
can point me in right direction of static index don't have have multi maps above each command have query gives me results list of icommands?
thanks
paddy
a couple of points:
you don't need mark field analyzed unless going doing fulltext searching
search
query method. if usingwhere
, there no advantage analyzing index term.if looking metadata values in results, need them metadata instead of document data using
getmetadatafor
. reference here.as said, there's index need. easiest way query using
lucenequery
api.var tag = documentstore.conventions.gettypetagname(thecommand.gettype()); var results = session.advanced .lucenequery<icommand, ravendocumentsbyentityname>() .whereequals("tag", tag) .andalso() .wheregreaterthanorequal("lastmodified", datetime.today .touniversaltime()) .tolist(); foreach (var result in results) { var md = session.advanced.getmetadatafor(result); var entityname = md.value<string>("raven-entity-name"); var lastmodified = md.value<datetime>("last-modified"); // can see metadata if debug.writeline(md.tostring(formatting.indented)); }
Comments
Post a Comment