Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Result returned from client.search() #133

Closed
kapil-signity opened this issue Oct 26, 2020 · 3 comments
Closed

No Result returned from client.search() #133

kapil-signity opened this issue Oct 26, 2020 · 3 comments

Comments

@kapil-signity
Copy link

I used the same code in Readme.
SearchResult res = client.search(q);
print(res.totalResults) <===Returning 0 always even item inserted in redis. see below snapshotshot
image

@gkorland
Copy link
Contributor

@kapil-signity can you please share the index schema definition?

@kapil-signity
Copy link
Author

kapil-signity commented Oct 28, 2020

@gkorland

Client client = new Client("myIndexNew", "localhost", 6379);
Schema sc = new Schema()
                .addTextField("title", 5.0)
                .addTextField("body", 1.0)
                .addNumericField("price");

// IndexDefinition requires RediSearch 2.0+
IndexDefinition def = new IndexDefinition()
						.setPrefixes(new String[] {"item:", "product:"})
						.setFilter("@price>100");

client.createIndex(sc, Client.IndexOptions.defaultOptions().setDefinition(def));

Map<String, Object> fields = new HashMap<>();
fields.put("title", "hello world");
fields.put("state", "NY");
fields.put("body", "lorem ipsum");
fields.put("price", 1337);

// RediSearch 2.0+ supports working with Redis Hash commands
try(Jedis conn = client.connection()){
	conn.hset("item", fields);
}

Query q = new Query("hello world")
                    .addFilter(new Query.NumericFilter("price", 0, 1000))
                    .limit(0,5);

// actual search
SearchResult res = client.search(q);
System.out.println(res.totalResults);  **<==== printing 0 as result**

@gkorland
Copy link
Contributor

I see two issues in your code example:

  1. Prefix is set as item: while the hash key is item --> this prefix can match keys like item:, item:1, items:2....
  2. Price is set as 1337 while the query range is 0-1000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants