mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-10-31 21:44:12 +00:00 
			
		
		
		
	wip
This commit is contained in:
		
							parent
							
								
									4636768810
								
							
						
					
					
						commit
						67afe968b4
					
				
					 5 changed files with 85 additions and 19 deletions
				
			
		|  | @ -35,29 +35,16 @@ | ||||||
| 				"bio": { | 				"bio": { | ||||||
| 					"type": "string", | 					"type": "string", | ||||||
| 					"index": "analyzed", | 					"index": "analyzed", | ||||||
| 					"analyzer": "kuromoji" | 					"analyzer": "bigram" | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		}, | 		}, | ||||||
| 		"post": { | 		"note": { | ||||||
| 			"properties": { | 			"properties": { | ||||||
| 				"text": { | 				"text": { | ||||||
| 					"type": "string", | 					"type": "string", | ||||||
| 					"index": "analyzed", | 					"index": "analyzed", | ||||||
| 					"analyzer": "kuromoji" | 					"analyzer": "bigram" | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		}, |  | ||||||
| 		"drive_file": { |  | ||||||
| 			"properties": { |  | ||||||
| 				"name": { |  | ||||||
| 					"type": "string", |  | ||||||
| 					"index": "analyzed", |  | ||||||
| 					"analyzer": "kuromoji" |  | ||||||
| 				}, |  | ||||||
| 				"user": { |  | ||||||
| 					"type": "string", |  | ||||||
| 					"index": "not_analyzed" |  | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -34,7 +34,6 @@ export type Source = { | ||||||
| 		pass: string; | 		pass: string; | ||||||
| 	}; | 	}; | ||||||
| 	elasticsearch: { | 	elasticsearch: { | ||||||
| 		enable: boolean; |  | ||||||
| 		host: string; | 		host: string; | ||||||
| 		port: number; | 		port: number; | ||||||
| 		pass: string; | 		pass: string; | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ import MachineInfo from './utils/machineInfo'; | ||||||
| import DependencyInfo from './utils/dependencyInfo'; | import DependencyInfo from './utils/dependencyInfo'; | ||||||
| import serverStats from './daemons/server-stats'; | import serverStats from './daemons/server-stats'; | ||||||
| import notesStats from './daemons/notes-stats'; | import notesStats from './daemons/notes-stats'; | ||||||
| 
 | import db from './db/mongodb'; | ||||||
| import loadConfig from './config/load'; | import loadConfig from './config/load'; | ||||||
| import { Config } from './config/types'; | import { Config } from './config/types'; | ||||||
| 
 | 
 | ||||||
|  | @ -204,4 +204,6 @@ process.on('uncaughtException', err => { | ||||||
| // Dying away...
 | // Dying away...
 | ||||||
| process.on('exit', code => { | process.on('exit', code => { | ||||||
| 	Logger.info(`The process is going exit (${code})`); | 	Logger.info(`The process is going exit (${code})`); | ||||||
|  | 
 | ||||||
|  | 	db.close(); | ||||||
| }); | }); | ||||||
|  |  | ||||||
							
								
								
									
										63
									
								
								src/server/api/endpoints/notes/search.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								src/server/api/endpoints/notes/search.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,63 @@ | ||||||
|  | import $ from 'cafy'; | ||||||
|  | import * as mongo from 'mongodb'; | ||||||
|  | import Note from '../../../../models/note'; | ||||||
|  | import { ILocalUser } from '../../../../models/user'; | ||||||
|  | import { pack } from '../../../../models/note'; | ||||||
|  | import es from '../../../../db/elasticsearch'; | ||||||
|  | 
 | ||||||
|  | module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { | ||||||
|  | 	// Get 'query' parameter
 | ||||||
|  | 	const [query, queryError] = $.str.get(params.query); | ||||||
|  | 	if (queryError) return rej('invalid query param'); | ||||||
|  | 
 | ||||||
|  | 	// Get 'offset' parameter
 | ||||||
|  | 	const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); | ||||||
|  | 	if (offsetErr) return rej('invalid offset param'); | ||||||
|  | 
 | ||||||
|  | 	// Get 'limit' parameter
 | ||||||
|  | 	const [limit = 10, limitErr] = $.num.optional().range(1, 30).get(params.limit); | ||||||
|  | 	if (limitErr) return rej('invalid limit param'); | ||||||
|  | 
 | ||||||
|  | 	es.search({ | ||||||
|  | 		index: 'misskey', | ||||||
|  | 		type: 'note', | ||||||
|  | 		body: { | ||||||
|  | 			size: limit, | ||||||
|  | 			from: offset, | ||||||
|  | 			query: { | ||||||
|  | 				simple_query_string: { | ||||||
|  | 					fields: ['text'], | ||||||
|  | 					query: query, | ||||||
|  | 					default_operator: 'and' | ||||||
|  | 				} | ||||||
|  | 			}, | ||||||
|  | 			sort: [ | ||||||
|  | 				{ _doc: 'desc' } | ||||||
|  | 			] | ||||||
|  | 		} | ||||||
|  | 	}, async (error, response) => { | ||||||
|  | 		if (error) { | ||||||
|  | 			console.error(error); | ||||||
|  | 			return res(500); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if (response.hits.total === 0) { | ||||||
|  | 			return res([]); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		const hits = response.hits.hits.map(hit => new mongo.ObjectID(hit._id)); | ||||||
|  | 
 | ||||||
|  | 		// Fetch found notes
 | ||||||
|  | 		const notes = await Note.find({ | ||||||
|  | 			_id: { | ||||||
|  | 				$in: hits | ||||||
|  | 			} | ||||||
|  | 		}, { | ||||||
|  | 			sort: { | ||||||
|  | 				_id: -1 | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  | 
 | ||||||
|  | 		res(await Promise.all(notes.map(note => pack(note, me)))); | ||||||
|  | 	}); | ||||||
|  | }); | ||||||
|  | @ -18,6 +18,7 @@ import { IApp } from '../../models/app'; | ||||||
| import UserList from '../../models/user-list'; | import UserList from '../../models/user-list'; | ||||||
| import resolveUser from '../../remote/resolve-user'; | import resolveUser from '../../remote/resolve-user'; | ||||||
| import Meta from '../../models/meta'; | import Meta from '../../models/meta'; | ||||||
|  | import config from '../../config'; | ||||||
| 
 | 
 | ||||||
| type Type = 'reply' | 'renote' | 'quote' | 'mention'; | type Type = 'reply' | 'renote' | 'quote' | 'mention'; | ||||||
| 
 | 
 | ||||||
|  | @ -366,7 +367,7 @@ export default async (user: IUser, data: { | ||||||
| 			watch(user._id, data.reply); | 			watch(user._id, data.reply); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// (自分自身へのリプライでない限りは)通知を作成
 | 		// 通知
 | ||||||
| 		nm.push(data.reply.userId, 'reply'); | 		nm.push(data.reply.userId, 'reply'); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -427,4 +428,18 @@ export default async (user: IUser, data: { | ||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	// Register to search database
 | ||||||
|  | 	if (note.text && config.elasticsearch) { | ||||||
|  | 		const es = require('../../../db/elasticsearch'); | ||||||
|  | 
 | ||||||
|  | 		es.index({ | ||||||
|  | 			index: 'misskey', | ||||||
|  | 			type: 'note', | ||||||
|  | 			id: note._id.toString(), | ||||||
|  | 			body: { | ||||||
|  | 				text: note.text | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue