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

RediSearch query error reporting #925

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ GRAPH.QUERY DEMO_GRAPH "DROP INDEX ON :person(age)"

## Full-text indexes

RedisGraph leverages the indexing capabilities of RediSearch to provide full-text indexes through procedure calls. To construct a full-text index on the `title` property of all nodes with label `movie`, use the syntax:
RedisGraph leverages the indexing capabilities of [RediSearch](https://oss.redislabs.com/redisearch/index.html) to provide full-text indices through procedure calls. To construct a full-text index on the `title` property of all nodes with label `movie`, use the syntax:

```sh
GRAPH.QUERY DEMO_GRAPH "CALL db.idx.fulltext.createNodeIndex('movie', 'title')"
Expand Down
13 changes: 13 additions & 0 deletions src/procedures/proc_fulltext_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ ProcedureResult Proc_FulltextQueryNodeInvoke(ProcedureCtx *ctx, const SIValue *a

// Execute query
pdata->iter = Index_Query(pdata->idx, query, &err);
// Raise runtime exception if err != NULL.
if(err) {
/* RediSearch error message is allocated using `rm_strdup`
* QueryCtx is expecting to free `error` using `free`
* in which case we have no option but to clone error. */
char *error;
asprintf(&error, "RediSearch: %s", err);
rm_free(err);
QueryCtx_SetError(error);
/* Raise the exception, we expect an exception handler to be set.
* as procedure invocation is done at runtime. */
QueryCtx_RaiseRuntimeException();
}
assert(pdata->iter);

ctx->privateData = pdata;
Expand Down
2 changes: 1 addition & 1 deletion src/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ SIValue SIValue_Modulo(const SIValue a, const SIValue n) {
case true:
// The modulo machine instruction may be used if a and n are both integers.
return SI_LongVal(a.longval % n.longval);
case false:
default:
// Otherwise, use the library function fmod to calculate the modulo and return a double.
return SI_DoubleVal(fmod(SI_GET_NUMERIC(a), SI_GET_NUMERIC(n)));
}
Expand Down
10 changes: 9 additions & 1 deletion tests/flow/test_procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,12 @@ def test_procedure_propertyKeys(self):
actual_resultset = redis_graph.call_procedure("db.propertyKeys").result_set
expected_results = [["name"], ["value"]]
self.env.assertEquals(actual_resultset, expected_results)


def test_procedure_fulltext_syntax_error(self):
try:
query = """CALL db.idx.fulltext.queryNodes('fruit', 'Orange || Apple') YIELD node RETURN node"""
redis_graph.query(query)
assert(False)
except redis.exceptions.ResponseError:
# Expecting an error.
pass