I am trying to write Lucene query in RavenDB Index which will return results sorted by some field.
But still no success.
The Query looks like:
Language:EN AND Key:*car* AND sort=KEY
Question:
Is it possible at all to add sorting statement in query?
If yes, how the sorting syntax looks like?
No. The sort parameter is passed along with the query, but not within the query. If you're using the C# client API you'll have an operator OrderBy, otherwise you're most likely using the REST API, in which the sort parameter is being passed as an additional URL parameter
Related
I want to know if it's possible to pass in a list as a parameter in native queries.
When search up online, an article in Baeldung has exactly what I want to do:
Collection-Valued Positional Parameters usage
I did the exact same thing, except that in the article, they used "createQuery" and I used "createNativeQuery". Not sure if this is the reason why mine is not working.
CreateQuery means JPQL was passed in which is parsed and modified into SQL, which allows it to break the collection parameter into its components to pass each into the SQL statement. CreateNativeQuery uses your SQL which isn't modified, and JDBC doesn't understand collections so requires parameters broken up into individual arguments in the SQL. You have to do it yourself and dynamically build the SQL based on the number of parameters in the collection.
There are other questions with solutions that touch on other options, such as using SQL within criteria or JPQL queries that can let you get the best of both.
Using LUCENE inside of OrientDB seems to work fine, but there are very many LUCENE-specific query parameters that I would ordinarily pass directly to LUCENE (normally through Solr). The first one I need to pass is the result limiter such as SELECT * FROM V WHERE field LUCENE "Value" LIMIT 10.
If I use a value that only returns a few rows, I get the performance I expect, but if it has a lot of values, I need the limiter to get the result to return quickly. Otherwise I get an message in the console stating that The query would return more than 50000 records. Please consider using an index.
How do I pass additional LUCENE query paramters?
There's a known issue with the query parser which is in the process of being fixed, until then the following workaround should help:
SELECT FROM (
SELECT * FROM V WHERE Field LUCENE 'Value'
) LIMIT 10
Alternatively, depending on which client libraries you're using you may be able to set a limit using the out-of-band query settings.
I have three fields in the index; firstname, lastname, and isManager (1 or 0).
How do I go about using the QueryParser and add isManager (as a global filter) to 1 only so that I am effectively searching for the managers only?
So, if user searches for/passes in "firstname:john", I would like to add/append "isManager:1" as a global filter. One solution is to append "NOT isManager:0" to all the user's query string... but was wondering if there's any other preferred way.
Wrap the Query object you get back from QueryParer using FilteredQuery http://lucene.apache.org/core/4_0_0/core/org/apache/lucene/search/FilteredQuery.html
Using query filters is the right way to do it.
The problem with appending is that theoretically this is prone to query injection attacks (think SQL injection but for Lucene queries).
Does this gremlin script (executed via REST API of Neo4j) executes the sorting on the lucene index? Or are the nodes sorted in Neo4j?
g.idx('myIndex').get('name', 'aaa').sort{it.name}
Two additional questions:
1. How to set ordering? ASC/DESC
2. How to perform a fulltext search (LIKE). I already tried *, %, nothing worked
sort is a Groovy method. To reverse the order, use reverse:
g.idx('myIndex').get('name', 'aaa').sort{it.name}.reverse()
See:
http://groovy.codehaus.org/groovy-jdk/java/util/Collection.html
http://groovy.codehaus.org/groovy-jdk/java/util/List.html
Besides doing what espeed suggested, which is using Gremlin's facilities to sort etc, you may also be interested in passing additional instructions down to Lucene itself. This can be done by prefixing the second argument into get with a magic string %query%. Like so:
... .get(null, "%query% _start_node_id_:15815486")
The key argument can be null if you don't need to use it.
We have data in our graph that is indexed by Lucene and need to query it with a
Field Grouping
The example in the link above shows the Lucene syntax to be:
title:(+return +"pink panther")
I can't figure out how to send a request like that via http to the REST interface. Specifically, the space in the second term is causing me problems.
Our data is actually a list and I need to match on multiple items:
regions:(+asia +"north america")
Anyone have any ideas?
Update: For the record, the following url encoded string works for this particular query:
regions%3A%28%2Basia+%2B%22north+america%22%29
Isn't it enough to just URL encode the query using java.net.URLEncoder or something?