IsSorted property Read-only. Indicates whether the documents in a collection are sorted. A collection is sorted only when it results from a full-text search of a database.
Since getting having an unsorted DocumentCollection is generally a pain, I've written some code that's pretty quick in sorting these documents on the fly. This uses a QuickSort algorithm, instead of the much slower bubble sorts that seem to be floating out here...I actually borrowed the CollectionToArray code from this board a while back, but it also used a bubble sort routine that was way too slow.This code should be able to be used as is. I've used this method in several DB's with no changes since the initial write. The only thing you should have to change is the variable which tells it which field to sort on (explained below)...Sub CollectionToArray ( dc As NotesDocumentCollection) Dim doc As NotesDocumentDim k As Longk = dc.CountIf k<>0 ThenRedim da( 1 To k+1) As NotesDocumentSet doc = dc.GetFirstDocumentFor i=1 To kSet da(i) = docSet doc = dc.GetNextDocument(doc)NextEnd If'Need to add a value at the end that will always be greater than all other valuesSet da(k+1) = dirDB.CreateDocumentda(k+1).Lastname = "ZZZZZZZZ"End SubFunction swap(i As Integer,j As Integer) As VariantDim temp As NotesDocumentSet temp = da(i)Set da(i) = da(j)Set da(j) = tempEnd FunctionSub QuickSort (leftpos As Integer, rightpos As Integer)Dim i As IntegerDim j As IntegerDim pivot As StringIf (leftpos < rightpos) Theni=leftposj=rightpos + 1pivot = da(leftpos).GetFirstItem(key).Text DoDo i=i+1Loop While da(i).GetFirstItem(key).Text<pivot And i<=rightposDoj=j-1 Loop While da(j).GetFirstItem(key).Text > pivot And j>=leftposIf (i<j) ThenCall swap(i, j)End IfLoop While (i<j)Call swap(leftpos,j)Call QuickSort(leftpos,j-1)Call QuickSort(j+1,rightpos)End IfEnd SubThese need to be public variables, so place them in your "Declarations":Dim s As NotesSessionDim db As NotesDatabase 'The current databaseDim da As VariantConst key = "LastName" 'This the name of the FIELD you want to sort onNow, how to use this stuff...In your Initialize, or wherever you're calling this from:1) Get your DocumentCollection (here: dc) 2) Call CollectionToArray(dc) 'just creates an array of your documents so that we can re-order them3) Call QuickSort(Lbound(da), Ubound(da)-1) 'actually sorts your documents4) Redim Preserve da( 1 To Ubound(da)-1) As NotesDocument 'just chops off the 'ZZZZZ' value we needed as a 'high' value (see CollectionToArray routine)5) Forall doc In da ... End ForAll 'Use this to loop through your sorted documentsRemember, the DocumentArray (da) is just an array of documents, so you can reference the 'doc' in your ForAll and any of it's properties, fields, etc. just like any other document.Let me know if you have any problems, or just to let me know you found this useful...
Bist Du Dir sicher, dass es nicht sortiert ist (nach irgendeiner obskuren Sortierregel)? Weil die Notes-Hilfe meint, dass Ergebnisse einer Suche sehr wohl sortiert sind.ZitatIsSorted property Read-only. Indicates whether the documents in a collection are sorted. A collection is sorted only when it results from a full-text search of a database.
FT_DATE_ASC (64) sorts by document date in ascending order.FT_DATE_DES (32) sorts by document date in descending order.FT_DATECREATED_ASC (1543) sorts by document creation date in ascending order.FT_DATECREATED_DES (1542) sorts by document creation date in descending order.FT_SCORES ( sorts by relevance score (default).
Hi,ich habe mir mal in grauer Vorzeit was aus dem Web gefischt.ZitatSince getting having an unsorted DocumentCollection is generally a pain, I've written some code that's pretty quick in sorting these documents on the fly. This uses a QuickSort algorithm, instead of the much slower bubble sorts that seem to be floating out here...I actually borrowed the CollectionToArray code from this board a while back, but it also used a bubble sort routine that was way too slow.This code should be able to be used as is. I've used this method in several DB's with no changes since the initial write. The only thing you should have to change is the variable which tells it which field to sort on (explained below)...Sub CollectionToArray ( dc As NotesDocumentCollection) Dim doc As NotesDocumentDim k As Longk = dc.CountIf k<>0 ThenRedim da( 1 To k+1) As NotesDocumentSet doc = dc.GetFirstDocumentFor i=1 To kSet da(i) = docSet doc = dc.GetNextDocument(doc)NextEnd If'Need to add a value at the end that will always be greater than all other valuesSet da(k+1) = dirDB.CreateDocumentda(k+1).Lastname = "ZZZZZZZZ"End SubFunction swap(i As Integer,j As Integer) As VariantDim temp As NotesDocumentSet temp = da(i)Set da(i) = da(j)Set da(j) = tempEnd FunctionSub QuickSort (leftpos As Integer, rightpos As Integer)Dim i As IntegerDim j As IntegerDim pivot As StringIf (leftpos < rightpos) Theni=leftposj=rightpos + 1pivot = da(leftpos).GetFirstItem(key).Text DoDo i=i+1Loop While da(i).GetFirstItem(key).Text<pivot And i<=rightposDoj=j-1 Loop While da(j).GetFirstItem(key).Text > pivot And j>=leftposIf (i<j) ThenCall swap(i, j)End IfLoop While (i<j)Call swap(leftpos,j)Call QuickSort(leftpos,j-1)Call QuickSort(j+1,rightpos)End IfEnd SubThese need to be public variables, so place them in your "Declarations":Dim s As NotesSessionDim db As NotesDatabase 'The current databaseDim da As VariantConst key = "LastName" 'This the name of the FIELD you want to sort onNow, how to use this stuff...In your Initialize, or wherever you're calling this from:1) Get your DocumentCollection (here: dc) 2) Call CollectionToArray(dc) 'just creates an array of your documents so that we can re-order them3) Call QuickSort(Lbound(da), Ubound(da)-1) 'actually sorts your documents4) Redim Preserve da( 1 To Ubound(da)-1) As NotesDocument 'just chops off the 'ZZZZZ' value we needed as a 'high' value (see CollectionToArray routine)5) Forall doc In da ... End ForAll 'Use this to loop through your sorted documentsRemember, the DocumentArray (da) is just an array of documents, so you can reference the 'doc' in your ForAll and any of it's properties, fields, etc. just like any other document.Let me know if you have any problems, or just to let me know you found this useful...Das habe ich in ein paar DBs schon verwendet. Läuft bisher ohne Probleme. Axel
Zitat von: m3 am 21.06.05 - 10:39:51 Bist Du Dir sicher, dass es nicht sortiert ist (nach irgendeiner obskuren Sortierregel)? Weil die Notes-Hilfe meint, dass Ergebnisse einer Suche sehr wohl sortiert sind.ZitatIsSorted property Read-only. Indicates whether the documents in a collection are sorted. A collection is sorted only when it results from a full-text search of a database.Das sind die Sortieroptionen einer Volltextsuche.ZitatFT_DATE_ASC (64) sorts by document date in ascending order.FT_DATE_DES (32) sorts by document date in descending order.FT_DATECREATED_ASC (1543) sorts by document creation date in ascending order.FT_DATECREATED_DES (1542) sorts by document creation date in descending order.FT_SCORES ( sorts by relevance score (default).In der Regel sind die aber nicht zu gebrauchen.Axel
pivot = da(leftpos).GetFirstItem(key).Text