Meilisearch: Matching a subset of a field value, like last four charaters of a unique ID

Created on 22 Jul 2020  路  4Comments  路  Source: meilisearch/MeiliSearch

Hey there,

I'm not sure if this is right place to ask this, but is there a way to partially match a word in the document? Currently, I have indexed my data and I am able to prioritize my search by adding searchableAttributes where it will first prioritize search within a unique ID attribute. I can search by typing the first matching characters in the ID, but I also want to be able to partially match them given a subset of that word, which does not work in my case.

For example, if I have an ID that is HID98273DDE, I don't want to enter the full word by typing HID... but maybe just type the last four characters like 3DDE and it should return the document that matches this partial search.

I'm not able to find anything relating to this in the documentation, or maybe I am search the wrong term in the docs to know where it is. I am using MS with the Laravel Scout driver (meilisearch-laravel-scout) but thought this would be more related to the settings of MeiliSearch than the driver itself. Appreciate any help provided :)

Most helpful comment

hey @creativenull !
what you seems to want is a postfix search which is not possible with meilisearch (@Kerollmops ?).

meilisearch inner db is kind of a "tree" where the root are first letters of existing words in your documents, and meilisearch browse the tree letter by letter from the root.

So for example if you have: [HID98273DDE, HID982733GH, HID768478594], generated tree will behave like:

                  |- DDE -> document
        |- 98273 -|
        |         |- 3GH -> document
|- HID -|
        |- 768478594 -----> document

and because meilisearch needs to begin by the root of the tree, it will never find your document. 馃槥

if there is a logic behind your IDs like:

HID     9827   3DDE
domain  scope  uid

or if you always search on 4 last letters,
I would suggest you to add an other searchable attribute with your ID space-splited like HID 9827 3DDE

All 4 comments

hey @creativenull !
what you seems to want is a postfix search which is not possible with meilisearch (@Kerollmops ?).

meilisearch inner db is kind of a "tree" where the root are first letters of existing words in your documents, and meilisearch browse the tree letter by letter from the root.

So for example if you have: [HID98273DDE, HID982733GH, HID768478594], generated tree will behave like:

                  |- DDE -> document
        |- 98273 -|
        |         |- 3GH -> document
|- HID -|
        |- 768478594 -----> document

and because meilisearch needs to begin by the root of the tree, it will never find your document. 馃槥

if there is a logic behind your IDs like:

HID     9827   3DDE
domain  scope  uid

or if you always search on 4 last letters,
I would suggest you to add an other searchable attribute with your ID space-splited like HID 9827 3DDE

Thanks for the clarification! There is no logic to the ID I generate, since I'm using it to track internal data transactions. Do you think this will work if I hyphen-split the string (like HID-9827-3DDE)? If not, then I'm fine with using space-split implementation you mentioned for now.

Also, are there any plans to implement a postfix search in MeiliSearch in the future? I'd be interested to see something like that. I'm still new to this search engine API stuff so apologies in advance if I got something wrong.

there is 2 kind of separator reconized:

  • SOFT: the distance of the 2 separated word is considered small (same context)

    white_spaces, ', ", - , _, : / \, @

  • HARD: the distance of the 2 separated word is considered big (not same context)

    ., ;, ,, !, ?, (, )

About postfix/subset search, I honestly think that meilisearch can't have this kind of feature without severely impacting performance.

But your use case is interesting and show that the expected behaviors of searching an ID is different than others attributes.

Thanks for your issue! 馃憤

I close it and let you reopen a new one if you need help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fimbault picture fimbault  路  3Comments

carlosb1 picture carlosb1  路  5Comments

frank-io picture frank-io  路  3Comments

imor picture imor  路  4Comments

qdequele picture qdequele  路  4Comments