Is My Query correct? - objectify

I am trying to query using objectify to display a list of <Fight> with eventEid = 111. Is the below call correct? I ran it and it returns 0... but its strange because it looks right
Please note that eventEid is a long. Does that affect the query?
ofy().load().type(Fight.class).filter("eventEid", 111).list();

Make sure that eventEid is indexed property.
Filtering on unindexed properties returns no results.
https://developers.google.com/appengine/docs/java/datastore/queries#Filters

Related

Sorting a Calculated datasource in AppMaker

I have a Calculated datasource that's populated via an appscript function. When I display this datasource in a table, it works great but I can't click on the headers to sort them. I'd like to implement sorting.
I can see that sorting is specified in the Query object using Query.sorting.<fieldname>._ascending() and descending(). What I can't figure out is how to read the value that was set by these functions so I can determine how the user wants me to sort the results.
How do I determine what the desired sort is from the appmaker Query object?
I can't find any documentation around this either, but by inspecting the Query object, I found I can do this:
query.sorting.._order: true - ascending; false - descending; null - no sorting by this column.
query.sorting.._priority: 0 based priority, null - no sorting.
So assuming I have a "Title" column, by inspecting query.sorting.Title._order and query.sorting.Title._priority, I can tell if I should or how to sort by it.

Google Could Firestore order string field like number

i am trying to order a field in Firestore which is a string, but contains numbers. Can i somehow specify the ordering method or customise it?
** Edit 1:
The order i am getting is like this:
1 -> 10 -> 100 -> 101
But i want:
1 -> 2 -> 3 -> 4
If you have a need for strings to behave like numbers, you're using the wrong data type. Use numbers when you need numeric behavior. It sounds like you may have to rewrite all your documents and update your code to properly type the data.
In short, no, you can't do what you're asking (without making a change, or reordering the documents on the client).
I was trying to order items in my Firestore Recycler by querying a number value field and the app was crashing.
So i tried :
Query query = placesRef.orderBy( String.valueOf("likesNum"), Query.Direction.DESCENDING).limit(5);
And it worked. Although the compiler is saying String.valueOF() is not necessary, my problem is perfectly solved.
Maybe that helps someone with same issue.
query = placesRef.orderBy( String.valueOf("likesNum"), Query.Direction.DESCENDING).limit(5);
This only works because when you order by String, the limit is 9 items. Nothing will show up again after that so the best way is to store the field as a number.

How to use cursors for navigating to previous pages using GQL and the new gcloud-java API?

I'm using the new gcloud-java API (https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-datastore/src/main/java/com/google/cloud/datastore) for working with the Cloud Datastore. My specific question is on using GQL for pagination with cursors. I was able to page through the results one page at a time in the forward direction using cursors, but not having any luck with paging backwards.
Example Scenario:
Let's say I've 20 entities in a Kind with IDs 1 through 20. I have a page size of 5. Once I'm on the 3rd page (IDs 11 through 15), if I need to go one page back; i.e. retrieve IDs 6 through 10, what would be the correct GQL/sample code? Again, I prefer not to use offset with a number, but would like to use Cursors.
From what I can tell (actually tested), it looks like one needs to keep track of Start/End cursors for each page as they navigate in the forward direction, then use the saved cursors when there is a need to go back. I just want to make sure if this is the correct/only way or there is a simpler way to accomplish this.
Thanks in advance for your help.
If you add to your original query a sort by key (appended to the end of your "order by" clause), you should be able to reverse each property's sort order and use the latest cursor from your original query to get results in reverse.
Suppose you've iterated through some of the values from your forward query's QueryResults. You can call QueryResults's cursorAfter() method, which will return a cursor pointing right after the last result you saw from your original query. Now you can issue a new query (with the opposite sort order on each property, including the key property) using that cursor as the start cursor. You'll probably want to skip the first result, since it will be the last result you saw from the original query.

element-attribute-range-query fetching result but element-attribute-value-query is not fetching any result

I wanted to fetch the document which have the particular element attribute value.
So, I tried the cts:element-attribute-value-query but I didn't get any result. But the same element attribute value, I am able to get using cts:element-attribute-range-query.
Here the sample snippet used.
let $s-query := cts:element-attribute-range-query(xs:QName("tit:title"),xs:QName("name"),"=",
"SampleTitle",
("collation=http://marklogic.com/collation/codepoint"))
let $s-query := cts:element-attribute-value-query(xs:QName("tit:title"),xs:QName("name"),
"SampleTitle",
())
return cts:search(fn:doc(),($s-query))
The problem with range-query is it needs the range index. I have hundreds of DB's in multiple hosts. I need to create range indexes on each DB.
What could be the problem with attribute-value-query?
I found the issue with a couple of research.
Actually the result document is a french language document. It has the structure as follows. This is a sample.
<doc xml:lang="fr:CA" xmlns:tit="title">
<tit:title name="SampleTitle"/>
</doc>
The cts:element-attribute-value-query is a language dependent query. To get the french language results, then language needs to be mentioned in the option as follows.
cts:element-attribute-value-query(xs:QName("tit:title"),xs:QName("name"), "SampleTitle",("lang=fr"))
But cts:element-attribute-range-query don't require the language option.
Thanks for the effort.

how to display multiple select list after node submit

I have been reading around and just havent found any type of answer.
I have a multiple select list and need to take the the values of the multiple select and pass them to an API call.
But I dont understand how drupal renders the multiple select list and how to habdle this.
Can someone please explain this to me or if you have come across any docs that explain this, please point me in the right direction.
Also, when I try to write the select to the db, I always get a the value 1... never changes...
Any help is appreciated :)
Solved:
The Multiple select is stored in an associative array where the key value pair are taken from the key value of the list, this means that both the key and value get the same value.
I did this by using devels dvm(); function which displays the array in the message area after the node was saved.

Resources