get index query is being executed on in IDocumentQueryListener.BeforeQueryExecuted

32 views
Skip to first unread message

Karl Cassar

unread,
Oct 28, 2014, 12:19:12 PM10/28/14
to rav...@googlegroups.com
Is it possible to get the name of the index and/or collection type that the query is being executed on, in the context of an IDocumentQueryListener.BeforeQueryExecuted?

The only parameter provided is the IDocumentQueryCustomization.

Thanks,
Karl

Chris Marisic

unread,
Oct 28, 2014, 12:31:27 PM10/28/14
to rav...@googlegroups.com
The collection part doesn't make sense, an index doesn't need to operate on any collection. Indexes can also operate on many collections. You would need to analyze the full index definition to determine this

It seems very reasonable that name would be available.

Oren Eini (Ayende Rahien)

unread,
Oct 28, 2014, 12:40:13 PM10/28/14
to ravendb
You can cast the IDocumentQueryCustomization to DocumentQuery<T>, and discover what it is working on from there.
From there, you can call GetIndexQuery(), and get the actual details.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" 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/d/optout.

Karl Cassar

unread,
Oct 29, 2014, 6:51:08 AM10/29/14
to rav...@googlegroups.com
Hi Oren,

The problem is that I don't "know" the generic type at that stage and cannot cast it. Is it possible to get it without knowing the generic type? I managed to get it using a very ugly workaround for now, as per below:


            var type = queryCustomization.GetType();
            var method= type.GetMethod("GetIndexQuery");
            object[] parameters = new object[1];
            parameters[0] = false;
            IndexQuery result= (IndexQuery)method.Invoke(queryCustomization,parameters);


However, I still couldn't locate the index name from the IndexQuery.  And what would happen if query is on a dynamic index?

Regards,
Karl

Oren Eini (Ayende Rahien)

unread,
Oct 29, 2014, 7:26:55 AM10/29/14
to ravendb
dynamic query = queryCustomization;
IndexQuery result = query.GetIndexQuery(false);

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--

Chris Marisic

unread,
Oct 29, 2014, 8:52:14 AM10/29/14
to rav...@googlegroups.com
It's hard for me to remember C# without dynamic, that was such an important addition.

Karl Cassar

unread,
Oct 29, 2014, 9:01:20 AM10/29/14
to rav...@googlegroups.com
I never used it before to be honest but I can imagine it's usefulness in such cases.

However, i still didnt find how I can get the actual index once I have the IndexQuery.  How can i get such information?

Regards,
Karl

Oren Eini (Ayende Rahien)

unread,
Oct 29, 2014, 9:07:50 AM10/29/14
to ravendb
The index?

get the IndexName property

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.

Karl Cassar

unread,
Oct 29, 2014, 9:09:45 AM10/29/14
to rav...@googlegroups.com
From where?  IndexQuery does not have a .IndexName property or method.  

Regards,
​Karl

Oren Eini (Ayende Rahien)

unread,
Oct 29, 2014, 9:13:38 AM10/29/14
to ravendb
dynamic query = queryCustomization;
var result = query.IndexName;

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--

Karl Cassar

unread,
Oct 29, 2014, 10:41:47 AM10/29/14
to rav...@googlegroups.com
Hi again,

The 'query' does not have a property named IndexName.  I tried to cast to a DocumentQuery<T> temporarily and it doesnt have .IndexName. Trying to do that gives a:

'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code

Additional information: 'Raven.Client.Document.DocumentQuery<ConceptTests_v2.RavenDb.SampleData.TestProduct>' does not contain a definition for 'IndexName'

Regards,
Karl

Oren Eini (Ayende Rahien)

unread,
Oct 29, 2014, 11:50:14 AM10/29/14
to ravendb
Sorry, the property name is IndexQueried

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--

Karl Cassar

unread,
Oct 29, 2014, 11:53:39 AM10/29/14
to rav...@googlegroups.com
Great, that works - thanks a lot as always!

Regards,
Karl
Reply all
Reply to author
Forward
0 new messages