Is there a way to grab any query in RavenDB 4.0 either as an expression or as the lucene query?

49 views
Skip to first unread message

Bruno Lopes

unread,
Dec 3, 2017, 7:40:46 PM12/3/17
to ravendb
I want to be able to add something like ".Where(f => f._AllowedUserIds.Contains(currentUserId)" on all queries hitting indexes named Secure/Something.

Previously, on Raven 3.5, we had a server side extension which looked at the Lucene IndexQuery and added some extra clauses to filter out items.

On 4.0 there's no server side extensions, and the query that goes to ravendb is RQL.

Is there somewhere I can hook into to add the filters? I'm thinking perhaps adding it to the expression that's passed to the RavenQueryInspector which is then translated into RQL, since I don't see anywhere I could hook into the lucene query.

There's ".Customize(q => q.QueryOperation.IndexQuery.Query)", but that's the RQL query, which I dread of parsing to try and inject the where clauses (and I'm thinking there's no rql parser client side).

Oren Eini (Ayende Rahien)

unread,
Dec 4, 2017, 1:53:34 AM12/4/17
to ravendb
You can use OnBeforeQueryExecuted event.
This has QueryCustomization, which give you the actual DocumentQuery / AsyncDocumentQuery that you can use to mutate the query before sending it

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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bruno Lopes

unread,
Dec 4, 2017, 5:19:04 AM12/4/17
to RavenDB - 2nd generation document database
On 4.0?

I'm looking at

                store.OnBeforeQueryExecuted += (sender, args) =>
                {
                    args.QueryCustomization.BeforeQueryExecuted(q =>
                    {
                        Assert.Equal("Just dump this", q.Query);
                    });
                };

q.Query gives me RQL.

Am I looking at the wrong place?
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Dec 4, 2017, 5:20:46 AM12/4/17
to ravendb
Cast   args.QueryCustomization to IDocumentQuery<T> or IAsyncDocumentQuery<T> and use that
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Bruno Lopes

unread,
Dec 5, 2017, 4:55:24 AM12/5/17
to ravendb
Awesome, that works even better than I expected. 

Would it make sense to have a non-generic IDocumentQuery that has the non-expression-based methods? (the ones that take strings instead of expressions)?

I'm doing a bit of reflection to call IDocumentQuery<T> and then ignoring the type itself since I'm working directly with the field names.

--
You received this message because you are subscribed to a topic in the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/Yars9qdPDiQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+unsubscribe@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Dec 5, 2017, 5:01:44 AM12/5/17
to ravendb
It _has_ just strings API there, IIRC, no?
The problem is that we need to be able to call ToList() on that.

Bruno Lopes

unread,
Dec 5, 2017, 5:10:29 AM12/5/17
to ravendb
It has the strings api. But since I'm doing this for "all" requests, I don't know upfront what the T in IDocumentQuery<T> is.  

I was "asking" for methods like 

- TSelf ContainsAny(string fieldName, IEnumerable<object> values);
- TSelf Search(string fieldName, string searchTerms, SearchOperator @operator = SearchOperator.Or);

To be on non-generic interfaces.



Oren Eini (Ayende Rahien)

unread,
Dec 5, 2017, 6:20:58 AM12/5/17
to ravendb
Hm... Can you send a PR for that?

Bruno Lopes

unread,
Dec 7, 2017, 4:19:27 AM12/7/17
to ravendb
I can look into it, sure. 
Reply all
Reply to author
Forward
0 new messages