pass Lucene Query directly to Raven

152 views
Skip to first unread message

balazs

unread,
Aug 2, 2012, 2:27:40 PM8/2/12
to rav...@googlegroups.com
It would be really nice if one could pass a Lucene Query directly to Raven.  The idea being something like LuceneQuery<T, TIndexCreator>(Query luceneQuery).  I think it would be a much cleaner solution that intercepting the Query in AbstractIndexQueryTrigger and modifying it, (or reparsing the original query entirely) within that trigger, allowing the caller to bypass all of the Raven query parsing logic if they really need to.  I don't expect this would be used heavily, but it could be of real value to users who need low level control over the queries issued to Lucene.  Unfortunately certain domains like legal research are given to different kinds of search than, say, a restaurant review site.  In legal research you generally want to exhaust the set of all possible matches- "most relevant" or "best results" just doesn't cut it (though in 95% of other types of search, it does).  Certain things that are really performance abusive, like wildcards in quoted phrases, at the beginnings or ends of words, phrases in proximity searches, and wildcards in proximity searches, are highly sough after and expected in such searches.  Many of these types of requirements can be accommodated through manually constructing Lucene queries (in fact, we've already got code to do much of this).   While we could certainly do this directly with Lucene.Net, Raven is extremely useful in managing documents and Lucene.Net itself, even if many of our queries would directly bypass it's query parser/generator.

Oren Eini (Ayende Rahien)

unread,
Aug 2, 2012, 2:30:08 PM8/2/12
to rav...@googlegroups.com
You can get an instance to the current searcher using.

IndexSearcher currentIndexSearcher;
using (database.IndexStorage.GetCurrentIndexSearcher(index, out currentIndexSearcher))
{

balazs

unread,
Aug 2, 2012, 2:57:20 PM8/2/12
to rav...@googlegroups.com
Outside of a trigger (I see it's a public property of AbstractIndexQueryTrigger), how can I get a reference to database?

--Balazs--

Oren Eini (Ayende Rahien)

unread,
Aug 2, 2012, 2:58:34 PM8/2/12
to rav...@googlegroups.com
RequestResponder
Startup Task

Pretty much all of our stuff have it.

Balazs Czifra

unread,
Aug 2, 2012, 3:15:28 PM8/2/12
to rav...@googlegroups.com
There's a lot of "stuff", and some less documented than others ;)  Somehow grabbing it in a startup task and then caching it doesn't seem like the best of solutions (if that would even work).  What do you suggest?  I don't think any of the triggers would do (wouldn't occur at the point where I need the IndexSearcher), and I'd prefer not to go the route of a custom responder if I don't have to.  There doesn't seem to be any way to grab it from the documentstore or the session.

Oren Eini (Ayende Rahien)

unread,
Aug 2, 2012, 3:21:19 PM8/2/12
to rav...@googlegroups.com
You want to create your own Request Responder, that can handle custom queries.

Balazs Czifra

unread,
Aug 2, 2012, 3:48:01 PM8/2/12
to rav...@googlegroups.com
The main concern I have there is there is only one relevant line I would want to change, and it's buried pretty deep:
var luceneQuery = ApplyIndexTriggers(GetLuceneQuery()); (line 639 of Index.cs).

Because the lucene query doesn't even get generated until there, I don't think my responder would be of much help.  I could grab the index searcher within the responder and then execute the search myself, but then I'm left with trying to reimplement/copy-paste all the logic that's currently wrapped around the Query() method in the Index class (paging, get the documents from the store, etc) in my responder, which strikes me as a versioning/maintenance nightmare.  I hope I'm not being obnoxious on this topic, and I realize that it really is an edge case, but I keep thinking there has to be a more concise, elegant solution.

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 1:49:05 AM8/3/12
to rav...@googlegroups.com
Balazs,
Can you create a pull request with the change that you need?

Balazs Czifra

unread,
Aug 3, 2012, 12:31:43 PM8/3/12
to rav...@googlegroups.com
I think for now we're going to actually modify the Raven source and change the QueryBuilder class to use our parser instead.  It seems far easier than the number of changes that would be required to accommodate this in any other way.  This class is only used in one place, so I'm hoping there won't be too much pain in upgrading to future versions of Raven. 

While substituting the query parser is a good solution for us (we're really only interested in one), I would imagine that from a product standpoint it would be more ideal if the client could specify which parser they would like to be used on a query-by-query, or perhaps session by session, basis.  Parsers could be added as bundles.  This feature would require a good number of changes that I would hesitate to submit a pull request for since I have a feeling others would have strong feelings on how this should be implemented, if at all.

Oren Eini (Ayende Rahien)

unread,
Nov 14, 2012, 5:07:22 AM11/14/12
to rav...@googlegroups.com
The client & the server aren't running on the same process/machine.
You can do that using: LuceneQuery<T,TindexCreator().Where(query);

On Wed, Nov 14, 2012 at 11:44 AM, Xuan Nguyen Huu <nguyen...@gmail.com> wrote:
I also support the idea : "pass Lucene Query directly to Raven". 
And i think that a method like :  "LuceneQuery<T, TIndexCreator>(Query luceneQuery)" will be helpfull.
Because i want to use Lucence QueryParser class to build my Lucence Query from user input. Not by using string builder like this topic.

And I have a question: Can I work around by convert the Lucence Query to string , then pass it to LuceneQuery<T, TIndexCreator>(String query) method ???

PS: I m new to RavenDB, and sorry for my bad English because it is not my mother tounge language. 
Reply all
Reply to author
Forward
0 new messages