v_common_search/
common.rs1use serde::Serialize;
2use v_api::app::ResultCode;
3
4#[derive(Serialize, Debug)]
5pub struct QueryResult {
6 pub result: Vec<String>,
7 pub count: i64,
8 pub estimated: i64,
9 pub processed: i64,
10 pub cursor: i64,
11 pub total_time: i64,
12 pub query_time: i64,
13 pub authorize_time: i64,
14 pub result_code: ResultCode,
15}
16
17impl Default for QueryResult {
18 fn default() -> Self {
19 QueryResult {
20 result: vec![],
21 count: 0,
22 estimated: 0,
23 processed: 0,
24 cursor: 0,
25 total_time: 0,
26 query_time: 0,
27 authorize_time: 0,
28 result_code: ResultCode::NotReady,
29 }
30 }
31}
32
33#[derive(Debug)]
34pub struct FTQuery {
35 pub ticket: String,
36 pub user: String,
37 pub query: String,
38 pub sort: String,
39 pub databases: String,
40 pub reopen: bool,
41 pub top: i32,
42 pub limit: i32,
43 pub from: i32,
44}
45
46impl FTQuery {
47 pub fn new_with_user(user: &str, query: &str) -> FTQuery {
48 FTQuery {
49 ticket: "".to_owned(),
50 user: user.to_owned(),
51 query: query.to_owned(),
52 sort: "".to_owned(),
53 databases: "".to_owned(),
54 reopen: false,
55 top: 10000,
56 limit: 10000,
57 from: 0,
58 }
59 }
60
61 pub fn new_with_ticket(ticket: &str, query: &str) -> FTQuery {
62 FTQuery {
63 ticket: ticket.to_owned(),
64 user: "".to_owned(),
65 query: query.to_owned(),
66 sort: "".to_owned(),
67 databases: "".to_owned(),
68 reopen: false,
69 top: 10000,
70 limit: 10000,
71 from: 0,
72 }
73 }
74
75 pub fn as_string(&self) -> String {
76 let mut s = String::new();
77
78 if self.ticket.is_empty() {
79 s.push_str("[\"UU=");
80 s.push_str(&self.user);
81 } else {
82 s.push_str("[\"");
83 s.push_str(&self.ticket);
84 }
85
86 s.push_str("\",\"");
87 s.push_str(&self.query);
88 s.push_str("\",\"");
89 s.push_str(&self.sort);
90 s.push_str("\",\"");
91 s.push_str(&self.databases);
92 s.push_str("\",");
93 s.push_str(&self.reopen.to_string());
94 s.push(',');
95 s.push_str(&self.top.to_string());
96 s.push(',');
97 s.push_str(&self.limit.to_string());
98 s.push(',');
99 s.push_str(&self.from.to_string());
100 s.push(']');
101
102 s
103 }
104}