I am using cts:search like this:-
let $query :=
cts:or-query((
cts:field-word-query(
"Assignor Name", $assignorName
),
cts:field-word-query(
"Assignee Name", $assigneeName
)
))
for $patent in cts:search(fn:doc(), $query)[1 to 10]
return $patent
where $assignorName and $assigneeName is the input from the user. But when both $assignorName & $assigneeName are empty strings then it does not show any results. I want to show all the results when the user does not enter any input. How can I achieve this ?
More explicitly, you might write the query something like this:
cts:or-query((
if (not($assignorName)) then () else cts:field-word-query(
"Assignor Name", $assignorName),
if (not($assigneeName)) then () else cts:field-word-query(
"Assignee Name", $assigneeName) ))
It takes a while to get used to the idea that you can put an if-then-else expression practically anywhere. Sometimes it helps to think of it as ternary logic.
To get all results, you have to replace the current $query with cts:and-query(()). A cts:or-query(()) might work too by the way.
HTH!
Related
I need to search those elements who have space " " in their attributes.
For example:
<unit href="http:xxxx/unit/2 ">
Suppose above code have space in the last for href attribute.
I have done this using FLOWER query. But I need this to be done using CTS functions. Please suggest.
For FLOWER query I have tried this:
let $x := (
for $d in doc()
order by $d//id
return
for $attribute in data($d//#href)
return
if (fn:contains($attribute," ")) then
<td>{(concat( "id = " , $d//id) ,", data =", $attribute)}</td>
else ()
)
return <tr>{$x}</tr>
This is working fine.
For CTS I have tried
let $query :=
cts:element-attribute-value-query(xs:QName("methodology"),
xs:QName("href"),
xs:string(" "),
"wildcarded")
let $search := cts:search(doc(), $query)
return fn:count($search)
Your query is looking for " " to be the entirety of the value of the attribute. If you want to look for attributes that contain a space, then you need to use wildcards. However, since there is no indexing of whitespace except for exact value queries (which are by definition not wildcarded), you are not going to get a lot of index support for that query, so you'll need to run this as a filtered search (which you have in your code above) with a lot of false positives.
You may be better off creating a string range index on the attribute and doing value-match on that.
I have the following Test collection where each document looks like:
firstName: "Jeff",
lastname: "Harper",
scores:[ {'period':'week one', 'score':90},
{'period':'week two', 'score':85},
{'period':'week three','score':92},
{'period':'week four', 'score':87}
I would like to iterate through the scores array and console.log the score. As a trial, I have tried:
Test.find()forEach(function(doc){ console.log( doc.firstName ) } );
This works fine to print out the first name. If I would want to print the first score in the array object, i.e., I try the statement:
Test.find()forEach(function(doc){ console.log( doc.scores[0].score ) } );
which doesn't work. How do I gain access to the elements in the array of objects?
Thanks everyone for your input. Christian Fritz identified my problem. Now, I limit my search to only documents that have the object array. Both the forEach method and the fetch() method work now. However, Ethaan, I had to include an inner for-loop inside the primary for-loop to gain access to each internal score. Thanks for your help and your editing and the picture of the beautiful asian princess.
I have a question and maybe somebody can help me figure out what the best way would be to achieve the solution. What i wanted to do is the reverse of:
http://doc.silverstripe.com/framework/en/topics/datamodel#highlighter_745635
WHERE ("LastName" = 'Minnée' AND ("FirstName" = 'Sam' OR "Age" = '17'))
I want to get something along the lines of:
WHERE( ("LastName" = 'Minnée') OR ("FirstName" = 'Sam' AND "Age" = '17'))
Now i cannot find any way to achieve this effect seeing as i cannot add a filter within the filterAny
For now i am doing it with the get()->where( ... ) option but was more wondering with this question if their are alternative options without having to write normal SQL code.
As 'AND' has a higher priority it doesn't need to be in braces. You can just write it as:
WHERE( "LastName" = 'Minnée' OR "FirstName" = 'Sam' AND "Age" = '17')
But as far as I can tell on the first look there isn't a way to write this without using where(). Let us know if you find a way. For debuging you can display the generated SQL-Query by calling the function sql():
... get()->where( ... )->sql();
I understand that I can specify multiple values for my filter in a way such as:
xxx::get()->filter('FirstName', array('Sam', 'Sig'));
Which gives me the equivalent of:
... WHERE FirstName = 'Sam' OR FirstName = 'Sig'
However, there doesn't appear to be anyway of combining OR's with the modifiers ('LastVisited:GreaterThan' => '2011-01-01')
I need to be able to filter like so:
WHERE ExpiryDate > 29-11-2012 OR ExpiryDate IS NULL
Is what I am trying to achieve possible? I have read the docs but have not found the answer to my issue.
Thanks
You could always use the where() function if nothing else will do what you need.
xxx::get()->where("\"ExpiryDate\" > 29-11-2012 OR \"ExpiryDate\" IS NULL");
http://doc.silverstripe.org/framework/en/topics/datamodel#where-clauses
So I have something like this:
var xmlStatement:String = "xmlObject.node[3].#thisValue";
What mystery function do I have to use so that I can execute xmlStatement and get thisValue from that xmlObject? Like....
var attribute:String = mysteryFunction(xmlStatement);
P.S. I know eval() works for actionscript2, I need the as3 solution. :)
Unfortunately this is not possible in ActionScript 3. This however might be a solution: http://blog.betabong.com/2008/09/23/e4x-string-parser/
For your example it would be:
var attribute : String = String( E4X.evaluate( XMLList(xmlobject) , 'node[3].#thisValue' ) );