Lucene queries

classic Classic list List threaded Threaded
33 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Lucene queries

fschmidt
Administrator
We should improve how Lucene queries work.  We discussed this.  Assigning to you for feedback.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

Hugo <Nabble>
Administrator
I still think that the easiest would be a string query like this:
local query = [[ id = '1' and type = 'A' and (size = '2' or size = '3') ]]
If you really want to enforce the lucene concepts, then this would be possible:
local query = { 
    Query.term_AND{id='1', type='A'}, 
    Query.term_OR{size='2', size='3'} 
}
But I am not sure how we would handle the 'NOT' in the second case. What do you think?
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
Here is the lst of all query types:

http://lucene.apache.org/core/4_9_0/core/org/apache/lucene/search/Query.html

How is your string approach going to handle all these options?  It requires a whole new syntax, and in fact this has been done in the Lucene QueryParser (which I can't even find).  We shouldn't do this.

Your second solution doesn't make sense to me.  I don't even understand how the 2 queries combine.

The NOT actually isn't a problem because I changed NOT in Luan to only take a boolean value, so having NOT also take a query won't break anything.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

Hugo <Nabble>
Administrator
fschmidt wrote
The NOT actually isn't a problem because I changed NOT in Luan to only take a boolean value, so having NOT also take a query won't break anything.
If this approach works, then you can do it. Just to confirm, consider this:
local query = Query.term{id='1'} and not Query.term{type='B'} or Query.term{size='2'}
This would work, right?
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
Yes that would work.

Keeping assigned to me to do.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
In reply to this post by Hugo <Nabble>
I worked on this and I am not happy with my code.  Now I just want to force all queries to be strings that would go through the lucene QueryParser described here:

http://lucene.apache.org/core/4_9_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description

So a query would look like:

query = "type:cart or cart_user_id:" .. user.id

The user would have to learn this, but at least it is well documented and is similar to Google advanced search.

ok?
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

Hugo <Nabble>
Administrator
That's a relief. You can go ahead.
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
This didn't work because we map field names.

I went ahead and finished the Query approach in rev 288 and jeans rev 131.  I know you won't like it because it is verbose, but I don't think it is so bad.  I like that the implementation is extremely lightweight and that you can figure out everything by reading the code in Lucene.luan .
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

Hugo <Nabble>
Administrator
Okay. Can you please explain to me how to do ANDs and ORs with that?
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
Query.all{fld1="x",fld2="y"}
Query.any{fld1="x",fld2="y"}
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

Hugo <Nabble>
Administrator
This is okay. It is not perfect, but I think this could work.
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
closing thread
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

Hugo <Nabble>
Administrator
I see an issue with queries. We can't search for nulls. For example:
    Query.all{user_id = 12, parent_id = nil}
Of course we could use zero as the nil case and do:
    Query.all{user_id = 12, parent_id = 0}
Do you have another solution?
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
This is the way Lucene works.  So either use another value like "0" or "NIL", or read all values and filter for nil in code.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

Hugo <Nabble>
Administrator
Okay, closing thread.
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
In reply to this post by fschmidt
I will try query strings again.  If it works, I will support both styles.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
done in rev 313.  You can use Query.parse() or just use a string as a query.

Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

Hugo <Nabble>
Administrator
Okay. I added another query example to the lucene query tool (rev 317 luan).
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

fschmidt
Administrator
It looks fine.  We discusses quoting and I looked into it.  Lucene uses double-quotes, so you would do something like this:

'type:user AND name:"Joe Smith"'
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Lucene queries

Hugo <Nabble>
Administrator
Okay, it works. Thanks.
12