recently got to use meilisearch — a search system that is just like elasticsearch, but for smaller data amounts and easier to get to and start using. used it in an environment of typescript (node.js) and a self-hosted instance of meilisearch
first of all, it's so much easier to set this whole thing up than i thought it would be. although, i need to say that the whole "second-ish database that is constantly indexed" thing is new to me, so i had to understand that. basically, all you have to do is to addDocuments into your index instance of the meilisearch (and update it every time any document is created/edited/deleted on the main database so both dbs are in sync), probably updateTypoTolerance so you can search and accept a few typos and then simply index.search('hello')!
const index = meilisearch.index('messages')
const messages = [
{ global_id: 1, chat_id: 10, message_id: 1, from: { user_id: 1, first_name: 'John', last_name: 'Doe' }, text: 'Hello world!' },
{ global_id: 2, chat_id: 10, message_id: 2, from: { user_id: 2, first_name: 'Jane', last_name: 'Doe' }, text: 'Hi!' },
{ global_id: 3, chat_id: 10, message_id: 3, from: { user_id: 1, first_name: 'John', last_name: 'Doe' }, text: 'How are you?' },
...
]
const response = await index.addDocuments(messages, {
primaryKey: 'global_id'
})
const response = await index.search('hello', {
attributesToSearchOn: ['text'],
filter: 'from.user_id = 1 AND chat_id = 10'
})
i've been thinking about creating at least my own API for my own messenger (tm), but i've never thought about the search system. like, how the search bar in the telegram even work? i could not understand it until i tried out meilisearch. it's definitely a good experience overall, would recommend, ign, blah-blah-blah. wanna experiment with some other stuff more, probably will and probably will post it on here. stay tuned!
first of all, it's so much easier to set this whole thing up than i thought it would be. although, i need to say that the whole "second-ish database that is constantly indexed" thing is new to me, so i had to understand that. basically, all you have to do is to addDocuments into your index instance of the meilisearch (and update it every time any document is created/edited/deleted on the main database so both dbs are in sync), probably updateTypoTolerance so you can search and accept a few typos and then simply index.search('hello')!
const index = meilisearch.index('messages')
const messages = [
{ global_id: 1, chat_id: 10, message_id: 1, from: { user_id: 1, first_name: 'John', last_name: 'Doe' }, text: 'Hello world!' },
{ global_id: 2, chat_id: 10, message_id: 2, from: { user_id: 2, first_name: 'Jane', last_name: 'Doe' }, text: 'Hi!' },
{ global_id: 3, chat_id: 10, message_id: 3, from: { user_id: 1, first_name: 'John', last_name: 'Doe' }, text: 'How are you?' },
...
]
const response = await index.addDocuments(messages, {
primaryKey: 'global_id'
})
const response = await index.search('hello', {
attributesToSearchOn: ['text'],
filter: 'from.user_id = 1 AND chat_id = 10'
})
i've been thinking about creating at least my own API for my own messenger (tm), but i've never thought about the search system. like, how the search bar in the telegram even work? i could not understand it until i tried out meilisearch. it's definitely a good experience overall, would recommend, ign, blah-blah-blah. wanna experiment with some other stuff more, probably will and probably will post it on here. stay tuned!