Google AppEngine Search Ranking - google-app-engine

When I do a GAE search with limit=20, I am not getting the 20 highest-ranked results, and I am not sure if this is a bug or a known-limitation (feature).
Here are my top search results with limit=20 (where first number is the rank, second number is just a related-timestamp to make things easier to read):
rank 1589728448 2017-09-03 12:00:00
rank 1589778848 2017-09-02 22:00:00
rank 1589778848 2017-09-02 22:00:00
rank 1589778848 2017-09-02 22:00:00
rank 1589780648 2017-09-02 21:30:00
rank 1589786048 2017-09-02 20:00:00
rank 1589786048 2017-09-02 20:00:00
rank 1589804048 2017-09-02 15:00:00
rank 1589807648 2017-09-02 14:00:00
rank 1589807648 2017-09-02 14:00:00
rank 1589814848 2017-09-02 12:00:00
rank 1589814848 2017-09-02 12:00:00
rank 1589865248 2017-09-01 22:00:00
rank 1589870648 2017-09-01 20:30:00
rank 1589876048 2017-09-01 19:00:00
rank 1589879648 2017-09-01 18:00:00
rank 1590416048 2017-08-26 13:00:00
rank 1593852248 2017-07-17 18:30:00
rank 1594282448 2017-07-12 19:00:00
rank 1595326448 2017-06-30 17:00:00
And likewise, here are the best-ranking documents from a search with limit=1000:
rank 1589721248 2017-09-03 14:00:00
rank 1589728448 2017-09-03 12:00:00
rank 1589778848 2017-09-02 22:00:00
rank 1589778848 2017-09-02 22:00:00
rank 1589778848 2017-09-02 22:00:00
rank 1589780648 2017-09-02 21:30:00
rank 1589782448 2017-09-02 21:00:00
rank 1589786048 2017-09-02 20:00:00
rank 1589786048 2017-09-02 20:00:00
rank 1589804048 2017-09-02 15:00:00
rank 1589807648 2017-09-02 14:00:00
rank 1589807648 2017-09-02 14:00:00
rank 1589814848 2017-09-02 12:00:00
rank 1589814848 2017-09-02 12:00:00
rank 1589865248 2017-09-01 22:00:00
rank 1589870648 2017-09-01 20:30:00
rank 1589876048 2017-09-01 19:00:00
rank 1589876048 2017-09-01 19:00:00
rank 1589879648 2017-09-01 18:00:00
rank 1589890448 2017-09-01 15:00:00
rank 1590131648 2017-08-29 20:00:00
rank 1590304448 2017-08-27 20:00:00
rank 1590416048 2017-08-26 13:00:00
rank 1590419648 2017-08-26 12:00:00
rank 1593852248 2017-07-17 18:30:00
rank 1594037648 2017-07-15 15:00:00
rank 1594282448 2017-07-12 19:00:00
rank 1595326448 2017-06-30 17:00:00
Notice that there is definitely some overlap...but that limit=1000 returns higher-ranking documents that limit=20 omitted. Almost like limit=20 gave up before it found all the best documents.
Am I doing something wrong, or should I not expect limit=N to return the N-best results?
The Google Appengine Search docs state:
The rank of a document is a positive integer which determines the
default ordering of documents returned from a search.
As well as the following about cursors and limits:
A call to search() can only return a limited number of matching
documents. You can repeat the same search, using cursors or offsets to
retrieve the complete set of matching documents.
Support paging through the search results by returning only a portion
of the matched documents on each query (using offsets and cursors)
I am unclear how paging across results would work here, given that the first page of results (with limit=20) isn't actually guaranteed to be the first 20 results... :/

Related

Find Records in SQL not having a particular value

Hi All I need a help finding a query that will get all records form my table
where it does not contain a pair alarmtype where its value is 'RETURN' and another value heres my table:
AlarmType Day PointName
SENSOR 2017-09-02 00:00:00.000 20CHB01CE104XG95.UNIT2#NET0
RETURN 2017-09-02 00:00:00.000 20CHB01CE104XG95.UNIT2#NET0
RETURN 2017-09-02 00:00:00.000 20CHB01CE105XG95.UNIT2#NET0
SENSOR 2017-09-02 00:00:00.000 20CHB01CE105XG95.UNIT2#NET0
RETURN 2017-09-02 00:00:00.000 20CHB01CE106XG95.UNIT2#NET0
SENSOR 2017-09-02 00:00:00.000 20CHB01CE106XG95.UNIT2#NET0
RETURN 2017-09-02 00:00:00.000 20CHB01CE107XG95.UNIT2#NET0
SENSOR 2017-09-02 00:00:00.000 20CHB01CE107XG95.UNIT2#NET0
HIGH1 2017-09-02 00:00:00.000 20LBB20CP003.UNIT2#NET0
SENSOR 2017-09-02 00:00:00.000 20MAV10CL011.UNIT2#NET0
Now the answer I am looking for is the last 2 rows since they don't have any 'RETURN' Values
Any help will be greatly appreciated
Try this :
select *
from <table>
where pointName not in (select pointName from <table> where alarmType = 'return');
try this:
SELECT * FROM <table> WHERE alarmtype <> 'RETURN'

First TimeIn Last TimeOut for each employee for respective days

I have following table from which I want to extract the time calculated. I am looking to get the Hours Spent by each employee for each day.
CREATE TABLE Attendance
(
, EmpID INT
, TimeIn datetime
, TimeOut datetime
)
The sample record against this table I have is listed below.
EmpID | AttendanceTimeIN | AttendanceTimeOut
1 2017-04-01 9:00:00 2017-04-01 10:20:00
2 2017-04-01 9:00:00 2017-04-01 12:30:00
1 2017-04-01 10:25:00 2017-04-01 17:30:00
2 2017-04-01 13:26:00 2017-04-01 14:50:00
2 2017-04-01 15:00:00 2017-04-01 18:00:00
1 2017-04-02 9:00:00 2017-04-02 11:00:00
1 2017-04-02 11:10:00 2017-04-02 12:00:00
2 2017-04-02 9:00:00 2017-04-02 12:00:00
1 2017-04-02 12:50:00 2017-04-02 18:00:00
2 2017-04-02 12:51:00 2017-04-02 18:00:00
I want to get the First TimeIn and Last TimeOut of and employee for each day to calculate how many hours a specific employee have spent in office each day.
I'm bit confused that how to use Min/Max function so I can get both employees hours for each day.
The result set I am looking for should look like this.
EmpID | AttendanceTimeIN | AttendanceTimeOut
1 2017-04-01 9:00:00 2017-04-01 17:30:00
2 2017-04-01 9:00:00 2017-04-01 18:00:00
1 2017-04-02 9:00:00 2017-04-02 18:00:00
2 2017-04-02 9:00:00 2017-04-02 18:00:00
Any help would be highly appreciated.
Thank you
If your TimeIn and TimeOut are datetime type (which they should be!), this solution works with the tests I did:
SELECT
EmpID
, MIN(TimeIn)
, MAX(TimeOut)
FROM Attendance
GROUP BY EmpID, CAST(TimeIn AS DATE)
the GROUP BY clause means that there's one row for each employee and each day, since CASTing to DATE gets rid of the time part. MIN and MAX then just inherently work.

sql server combining date_time and smallint columns to derive datetime column in 12 hour format

I have a date_time column and hour_ending column,like below. How do i join them both together to derive a date_time column in 12 hour date format. my requirement is to join Table A with Table B using date_time as join key
TABLE A
DATE HOUR_ENDING
--- ----------
8/31/2016 12:00:00.000 AM 1
8/31/2016 12:00:00.000 AM 2
8/31/2016 12:00:00.000 AM 3
8/31/2016 12:00:00.000 AM 4
8/31/2016 12:00:00.000 AM 5
8/31/2016 12:00:00.000 AM 6
8/31/2016 12:00:00.000 AM 7
8/31/2016 12:00:00.000 AM 8
8/31/2016 12:00:00.000 AM 9
8/31/2016 12:00:00.000 AM 10
8/31/2016 12:00:00.000 AM 11
8/31/2016 12:00:00.000 AM 12
8/31/2016 12:00:00.000 AM 13
8/31/2016 12:00:00.000 AM 14
8/31/2016 12:00:00.000 AM 15
8/31/2016 12:00:00.000 AM 16
8/31/2016 12:00:00.000 AM 17
8/31/2016 12:00:00.000 AM 18
8/31/2016 12:00:00.000 AM 19
8/31/2016 12:00:00.000 AM 20
8/31/2016 12:00:00.000 AM 21
8/31/2016 12:00:00.000 AM 22
8/31/2016 12:00:00.000 AM 23
8/31/2016 12:00:00.000 AM 24
Table B (I need Table A to be like this)
8/31/2013 12:00:00 AM
8/31/2013 1:00:00 AM
8/31/2013 2:00:00 AM
8/31/2013 3:00:00 AM
8/31/2013 4:00:00 AM
8/31/2013 5:00:00 AM
8/31/2013 6:00:00 AM
8/31/2013 7:00:00 AM
8/31/2013 8:00:00 AM
8/31/2013 9:00:00 AM
8/31/2013 10:00:00 AM
8/31/2013 11:00:00 AM
8/31/2013 12:00:00 PM
8/31/2013 1:00:00 PM
8/31/2013 2:00:00 PM
8/31/2013 3:00:00 PM
8/31/2013 4:00:00 PM
8/31/2013 5:00:00 PM
8/31/2013 6:00:00 PM
8/31/2013 7:00:00 PM
8/31/2013 8:00:00 PM
8/31/2013 9:00:00 PM
8/31/2013 10:00:00 PM
8/31/2013 11:00:00 PM
9/1/2013 12:00:00 AM
You can use DATEADD() to adjust the dates from the A table using the hour offsets. Then, join table A to B using this adjusted timestamp.
SELECT *
FROM tableA a
INNER JOIN tableB b
ON DATEADD(HOUR, a.HOUR_ENDING, a.DATE) = b.DATE
By the way you should consider changing your table A design such that date and time are being stored together in a single column.

Data according to date in MSSQL

I have a data like this
RID Region StartDate EndDate
944 Canada 2016-01-09 00:00:00.000 2016-01-16 23:59:59.000
955 Canada 2016-01-17 00:00:00.000 2016-01-24 23:59:59.000
981 Canada 2016-02-01 00:00:00.000 2016-02-08 23:59:59.000
996 Canada 2016-02-09 00:00:00.000 2016-02-16 23:59:59.000
1006 Canada 2016-01-25 00:00:00.000 2016-01-31 23:59:59.000
1020 Canada 2016-02-17 00:00:00.000 2016-02-24 23:59:59.000
1030 Canada 2016-02-25 00:00:00.000 2016-02-29 23:59:59.000
1041 Canada 2016-03-01 00:00:00.000 2016-03-08 23:59:59.000
1046 Canada 2016-03-09 00:00:00.000 2016-03-16 23:59:59.000
1062 Canada 2016-03-17 00:00:00.000 2016-03-24 23:59:59.000
1073 Canada 2016-03-24 00:00:00.000 2016-03-31 23:59:59.000
1083 Canada 2016-04-01 00:00:00.000 2016-04-08 23:59:59.000
1105 Canada 2016-04-09 00:00:00.000 2016-04-16 23:59:59.000
1118 Canada 2016-04-17 00:00:00.000 2016-04-24 23:59:59.000
1128 Canada 2016-04-25 00:00:00.000 2016-04-30 23:59:59.000
1164 Canada 2016-05-01 00:00:00.000 2016-05-08 23:59:59.000
now i try to select data like this
select * from tab1 where Region='Canada'
and StartDate ='2016-01-09 00:00:00.000'
and EndDate ='2016-01-24 23:59:59.000'
desired result is
RID Region StartDate EndDate
944 Canada 2016-01-09 00:00:00.000 2016-01-16 23:59:59.000
955 Canada 2016-01-17 00:00:00.000 2016-01-24 23:59:59.000
but when i execute this query data is empty
any solution?
I think you were intending to restrict to a date range, but you actually restricted to two points in time instead. Try this query:
SELECT *
FROM tab1
WHERE Region = 'Canada' AND
StartDate >= '2016-01-09 00:00:00.000' AND
EndDate <= '2016-01-24 23:59:59.000'
Try this.
SELECT *
FROM tab1
WHERE Region = 'Canada'
AND StartDate >='2016-01-09 00:00:00.000'
AND EndDate <='2016-01-24 23:59:59.000'
The 'between' must work. I tried this. If in case it is not working, try convert function for those datetime columns.
SELECT *
FROM tab1
WHERE Region = 'Canada' AND
StartDate >= convert(datetime,'2016-01-09 00:00:00.000') AND
EndDate <= convert(datetime,'2016-01-24 23:59:59.000')

KDB: Union of time intervals

Any nifty ways of converting a series of (possibly overlapping) time intervals into a set of disjoint time intervals covering the same times?
Example:
interval1:(07:00:00;08:00:00)
interval2:(07:30:00;08:30:00)
interval3:(10:00:00;11:00:00)
Desired output:
((07:00:00;08:30:00) ; (10:00:00;11:00:00))
In a table context you can do something like:
q)d:([]st:07:00:00 07:30:00 10:00:00; et:08:00:00 08:30:00 11:00:00)
q)d
st et
-----------------
07:00:00 08:00:00
07:30:00 08:30:00
10:00:00 11:00:00
distinct update st:?[st<prev et;prev st;st], et:et^?[et>next st;next et;et] from d
st et
-----------------
07:00:00 08:30:00
10:00:00 11:00:00
Not sure if i'd call it nifty, but it's decent!

Resources