Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

nosql - neo4j - pagination return same results even when skip and order by are specified

I'm implementing infinite scroll and trying to get new items every time the user reach the bottom of the page.

problem is, neo4j return nodes that were already returned.

I read that ORDER BY is must for this case, but it didn't help.

I tried follow the solution here: How to paginate query results with cypher?, and put the pagination clauses (LIMIT, SKIP...) before the WITH clause, but it didn't work. It also throw an error

the query:

MATCH(shops: Shop)
WHERE shops.title = ~ '(?i).*${search}.*'
WITH shops
ORDER BY shops.title asc
SKIP $skip
LIMIT $limit
MATCH(products: Product) < -[relation: SELL] - (shops)
RETURN shops, products, relation

how the query can guarantee new items on each request ?

*note - the limit is always 12, and skip is the items array length, the client app contain on the request.

EDIT 1 - IMAGES FROM THE DB OF THE DUPLICATION

it can be shown that a node with the same id, is returned from the two queries.

1ST page - skip 0, limit 12

1st page - skip 0, limit 12

2ND page - skip 12, limit 12

2ND page - skip 12, limit 12

question from:https://stackoverflow.com/questions/65873569/neo4j-pagination-return-same-results-even-when-skip-and-order-by-are-specified

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Neo4j doesn't have fallback when the order by is facing 2 or more nodes with the same value. I tried to order by the title Timer and there is several of Shops with this title. the work around was adding the fallback to another comparison.

ORDER BY shops.title, shops.id

wired that neo4j doesn't provide failsafe ( like, id of the node ), and resolving in sending the same node when skip is used.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...