par Stephane Maillard » 10 Juin 2003 à 17:07
Bonjour,Attention le FTSearch ne retourne que 250 documents. Si mes souvenirs sont correct le FTSearch fonctionne en back end, arrière plan, donc sur la vue en cours d'affichage, front end ou avant plan, aucune modification ne sera effectuer.Je vous propose une solution un peu différente :Option PublicConst FT_SEARCH_SET_COLL = &H00000001Const FT_SEARCH_NUMDOCS_ONLY = &H00000002Const FT_SEARCH_REFINE = &H00000004Const FT_SEARCH_SCORES = &H00000008Const FT_SEARCH_RET_IDTABLE = &H00000010Const FT_SEARCH_SORT_DATE = &H00000020Const FT_SEARCH_SORT_ASCEND = &H00000040Const FT_SEARCH_TOP_SCORES = &H00000080Const FT_SEARCH_STEM_WORDS = &H00000200Const FT_SEARCH_THESAURUS_WORDS = &H00000400Const FT_SEARCH_EXT_RET_URL = &H00004000Const FT_SEARCH_EXT_DOMAIN = &H00020000Const FT_SEARCH_FUZZY = &H00080000Const DFLAGPAT_FOLDER$ = "(+-04n*F"Const DFLAGPAT_VIEWS_AND_FOLDERS$ = "-G40n"Const NOTE_CLASS_VIEW% = &H0008Const PKG_MISC% = &H0400Const ERR_NOT_FOUND = PKG_MISC + 4Const UPDATE_FORCE% = &H0001Dim batchSize As IntegerDim queryStr As StringDim dbHandle As LongDim status As IntegerDim searchHandle As LongDim searchOptions As LongDim retNumHits As LongDim numDocs As LongDim resultHandle As LongDim folderID As LongDim updateOptions As IntegerDim junkLong As LongDim junkBoolean As IntegerDim dbOpenFlag As IntegerDim searchHandleOpenFlag As IntegerDim searchResultsLockedFlag As IntegerDim folderNoteOpenFlag As IntegerDeclare Function apiDbOpen Lib "nnotes.dll" Alias "NSFDbOpen" (Byval PathName As String, rethDb As Long) As IntegerDeclare Function apiDbClose Lib "nnotes.dll" Alias "NSFDbClose" (Byval hDB As Long) As IntegerDeclare Function apiGetDBID Lib "nnotes.dll" Alias "NSFDbGetOpenDatabaseID" (Byval hDBU As Long) As LongDeclare Function apiFTOpenSearch Lib "nnotes.dll" Alias "FTOpenSearch" (rethSearch As Long) As IntegerDeclare Function apiFTCloseSearch Lib "nnotes.dll" Alias "FTCloseSearch" (Byval hSearch As Long) As IntegerDeclare Function apiFTSearch Lib "nnotes.dll" Alias "FTSearch" (Byval hDB As Long, phSearch As Long, Byval hColl As Integer, Byval query As String, Byval options As Long, Byval limit As Integer, Byval hlDTable As Integer, retNumDocs As Long, reserved As Long, rethResults As Long) As IntegerDeclare Function apiFTSearchExt Lib "nnotes.dll" Alias "FTSearchExt" (Byval hDB As Long, phSearch As Long, Byval hColl As Integer, Byval query As String, Byval options As Long, Byval limit As Integer, Byval hlDTable As Long, retNumDocs As Long, reserved As Long, rethResults As Long, retNumHits As Long, Byval Start As Long, Byval Count As Integer, Byval Arg As Integer, Byval hNames As Long) As IntegerDeclare Function apiIDEntries Lib "nnotes.dll" Alias "IDEntries" (Byval hTable As Long) As LongDeclare Function apiIDScan Lib "nnotes.dll" Alias "IDScan" (Byval hTable As Long, Byval fFirst As Integer, retID As Long) As IntegerDeclare Function apiIDDestroyTable Lib "nnotes.dll" Alias "IDDestroyTable" (Byval hTable As Long) As IntegerDeclare Function apiNIFFindDesignNoteExt Lib "nnotes.dll" Alias "NIFFindDesignNoteExt" (Byval hFile As Long, Byval noteName As String, Byval noteClass As Integer, Byval pszFlagsPattern As String, retNoteID As Long, Byval Options As Long) As IntegerDeclare Function apiNSFNoteUpdate Lib "nnotes.dll" Alias "NSFNoteUpdate" (Byval noteHandle As Long, Byval updateFlags As Integer) As IntegerDeclare Function apiNSFNoteClose Lib "nnotes.dll" Alias "NSFNoteClose" (Byval noteHandle As Long) As IntegerDeclare Function apiFolderDocAdd Lib "nnotes.dll" Alias "FolderDocAdd" (Byval hDataDB As Long, Byval hFolderDB As Long, Byval FolderNoteID As Long, Byval hTable As Long, Byval dwFlags As Long) As IntegerDeclare Function apiOSLoadString Lib "nnotes.dll" Alias "OSLoadString" (Byval hModule As Long, Byval StringCode As Integer, Byval retBuffer As String, Byval BufferLength As Integer) As IntegerDeclare Function apiOSLockObject Lib "nnotes.dll" Alias "OSLockObject" (Byval handle As Long) As LongDeclare Function apiOSUnLockObject Lib "nnotes.dll" Alias "OSUnlockObject" (Byval handle As Long) As IntegerFunction LimitlessFTSearch (Byval query As String, Byval destinationFolderName As String, Byval dbPath As String) As String LimitlessFTSearch = "" queryStr = query status = apiDbOpen(dbPath, DBHandle) If (status <> 0) Then LimitlessFTSearch = "apiDbOpen(): " + apiError(status) LimitlessFTSearch = LimitlessFTSearch + CleanUp() Exit Function Else dbOpenFlag = 1 End If status = apiFTOpenSearch(SearchHandle) If (status <> 0) Then LimitlessFTSearch = "apiFTOpenSearch(): " + apiError(status) LimitlessFTSearch = LimitlessFTSearch + CleanUp() Exit Function Else searchHandleOpenFlag = 1 End If status = apiNIFFindView(dbHandle, destinationFolderName, folderID) If (status <> 0) Then ' If (status = ERR_NOT_FOUND) Then' LimitlessFTSearch = {The folder named "} + destinationFolderName + {" doesn't exist. Cleaning up and exiting."}' End If LimitlessFTSearch = "apiNIFFindView(): " + apiError(status) LimitlessFTSearch = LimitlessFTSearch + CleanUp() Exit Function Else folderNoteOpenFlag = 1 End If Dim currentDocPointer As Long currentDocPointer = 0 retNumHits = 1 While (currentDocPointer <= retNumHits) status = RunSearch (currentDocPointer, batchSize) If (status <> 0) Then LimitlessFTSearch = "RunSearch(): apiFTSearchExt(): " + apiError(status) LimitlessFTSearch = LimitlessFTSearch + CleanUp() Exit Function End If %REM Print "............................................and the number of docs returned is...(actual)........... :" + Cstr(numDocs) Print "............................................and the number of total hits returned is..(poss)......... :" + Cstr(retNumHits)%END REM If (retNumHits <> 0) Then junkLong = apiOSLockObject(resultHandle) status = apiFolderDocAdd(dbHandle, 0, folderID, resultHandle, 0) If (status <> 0) Then LimitlessFTSearch = "apiFolderDocAdd(): " + apiError(status) LimitlessFTSearch = LimitlessFTSearch + CleanUpIDTable() LimitlessFTSearch = LimitlessFTSearch + CleanUp() Exit Function End If %REM numEntries& = apiIDEntries(resultHandle) Print "The table we have a handle on has this many entries : " + Cstr(numEntries&) boolean% = apiIDScan(resultHandle, 1, noteID&) While (boolean% = 1) Print "NoteID: " +Cstr(noteID&) boolean% = apiIDScan(resultHandle, 0, noteID&) Wend%END REM LimitlessFTSearch = LimitlessFTSearch + CleanUpIDTable() End If currentDocPointer = currentDocPointer + batchSize Wend LimitlessFTSearch = LimitlessFTSearch + CleanUp() End FunctionFunction CleanUp() As String CleanUp = "" If (searchHandleOpenFlag = 1) Then status = apiFTCloseSearch(SearchHandle) If (status <> 0) Then CleanUp = CleanUp + " - apiFTCloseSearch(): " + apiError(status) End If ' saveFolderNoteFlag = 1 ' If (saveFolderNoteFlag = 1) Then' updateOptions = UPDATE_FORCE' status = apiNSFNoteUpdate(folderID, updateOptions)' If (status <> 0) Then CleanUp = CleanUp + " - apiNSFNoteUpdate(): " + apiError(status)' End If ' If (folderNoteOpenFlag = 1) Then' status = apiNSFNoteClose(folderID)' End If 'Close the database, if needed. If (dbOpenFlag = 1) Then status = apiDbClose(DBHandle) If (status <> 0) Then CleanUp = CleanUp + " - apiDbClose(): " + apiError(status) End IfEnd FunctionFunction apiError (status As Integer) As String Dim Err_Mask As Integer Dim errorStr As String Err_Mask = &H00003fff status = status And Err_Mask errorStr = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" status = apiOSLoadString(0, status, errorStr , Len(errorStr) - 1) apiError = "apiError(): " + errorStrEnd FunctionFunction apiNIFFindView(Byval hFile As Long, Byval viewName As String, retNoteID As Long) As Integer apiNIFFindView = apiNIFFindDesignNoteExt(hFile, viewName, NOTE_CLASS_VIEW, DFLAGPAT_VIEWS_AND_FOLDERS, retNoteID, 0) End FunctionFunction RunSearch (Byval start As Long, Byval count As Integer) As Integer Dim collectionHandle As Integer Dim limit As Integer Dim idTableHandle As Long Dim reserved As Long Dim arg As Integer Dim namesHandle As Long collectionHandle = 0 limit = 0 idTableHandle = 0 reserved = 0 arg = 0 namesHandle = 0 searchOptions = FT_SEARCH_RET_IDTABLE RunSearch = apiFTSearchExt(dbHandle, searchHandle, collectionHandle, queryStr, searchOptions, limit, idTableHandle, numDocs, 0, resultHandle, retNumHits, start, count, arg, 0) End FunctionSub Initialize batchSize = 4900 dbOpenFlag = 0 searchHandleOpenFlag = 0 searchResultsLockedFlag = 0 folderNoteOpenFlag = 0 End SubFunction CleanUpIDTable() As String CleanUpIDTable = "" junkBoolean = apiOSUnlockObject(resultHandle) status = apiIDDestroyTable(resultHandle) If (status <> 0) Then CleanUpIDTable = CleanUpIDTable + " - apiIDDestroyTable(): " + apiError(status) CleanUpIDTable = CleanUpIDTable + CleanUp() Exit Function End IfEnd FunctionExemple d'utilisation :Créer un dossier 'test' par exemple.Dans un agent :Sub initialise dim s as new notessession dim db as notesdatabase set db = s.currentdatabase rc = LimitlessFTSearch("FIELD form=NomMasque", "test", db.FilePath) messagebox rcEnd SubAppel de la fonction :Query => Ce que vous voulez rechercherFolder => Le dossier ou vous voulez mettre les documents trouvédbpath => Le chemin d'accès à la base NotesDans le code vous avez la méthode pour ouvrir, fermer et traiter les erreurs API Notes.Attention : Plateforme Win32 uniquement.[%sig%]
Cordialement
Stéphane Maillard