Marklogic lexicons: understanding cts:element-values - search

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!

Related

COBOL substring between two finite points

I understand that the string_variable(start:length) can be used to get a substring of a string given a starting point and substring length, however, I am finding that I often need to get a substring between a 'start' and 'end' point.
While I know I could always do this:
SUBTRACT start FROM end GIVING len
string(start:len)
It seems cumbersome to have to do so every time when I am writing programs that use this functionality often. Is there perhaps a quicker/built-in way of achieving this?
How about?
move str (start-pos : end-pos - start-pos + 1) to ...
You can subtract the first from the last, but you need to add 1 to get the correct length.
STRING is a statement name, as is START, and END is reserved. LENGTH is a function name. I avoid those in anything that looks like code.

If statement not behaving itself

I have a very simple if statement that is looking to see if $_FILES[] is set and if so create a variable. Here it is:
if(isset($_FILES['photo']['name'])){$image="yes";}
So if it finds the files is in fact set, give $image the value of yes. At the moment, regardless of if its set or not, the value is being passed to $image. Its driving me nuts. Doesnt matter if I drop the ['name'] part even. Ive been doing every incarnation of the if statement I can think of to make it behave but Im at a loss.
It turns out that checking to see if $_files isset will return a value in that even with no file being uploaded the array will contain information. If you were to do var_dump on $files['photos']['name'] you will see that the value for that bit of information is 0 and therefore when checking to see if its set you will get a positive response. This is how I overcame my problem:
$foo =$_FILES['photo']['name'];
$foopoo = $foo[0];
if (strlen($foopoo)>2){$image= "yes";}

Combination of AND , OR with NOT in grouping

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.

How do you specify range to end of list?

Consider the following statement:
process.text.readLines[3..<-1]
It seems like it should work. Essentially, strip off the first two elements of the array. However, the range operator is confused by the ending -1, since its less than -1. You can easily solve this problem by storing the array as a variable and replacing -1 with size() but that requires an extra line and the definition of a variable. Any other ideas how to express this easily?
I believe you could do:
process.text.readLines()[ 2..-1 ]
or:
process.text.readLines().drop( 2 )
This will also do the trick:
process.text.readLines().with { it[2..size()-1] }
It's longer than simply calling drop as suggested above, but it might read a little better depending on the larger context. with lets you get around defining a new variable.

An alternative to offest = "-1" in Expression Engine

Does anyne know how expression engine deals with a negative offset in a list of channel entries in EE?
as in
offset="-1"
If you use offset="-1" in {exp:channel:entries}, you'll get a major MySQL error (assuming you're logged in as a super admin or are capable of seeing errors).
It's unclear what your goal is from your question. If you expect a negative offset to reverse the order (like PHP string functions), you can use use the opposite sort value. The default is desc, so sort="asc" would be the reverse. Use a positive offset="X" to skip X entries.
If you're expecting an offset like in PHP array_slice where you're still going "forward" but a negative offset starts you X entries from the end, I don't believe there's a direct comparison.
The goal was to work with the preceding chanel entry on the same page as the current channel entry.
I managed to do it instead by pulling out the relevant entry_ids and processing them in php and then put them back in with a fixed_order attribute

Resources