Looking for ideas for index ordering

I’m doing a silly thing and implementing my own full-text search for a recipe database.

An index is specified by a list of fields [“name”, “tags”, “ingredients”]

The index is created by breaking the fields into words.

The index is created for each book of recipes and looks something like this:

/index/recipes/{bookid}/fts/chicken/{recipe-id}
/index/recipes/{bookid}/fts/beef/{recipe-id}

A search is then a PrefixRange with (searchTerm, searchTerm[:-1]+strinc(searchTerm[-1]))

This works well. The change I would like to make is to make the order of the of the list of fields be there order of the returned values. In other words, if “chicken” is found, then the first results would be where chicken was found in the “name” field, next the “tags” field, etc.

I thought about prefixing the words with the index of the list of fields, but I can’t figure out a way to “wildcard” the index when doing the PrefixRange search.

Any ideas? My hope is to avoid have to do multiple queries (.e.g. /index/recipes/{bookid}/fts/name/chicken, /index/recipes/{bookid}/fts/tags/chicken)

Thanks,
Greg

I thought about prefixing the words with the index of the list of fields, but I can’t figure out a way to “wildcard” the index when doing the PrefixRange search.

Have you tried suffix? Something like

/index/recipes/{bookid}/fts/chicken/filed_index_0/{recipe-id}
/index/recipes/{bookid}/fts/chicken/filed_index_1/{recipe-id}

So a wildcard search would be a range scan of (/index/recipes/{bookid}/fts/chicken/, /index/recipes/{bookid}/fts/chicken/\0xff)

Suffix is a good idea. I have been trying appending a digit to the name itself ‘chicken0’, ‘chicken1’, which seems to work, but a separate tuple sounds better. Thanks!