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

Support empty FT_SEARCH result #37

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
7 changes: 7 additions & 0 deletions src/commands/search_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,13 @@ impl<'de> Deserialize<'de> for FtSearchResult {
return Err(de::Error::custom("sequence `size_hint` is expected for FtSearchResult"));
};

if total_results == 0 {
return Ok(FtSearchResult {
total_results,
results: Vec::new(),
});
}

let row_num_fields = (seq_size - 1) / total_results;
let mut results = Vec::with_capacity(total_results);
let mut row: Option<FtSearchResultRow> = None;
Expand Down
39 changes: 39 additions & 0 deletions src/tests/search_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,45 @@ async fn ft_search() -> Result<()> {
Ok(())
}

#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn ft_search_empty_index() -> Result<()> {
let client = get_redis_stack_test_client().await?;
client.flushall(FlushingMode::Sync).await?;

client
.ft_create(
"index",
FtCreateOptions::default()
.on(FtIndexDataType::Hash)
.prefix("doc")
.payload_field("payload"),
[
FtFieldSchema::identifier("title")
.field_type(FtFieldType::Text)
.sortable(),
FtFieldSchema::identifier("data")
.field_type(FtFieldType::Text)
.sortable(),
FtFieldSchema::identifier("published_at")
.field_type(FtFieldType::Numeric)
.sortable(),
],
)
.await?;
wait_for_index_scanned(&client, "index").await?;

let result = client
.ft_search("index", "wizard", FtSearchOptions::default())
.await?;
log::debug!("result: {result:?}");
assert_eq!(0, result.total_results);
assert_eq!(0, result.results.len());

Ok(())
}

#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
Expand Down
Loading