mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.61k stars 1.25k forks source link

Custom String Query #1333

Open lazlo-bonin opened 5 years ago

lazlo-bonin commented 5 years ago

Is there a way to create a custom string query?

I have a custom search engine that needs to return results based on initials, for code completion.

For example, "CWL" should match "Console Write Line".

Looking at the query class a bit, I see that it expects a BsonExpression and I don't see a way to extend it. Is there a way to do this?

mbdavid commented 5 years ago

Hi, is your source string inside a long memo text? Or is just a single word field?

It’s possible to create a new propriety (get only) that return this initial letters? (Or return an array of string)

In this case you can create index on this result and query over it.

Yes, BsonExpressions are best solution for this case, but current version has no support for user-defined methods

lazlo-bonin commented 5 years ago

Hi,

It's a short text field, but the initials approach wouldn't work. I simplified the requirement a bit, but basically I need to implement a fuzzy search engine, so for example "Conwli" should also match "Console Write Line".

My last resort would be loading the entire string-to-ID collection in memory and performing the search there, but it might defeat the purpose of a database to begin with!

mbdavid commented 5 years ago

Your case is almost a Full Text Search using custom analyzer and tokenizer. Did you already use Lucene.net? Lucine implement this full search very well and already exist plugin to store Lucene index data into LiteDB

Jacknq commented 2 years ago

Hi, any example of simple tokenizer in v5? Like you mentioned Register( method on bsonxepression. Thanks