1

I am trying to understand on how to perform queries in Redisearch strictly with "begins with" and I keep getting "contains".

For example if I have fields with values like 'football', 'myfootball', 'greenfootball' and would provide a search term like this:

> FT.SEARCH myIdx @myfield:foot*

I want just to get 'football' but I keep getting other fields that contain the word instead of beginning with that word.

Is there a way to avoid this?

I was trying to use VERBATIM and things like @myfield:^foot* but nothing.

I am using JRedisearch as a client but eventually I had to enter the DB and perform these queries manually in order to figure out what's happening. That being said, is this possible to do with this client at the moment?

Thanks

EDIT A sample of my index setup:

Client client = new Client(INDEX_NAME, url, PORT);
Schema sc = new Schema().addSortableTextField("url", 1.0); // using this field for query
client.dropIndex(true);
client.createIndex(sc, Client.IndexOptions.Default());
return client;

Sample document:

id: // random uuid
urlPath: myfootbal
application: web
market: Europe
Urosh T.
  • 3,336
  • 5
  • 34
  • 42

1 Answers1

1

After checking the RDB provided I see that when searching foot* you are not getting myfootbal. The replies look like this: /dot-com/plp/football/x/index.html. You are getting those replies because this url is tokenized, and '/' is one of the tokenize chars. If you do not want those urls to be tokenized you need to declare them as TAGS and not as TEXT. This way the entire url will be indexed as is and when search for foot* it will not appear in the results.

For more information about TAGS see the FT.CREATE documentation: https://oss.redislabs.com/redisearch/Commands.html

Meir Shpilraien
  • 506
  • 2
  • 4
  • I have failed to mention that I had `/` in my field, sorry about that. However, documentation doesn't mention anything on forward slashes when it comes to tokenization. https://oss.redislabs.com/redisearch/Escaping.html - It specifies these fields: `,.<>{}[]"':;!@#$%^&*()-+=~`. At least it wasn't clear for me that it was the issue and that the forward slash was tokenized. Also, by using tags, I lose the benefit of doing wildcard searches (e.g: `/gts/foot*` and such) which is not what I want. – Urosh T. May 19 '19 at 16:16
  • 1
    You can do prefixes with TAGS so you do not lose this ability. – Meir Shpilraien May 20 '19 at 08:25