Search code examples
xodus

Substring or regex search in Xodus


I notice the Xodus entity browser allows searching for property values that begin with a substring. For example:

firstName ~ Jo

I am wondering whether substring or regex search has been considered. I assume it's not there because it would require iterating over every entity. But even if slow it would be a handy feature in the entity browser, perhaps with a progress bar. Does someone know if this has been considered, or whether a PR adding it would be entertained?


Solution

  • In order to search for "cat" in the string "dogcatcow"

    The only possible solution I can think of now is to ceate a transaction and do:

    EntityIterable entities = txn.find(entityType);
    

    From here is it just standard Java iteration and iterate over the properties that contains the keyword "cat"

    Another idea is to process every property you put into the Xodus store. You can build a typical key value service that will process (e.g. text processing to extract words with Apache Tika) the text properties before or after saving into the store.

    So from your example "dogcatcow" you can have 1 key that links with "dog" "cat' and "cow" back to the entity [or the other way around] (so maybe after save is the best time to created this indexed keys).

    As a side note, links is what sets Xodus apart from other databases in my experience this is very powerful and useful for many cases.

    From there is it just simple findWithLinks when searching for keys.

    You can refer to this code for a sample KV store: https://github.com/divroll/backend/blob/master/src/main/java/com/divroll/backend/service/jee/JeeKeyValueService.java