forked from open-webui/open-webui
		
	full search
This commit is contained in:
		
							parent
							
								
									46d0eff218
								
							
						
					
					
						commit
						3fa7718fa1
					
				
					 1 changed files with 37 additions and 14 deletions
				
			
		|  | @ -11,6 +11,7 @@ | ||||||
| 	import { | 	import { | ||||||
| 		deleteChatById, | 		deleteChatById, | ||||||
| 		getChatList, | 		getChatList, | ||||||
|  | 		getChatById, | ||||||
| 		getChatListByTagName, | 		getChatListByTagName, | ||||||
| 		updateChatById | 		updateChatById | ||||||
| 	} from '$lib/apis/chats'; | 	} from '$lib/apis/chats'; | ||||||
|  | @ -28,18 +29,34 @@ | ||||||
| 	let showDropdown = false; | 	let showDropdown = false; | ||||||
| 
 | 
 | ||||||
| 	onMount(async () => { | 	onMount(async () => { | ||||||
| 		if (window.innerWidth > 1280) { |         if (window.innerWidth > 1280) { | ||||||
| 			show = true; |             show = true; | ||||||
| 		} |         } | ||||||
| 
 | 
 | ||||||
| 		await chats.set(await getChatList(localStorage.token)); |         const chatList = await getChatList(localStorage.token); | ||||||
|  |         await enrichChatsWithContent(chatList); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     tags.subscribe(async (value) => { | ||||||
|  |         if (value.length === 0) { | ||||||
|  |             const chatList = await getChatList(localStorage.token); | ||||||
|  |             await enrichChatsWithContent(chatList); | ||||||
|  |         } | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     // Helper function to fetch and add chat content to each chat | ||||||
|  |     async function enrichChatsWithContent(chatList) { | ||||||
|  |         const enrichedChats = await Promise.all(chatList.map(async (chat) => { | ||||||
|  |             const chatDetails = await getChatById(localStorage.token, chat.id).catch(error => null); // Handle error or non-existent chat gracefully | ||||||
|  |             if (chatDetails) { | ||||||
|  |                 chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content | ||||||
|  |             } | ||||||
|  |             return chat; | ||||||
|  |         })); | ||||||
|  | 
 | ||||||
|  |         await chats.set(enrichedChats); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| 		tags.subscribe(async (value) => { |  | ||||||
| 			if (value.length === 0) { |  | ||||||
| 				await chats.set(await getChatList(localStorage.token)); |  | ||||||
| 			} |  | ||||||
| 		}); |  | ||||||
| 	}); |  | ||||||
| 
 | 
 | ||||||
| 	const loadChat = async (id) => { | 	const loadChat = async (id) => { | ||||||
| 		goto(`/c/${id}`); | 		goto(`/c/${id}`); | ||||||
|  | @ -323,13 +340,19 @@ | ||||||
| 						let title = chat.title.toLowerCase(); | 						let title = chat.title.toLowerCase(); | ||||||
| 						const query = search.toLowerCase(); | 						const query = search.toLowerCase(); | ||||||
| 
 | 
 | ||||||
| 						if (title.includes(query)) { | 						let contentMatches = false; | ||||||
| 							return true; | 						// Access the messages within chat.chat.messages | ||||||
| 						} else { | 						if (chat.chat && chat.chat.messages && Array.isArray(chat.chat.messages)) { | ||||||
| 							return false; | 							contentMatches = chat.chat.messages.some(message => { | ||||||
|  | 								// Check if message.content exists and includes the search query | ||||||
|  | 								return message.content && message.content.toLowerCase().includes(query); | ||||||
|  | 							}); | ||||||
| 						} | 						} | ||||||
|  | 
 | ||||||
|  | 						return title.includes(query) || contentMatches; | ||||||
| 					} | 					} | ||||||
| 				}) as chat, i} | 				}) as chat, i} | ||||||
|  | 
 | ||||||
| 					<div class=" w-full pr-2 relative"> | 					<div class=" w-full pr-2 relative"> | ||||||
| 						<button | 						<button | ||||||
| 							class=" w-full flex justify-between rounded-md px-3 py-2 hover:bg-gray-900 {chat.id === | 							class=" w-full flex justify-between rounded-md px-3 py-2 hover:bg-gray-900 {chat.id === | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Henry Holloway
						Henry Holloway