Skip to content

Commit e5843bc

Browse files
List word buckets: first pass of normalizations
1 parent 69c6569 commit e5843bc

File tree

7 files changed

+100
-105
lines changed

7 files changed

+100
-105
lines changed

src/channel/command.rs

+79-83
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use super::format::unescape;
1616
use super::statistics::ChannelStatistics;
1717
use crate::query::builder::{QueryBuilder, QueryBuilderResult};
1818
use crate::query::types::{
19-
ControlListAllLimit, ControlListAllOffset, ListAllMetaData, QueryGenericLang, QueryMetaData,
20-
QuerySearchLimit, QuerySearchOffset,
19+
ListLimit, ListMetaData, ListOffset, QueryGenericLang, QueryMetaData, QuerySearchLimit,
20+
QuerySearchOffset,
2121
};
2222
use crate::store::fst::StoreFSTPool;
2323
use crate::store::kv::StoreKVPool;
@@ -490,6 +490,48 @@ impl ChannelCommandSearch {
490490
}
491491
}
492492

493+
pub fn dispatch_list(mut parts: SplitWhitespace) -> ChannelResult {
494+
match (
495+
parts.next(),
496+
parts.next(),
497+
ChannelCommandBase::parse_text_parts(&mut parts),
498+
) {
499+
(Some(collection), Some(bucket), Some(_text)) => {
500+
debug!(
501+
"dispatching list of words for the collection {} on bucket: {}",
502+
collection, bucket
503+
);
504+
505+
let mut last_meta_err = None;
506+
let mut list_limit = APP_CONF.server.control_list_limit;
507+
let mut offset: u32 = 0;
508+
509+
while let Some(meta_result) = ChannelCommandBase::parse_next_meta_parts(&mut parts)
510+
{
511+
match Self::handle_list_meta(meta_result) {
512+
Ok(metadata) => match metadata {
513+
(Some(limit), None) => list_limit = limit,
514+
(None, Some(defined_offset)) => offset = defined_offset,
515+
_ => {}
516+
},
517+
Err(parse_err) => last_meta_err = Some(parse_err),
518+
}
519+
}
520+
521+
if let Some(err) = last_meta_err {
522+
return Err(err);
523+
}
524+
525+
ChannelCommandBase::commit_result_operation(QueryBuilder::list(
526+
collection, bucket, list_limit, offset,
527+
))
528+
}
529+
_ => Err(ChannelCommandError::InvalidFormat(
530+
"LIST <collection> <bucket> [LIMIT(<count>)]? [OFFSET(<count>)]?",
531+
)),
532+
}
533+
}
534+
493535
pub fn dispatch_help(parts: SplitWhitespace) -> ChannelResult {
494536
ChannelCommandBase::generic_dispatch_help(parts, &*MANUAL_MODE_SEARCH)
495537
}
@@ -571,6 +613,41 @@ impl ChannelCommandSearch {
571613
)),
572614
}
573615
}
616+
617+
fn handle_list_meta(meta_result: MetaPartsResult) -> Result<ListMetaData, ChannelCommandError> {
618+
match meta_result {
619+
Ok((meta_key, meta_value)) => {
620+
debug!("handle list meta: {} = {}", meta_key, meta_value);
621+
622+
match meta_key {
623+
"LIMIT" => {
624+
if let Ok(list_limit_parsed) = meta_value.parse::<ListLimit>() {
625+
Ok((Some(list_limit_parsed), None))
626+
} else {
627+
Err(ChannelCommandBase::make_error_invalid_meta_value(
628+
meta_key, meta_value,
629+
))
630+
}
631+
}
632+
"OFFSET" => {
633+
if let Ok(query_offset_parsed) = meta_value.parse::<ListOffset>() {
634+
Ok((None, Some(query_offset_parsed)))
635+
} else {
636+
Err(ChannelCommandBase::make_error_invalid_meta_value(
637+
meta_key, meta_value,
638+
))
639+
}
640+
}
641+
_ => Err(ChannelCommandBase::make_error_invalid_meta_key(
642+
meta_key, meta_value,
643+
)),
644+
}
645+
}
646+
Err(err) => Err(ChannelCommandBase::make_error_invalid_meta_key(
647+
err.0, err.1,
648+
)),
649+
}
650+
}
574651
}
575652

576653
impl ChannelCommandIngest {
@@ -755,47 +832,6 @@ impl ChannelCommandIngest {
755832
}
756833

757834
impl ChannelCommandControl {
758-
fn handle_list_all_meta(
759-
meta_result: MetaPartsResult,
760-
) -> Result<ListAllMetaData, ChannelCommandError> {
761-
match meta_result {
762-
Ok((meta_key, meta_value)) => {
763-
debug!(
764-
"handle control list-all meta: {} = {}",
765-
meta_key, meta_value
766-
);
767-
768-
match meta_key {
769-
"LIMIT" => {
770-
if let Ok(list_limit_parsed) = meta_value.parse::<ControlListAllLimit>() {
771-
Ok((Some(list_limit_parsed), None))
772-
} else {
773-
Err(ChannelCommandBase::make_error_invalid_meta_value(
774-
meta_key, meta_value,
775-
))
776-
}
777-
}
778-
"OFFSET" => {
779-
if let Ok(query_offset_parsed) = meta_value.parse::<ControlListAllOffset>()
780-
{
781-
Ok((None, Some(query_offset_parsed)))
782-
} else {
783-
Err(ChannelCommandBase::make_error_invalid_meta_value(
784-
meta_key, meta_value,
785-
))
786-
}
787-
}
788-
_ => Err(ChannelCommandBase::make_error_invalid_meta_key(
789-
meta_key, meta_value,
790-
)),
791-
}
792-
}
793-
Err(err) => Err(ChannelCommandBase::make_error_invalid_meta_key(
794-
err.0, err.1,
795-
)),
796-
}
797-
}
798-
799835
pub fn dispatch_trigger(mut parts: SplitWhitespace) -> ChannelResult {
800836
match (parts.next(), parts.next(), parts.next()) {
801837
(None, _, _) => Ok(vec![ChannelCommandResponse::Result(format!(
@@ -882,46 +918,6 @@ impl ChannelCommandControl {
882918
pub fn dispatch_help(parts: SplitWhitespace) -> ChannelResult {
883919
ChannelCommandBase::generic_dispatch_help(parts, &*MANUAL_MODE_CONTROL)
884920
}
885-
886-
pub fn dispatch_list(mut parts: SplitWhitespace) -> ChannelResult {
887-
match (
888-
parts.next(), // collection
889-
parts.next(), // bucket
890-
ChannelCommandBase::parse_text_parts(&mut parts),
891-
) {
892-
(Some(collection), Some(bucket), Some(_text)) => {
893-
debug!(
894-
"dispatching list of words for the collection {} on bucket: {}",
895-
collection, bucket
896-
);
897-
let mut last_meta_err = None;
898-
let mut list_limit = APP_CONF.server.control_list_limit;
899-
let mut offset: u32 = 0;
900-
while let Some(meta_result) = ChannelCommandBase::parse_next_meta_parts(&mut parts)
901-
{
902-
match Self::handle_list_all_meta(meta_result) {
903-
Ok(metadata) => match metadata {
904-
(Some(limit), None) => list_limit = limit,
905-
(None, Some(defined_offset)) => offset = defined_offset,
906-
_ => {}
907-
},
908-
Err(parse_err) => last_meta_err = Some(parse_err),
909-
}
910-
}
911-
912-
if let Some(err) = last_meta_err {
913-
return Err(err);
914-
}
915-
916-
ChannelCommandBase::commit_result_operation(QueryBuilder::list(
917-
collection, bucket, list_limit, offset,
918-
))
919-
}
920-
_ => Err(ChannelCommandError::InvalidFormat(
921-
"LIST <collection> <bucket> [LIMIT(<count>)]? [OFFSET(<count>)]?",
922-
)),
923-
}
924-
}
925921
}
926922

927923
impl fmt::Display for ChannelCommandError {

src/channel/message.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl ChannelMessageMode for ChannelMessageModeSearch {
166166
gen_channel_message_mode_handle!(message, COMMANDS_MODE_SEARCH, {
167167
"QUERY" => ChannelCommandSearch::dispatch_query,
168168
"SUGGEST" => ChannelCommandSearch::dispatch_suggest,
169+
"LIST" => ChannelCommandSearch::dispatch_list,
169170
"HELP" => ChannelCommandSearch::dispatch_help,
170171
})
171172
}
@@ -191,7 +192,6 @@ impl ChannelMessageMode for ChannelMessageModeControl {
191192
"TRIGGER" => ChannelCommandControl::dispatch_trigger,
192193
"INFO" => ChannelCommandControl::dispatch_info,
193194
"HELP" => ChannelCommandControl::dispatch_help,
194-
"LIST" => ChannelCommandControl::dispatch_list,
195195
})
196196
}
197197
}

src/executor/list.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
use crate::query::types::ControlListAllLimit;
2-
use crate::query::types::ControlListAllOffset;
1+
// Sonic
2+
//
3+
// Fast, lightweight and schema-less search backend
4+
// Copyright: 2022, Troy Kohler <troy.kohler@zalando.de>
5+
// License: Mozilla Public License v2.0 (MPL v2.0)
6+
7+
use crate::query::types::ListLimit;
8+
use crate::query::types::ListOffset;
39
use crate::store::fst::StoreFSTActionBuilder;
410
use crate::store::fst::StoreFSTPool;
511
use crate::store::item::StoreItem;
@@ -9,17 +15,17 @@ pub struct ExecutorList;
915
impl ExecutorList {
1016
pub fn execute(
1117
store: StoreItem,
12-
limit: ControlListAllLimit,
13-
offset: ControlListAllOffset,
18+
limit: ListLimit,
19+
offset: ListOffset,
1420
) -> Result<Vec<String>, ()> {
1521
if let StoreItem(collection, Some(bucket), None) = store {
16-
1722
general_fst_access_lock_read!();
1823

1924
if let Ok(fst_store) = StoreFSTPool::acquire(collection, bucket) {
2025
let fst_action = StoreFSTActionBuilder::access(fst_store);
2126

2227
debug!("running list, read lock is acquired");
28+
2329
let (limit_usize, offset_usize) = (limit as usize, offset as usize);
2430

2531
return fst_action.list_words(limit_usize, offset_usize);

src/executor/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub mod count;
1111
pub mod flushb;
1212
pub mod flushc;
1313
pub mod flusho;
14+
pub mod list;
1415
pub mod pop;
1516
pub mod push;
1617
pub mod search;
1718
pub mod suggest;
18-
pub mod list;

src/query/actions.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,5 @@ pub enum Query<'a> {
2828
FlushC(StoreItem<'a>),
2929
FlushB(StoreItem<'a>),
3030
FlushO(StoreItem<'a>),
31-
List(
32-
StoreItem<'a>,
33-
ControlListAllLimit,
34-
ControlListAllOffset
35-
),
31+
List(StoreItem<'a>, ListLimit, ListOffset),
3632
}

src/query/builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use super::actions::Query;
88
use super::types::{QueryGenericLang, QuerySearchLimit, QuerySearchOffset};
99
use crate::lexer::token::{TokenLexerBuilder, TokenLexerMode};
10-
use crate::query::types::{ControlListAllLimit, ControlListAllOffset};
10+
use crate::query::types::{ListLimit, ListOffset};
1111
use crate::store::item::StoreItemBuilder;
1212

1313
pub struct QueryBuilder;
@@ -129,8 +129,8 @@ impl QueryBuilder {
129129
pub fn list<'a>(
130130
collection: &'a str,
131131
bucket: &'a str,
132-
limit: ControlListAllLimit,
133-
offset: ControlListAllOffset,
132+
limit: ListLimit,
133+
offset: ListOffset,
134134
) -> QueryBuilderResult<'a> {
135135
match StoreItemBuilder::from_depth_2(collection, bucket) {
136136
Ok(store) => Ok(Query::List(store, limit, offset)),

src/query/types.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ pub type QuerySearchID<'a> = &'a str;
1616
pub type QuerySearchLimit = u16;
1717
pub type QuerySearchOffset = u32;
1818

19+
pub type ListLimit = u16;
20+
pub type ListOffset = u32;
21+
1922
pub type QueryMetaData = (
2023
Option<QuerySearchLimit>,
2124
Option<QuerySearchOffset>,
2225
Option<QueryGenericLang>,
2326
);
2427

25-
pub type ControlListAllLimit = u16;
26-
pub type ControlListAllOffset = u32;
27-
28-
pub type ListAllMetaData = (
29-
Option<ControlListAllLimit>,
30-
Option<ControlListAllOffset>,
31-
);
28+
pub type ListMetaData = (Option<ListLimit>, Option<ListOffset>);
3229

3330
impl QueryGenericLang {
3431
pub fn from_value(value: &str) -> Option<QueryGenericLang> {

0 commit comments

Comments
 (0)