forked from cory/tildefriends
		
	Proof of concept full text search.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3978 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		| @@ -427,12 +427,38 @@ class TfElement extends LitElement { | ||||
| 		this.load(); | ||||
| 	} | ||||
|  | ||||
| 	async search(event) { | ||||
| 		this.messages = []; | ||||
| 		this.messages_by_id = {}; | ||||
| 		let query = this.renderRoot.getElementById('search').value; | ||||
| 		console.log('Searching...'); | ||||
| 		let results = await tfrpc.rpc.query(` | ||||
| 				SELECT messages.* | ||||
| 				FROM messages_fts(?) | ||||
| 				JOIN messages ON messages.rowid = messages_fts.rowid | ||||
| 				JOIN json_each(?) AS following ON messages.author = following.value | ||||
| 				ORDER BY timestamp DESC limit 100 | ||||
| 			`, | ||||
| 			[query, JSON.stringify(this.allFollowing)]); | ||||
| 		console.log('Done.'); | ||||
| 		this.process_messages(results); | ||||
| 		await this.finalize_messages(); | ||||
| 		this.renderRoot.getElementById('search').value = ''; | ||||
| 	} | ||||
|  | ||||
| 	search_keydown(event) { | ||||
| 		if (event.keyCode == 13) { | ||||
| 			this.search(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	render() { | ||||
| 		let self = this; | ||||
| 		let tabs = html` | ||||
| 			<div> | ||||
| 				<input type="button" value="News" ?disabled=${self.tab == 'news'} @click=${event => self.tab = 'news'}></input> | ||||
| 				<input type="button" value="Connections" ?disabled=${self.tab == 'connections'} @click=${event => self.tab = 'connections'}></input> | ||||
| 				<input type="button" value="Search" ?disabled=${self.tab == 'search'} @click=${event => self.tab = 'search'}></input> | ||||
| 			</div> | ||||
| 		`; | ||||
| 		let profile = this.hash.startsWith('#@') ? | ||||
| @@ -455,6 +481,13 @@ class TfElement extends LitElement { | ||||
| 				${tabs} | ||||
| 				<tf-connections .users=${this.users} .connections=${this.connections} .broadcasts=${this.broadcasts}></tf-connections> | ||||
| 			`; | ||||
| 		} else if (this.tab === 'search') { | ||||
| 			let search = html` | ||||
| 				<input type="text" id="search" @keydown=${this.search_keydown}></input> | ||||
| 				<input type="button" value="Search" @click=${this.search}></input> | ||||
| 				${this.messages?.map(x => html`<tf-message .message=${x} whoami=${this.whoami} .users=${this.users}></tf-message>`)} | ||||
| 			`; | ||||
| 			return html`${tabs}${search}`; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user