mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-05 20:20:59 +08:00
Added sorting [skip ci]
This commit is contained in:
@@ -141,6 +141,24 @@ hnswrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int no
|
||||
memmove(scan->orderByData, orderbys, scan->numberOfOrderBys * sizeof(ScanKeyData));
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare search candidate distances
|
||||
*/
|
||||
static int
|
||||
CompareSearchCandidateDistances(const ListCell *a, const ListCell *b)
|
||||
{
|
||||
HnswSearchCandidate *hca = lfirst(a);
|
||||
HnswSearchCandidate *hcb = lfirst(b);
|
||||
|
||||
if (hca->distance < hcb->distance)
|
||||
return 1;
|
||||
|
||||
if (hca->distance > hcb->distance)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the next tuple in the given scan
|
||||
*/
|
||||
@@ -216,10 +234,12 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Return remaining tuples and exit */
|
||||
/* TODO sort */
|
||||
/* Return remaining tuples */
|
||||
so->w = so->discarded;
|
||||
so->discarded = NIL;
|
||||
|
||||
/* Sort in reverse order since results are removed from end */
|
||||
list_sort(so->w, CompareSearchCandidateDistances);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -245,6 +265,8 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
|
||||
hc = llast(so->w);
|
||||
element = HnswPtrAccess(base, hc->element);
|
||||
|
||||
elog(INFO, "distance = %f", hc->distance);
|
||||
|
||||
/* Move to next element if no valid heap TIDs */
|
||||
if (element->heaptidsLength == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user