test:1 AND NOT bool:true
returns 5 documents
but
test:1 AND (NOT bool:true)
returns 0 documents
Why?
Please Explain me the value of parentheses in lucene query formation
When you place (NOT bool:true) in parentheses it becomes a subquery, which is executed independent of the query test:1. NOT clauses in Lucene ONLY remove elements from the result set, they don't find anything. In SQL, for instance, you implicitly start with every value available, and filter elements which don't match clauses out. In Lucene, you start with nothing, and find results based on the clauses. The query NOT bool:true tells it what not to match, but doesn't give Lucene anything to find and return. Any query of the form:
(any query finding results) AND (NOT something)
Will find zero results, because, on it's own, NOT something finds nothing, and (something) AND (nothing) returns nothing. You can perform a search like that, by getting all values first, before the lonely NOT clause, like:
test:1 AND (*:* AND NOT bool:true)
However, that will perform very poorly, and your first example:
test:1 AND NOT bool:true
Is definitely the correct one.
Related
Can you tell me, please?
Why does the mysql2 value substitution not work inside the IN operator?
I do this, but nothing works.
Only the first character of the array is being substituted (number 6)
"select * from products_categories WHERE category_id IN (?)", [6,3]);
You can do it like this, of course:
IN(?,?,?,?,?,?,?,?,?,?) [6,3,1,1,1,1,1,1,1,1,1]
But that's not right, I thought that the IN should be automatically substituted from an array =(
I haven't used this, but my gut feeling tells that array items map to question marks based on indexes, so in your case 6 binds to first ? and 3 looks for another one, but doesn't find.
If I were you, I'd try to make sure that my first array item is then actually array, so I'd rewrite it:
"select * from products_categories WHERE category_id IN (?)", [[6,3]]);
I suspect you are using this with .execute(), which is short for prepared statements "prepare first if never executed before"+execute. While api is very similar to .query() one biggest difference is that in case of prepared statement only parameters are sent at execution time, unlike .query() where whole query text is interpolated with all parameters on the client. As a result, you need to send exactly the number of parameters as you have number of placeholders in original query text ( in you example - one ?). The whole [6,3,1,1,1,1,1,1,1,1,1] is treated as one parameter and sent to server as "6,3,1,1,1,1,1,1,1,1,1" string ( because during prepare step that parameter was likely reported by server as VAR_CHAR )
The solution is 1) use .query() and interpolate on the client or 2) build enough ?s dynamically and prepare different PS for different number of IN parameters
I've been trying to create a filter matching the end of the whole field text.
For example, taking a text field with the text: the brown fox jumped over the lazy dog
I would like it to match with a query that searches for fields with values ending with g. Something like:
{
"search":"*",
"queryType":"full",
"searchMode": "any",
...
"filter":"search.ismatchscoring('/g$/','MyField')"
}
The result is only records where MyField contains values with words composed by a the single g character anywhere on the string.
Using the filter directly also produces no results:
{
"search":"*",
"queryType":"full",
"searchMode": "any",
...
"filter":"MyField eq '*g'"
}
As far as I can see, the tokenization will always be the base for the search and filter, which means that on the above query, $ is completely ignored and matches will be by word, not by field.
Probably I could use the keyword_v2 analyzer on this field but then I would lose the tokenizarion that I use when searching normally.
One possible solution could be defining a second field in your index, with the same value as ‘MyField’, but with a different analyzer (e.g. keyword_v2). That way you may still search over the original field while filtering over the other.
Regardless, you might have simplified the filter for the sake of the example, but otherwise it seems redundant to use search.ismatchscoring() when not combining with another filter clause via ‘or’ – one can use the search parameter directly.
Moreover, regex might not be working because the default queryType for search.ismatchscoring() is simple, not full - please see docs here
I am trying to understand the usage of
cts:element-values($element-names as xs:QName*,[$start as xs:anyAtomicType?])
I was under the impression that the above function returns values from the specified element value lexicon, starting with $start.
On Querying:
cts:element-values(xs:QName("ts:title"), "He")
I was expecting results starting with "He" only, but I have also got results such as:
(as I scroll down)
I Feel Fine
I Get Around
I would like to know what exactly does $start specify ?
Think of $start not as a starting prefix but as a starting location in the list. You're getting all the values from that point onward.
To limit by prefix you want to use cts:element-value-match which accepts a $pattern. http://docs.marklogic.com/cts:element-value-match
cts:element-values and the like return values greater or equal to $start value. It really is just a start place for all values, until limit is depleted.
If you are looking for a function that returns values matching a particular pattern, you probably want to use cts:element-value-match instead:
cts:element-value-match(xs:QName("title"), "He*")
HTH!
I am newest in Lucene.
I'm using Lucene.NET version 2.9.4.
What is the difference between these queries?
the first is:
title:hello AND tags:word
the second is:
+title:hello +tags:word
I testing a software, and I note that the first returns 3 records, and the second returns many records.
I observe that the first returns records where title and tags fields are fuel, but the second returns records where title and tags can be empty.
Is it the difference?
There is no difference between the two. clause1 AND clause2 is effectively shorthand for +clause1 +clause2
Similarly: clause1 clause2 = clause1 OR clause2
Note, there is really no equivalent for +clause1 clause2 using the boolean operators.
Are you sending the query over the Internet, if you are and not urlencoding the request correctly it could be misinterting the '+' as an encoded space and therefore lucene just runs the second query as if the +'s not there which would just OR the two parts and give the results you get.
title:hello tags:word
I'm trying to use IxSet for database-like purposes, so I've built an index of items and I need to do exact match on some field.
Query operator (#=) http://hackage.haskell.org/packages/archive/ixset/1.0.2/doc/html/Data-IxSet.html#v:-64--61- returns an IxSet a type, but I need only to either get 1 or 0 results. To check if it's 0 results, I do null items on that, but how do I get first item?
Due to description of IxSet type http://hackage.haskell.org/packages/archive/ixset/1.0.5/doc/html/Data-IxSet.html#t:IxSet I don't see any typeclass that has operation like head or fst.
Ok, found an answer. You should use some available function like getOne http://hackage.haskell.org/packages/archive/ixset/1.0.5/doc/html/Data-IxSet.html#v:getOne , for example.
p.s.: I find that a bit strange to first create your type from list of items and then add operations that duplicate list-operations, but maybe I'm just newbie :)