Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MongoDB fuzzy search feature to filter the chats list #1

Open
GromNaN opened this issue Mar 6, 2023 · 1 comment
Open

Use MongoDB fuzzy search feature to filter the chats list #1

GromNaN opened this issue Mar 6, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@GromNaN
Copy link
Owner

GromNaN commented Mar 6, 2023

This feature requires MongoDB Atlas to use Lucene search.

/**
* @return array{title: string, createdAt: \DateTimeImmutable, id: string}[]
* @todo project only the fields we need, not the whole document with all messages
* also use the atlas search for fuzzy search https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples
*/
public function getConversations(): iterable
{
return $this->documentManager->getRepository(Conversation::class)
->createQueryBuilder()
->field('title')->equals(new Regex($this->query ?? '', 'i'))
->sort('createdAt', 'desc')
->limit(20)
->getQuery()
->execute();
}

@GromNaN GromNaN added enhancement New feature or request help wanted Extra attention is needed labels Mar 6, 2023
@GromNaN
Copy link
Owner Author

GromNaN commented Mar 6, 2023

The index must be created in Atlas first. Doctrine ODM & MongoDB Driver doesn't seems to provide a way to create the index by code.

{
  index: 'default',
  text: {
    query: 'SymfonyGPT',
    path: 'title',
    fuzzy: {}
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant