NIMSDK-AOS  10.10.13
V2NIMMessageSearchExParams.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.message.params;
2 
7 import java.util.List;
8 
10  /**
11  * 搜索 “全部会话” 还是搜索 “指定的会话”
12  * conversationID 为空(null),搜索全部会话;
13  * conversationID 不为空,搜索指定会话。
14  */
15  private final String conversationId;
16  /**
17  * 关键字列表,
18  * 最多支持 5 个。当消息发送者以及消息类型均未指定时,必须设置关键字列表;否则,关键字列表可以为空。
19  */
20  private final List<String> keywordList;
21  /**
22  * 指定关键字列表匹配类型
23  * 可设置为 “或” 关系搜索,或 “与” 关系搜索。取值分别为 V2TIM_KEYWORD_MATCH_TYPE_OR 和 V2TIM_KEYWORD_MATCH_TYPE_AND。默认为 “或” 关系搜索。
24  * 关键字列表为空或为数量为1,该字段无效
25  */
26  private final V2NIMSearchKeywordMathType keywordMatchType;
27  /**
28  * 指定消息发送者,
29  * 最多支持 5 个。
30  * 超过返回参数错误, accountid默认只检查数量, 不检查是否重复
31  * null 和size==0 都表示没有指定人数
32  */
33  private final List<String> senderAccountIds;
34  /**
35  * 指定消息类型,
36  * 为null或空列表, 则表示查询所有消息类型
37  * 关键字不为空时, 不支持检索通知类消息
38  * 非文本消息,只检索对应检索字段,如果检索字段为空则该消息不回被检索到
39  */
40  private final List<V2NIMMessageType> messageTypes;
41  /**
42  * 指定消息子类型,
43  * 为null或空列表, 则表示查询所有消息子类型
44  * 关键字不为空时, 不支持检索通知类消息
45  * 非文本消息,只检索对应检索字段,如果检索字段为空则该消息不回被检索到
46  */
47  private final List<Integer> messageSubtypes;
48  /**
49  * 搜索的起始时间点,
50  * 默认为 0(从现在开始搜索)。UTC 时间戳,单位:毫秒。
51  */
52  private final long searchStartTime;
53  /**
54  * 从起始时间点开始的过去时间范围,
55  * 默认为 0(不限制时间范围)。24 x 60 x 60 x 1000 代表过去一天,单位:毫秒。
56  */
57  private final long searchTimePeriod;
58  /**
59  * 搜索的数量限制,
60  * 最大100
61  */
62  private final int limit;
63  /**
64  * 检索方向
65  */
66  private final V2NIMSearchDirection direction;
67  /**
68  * 消息检索的策略
69  */
70  private final V2NIMSearchStrategy strategy;
71  /**
72  * 搜索的起始位置,第一次填写空字符串,续拉时填写上一次返回的 V2NIMMessageSearchResult 中的 nextPageToken。
73  * 两次查询参数必须一致
74  */
75  private final String pageToken;
76 
77  private V2NIMMessageSearchExParams() {
78  this(null, null, V2NIMSearchKeywordMathType.V2NIM_SEARCH_KEYWORD_MATH_TYPE_OR, null, null,null, 0, 0, LIMIT_DEFAULT, DIRECTION_DEFAULT, STRATEGY_DEFAULT, null);
79  }
80 
81  private V2NIMMessageSearchExParams(String conversationId, List<String> keywordList, V2NIMSearchKeywordMathType keywordMatchType, List<String> senderAccountIds, List<V2NIMMessageType> messageTypes, List<Integer> messageSubtypes, long searchStartTime, long searchTimePeriod, int limit, V2NIMSearchDirection direction, V2NIMSearchStrategy strategy, String pageToken) {
82  this.conversationId = conversationId;
83  this.keywordList = keywordList;
84  this.keywordMatchType = keywordMatchType;
85  this.senderAccountIds = senderAccountIds;
86  this.messageTypes = messageTypes;
87  this.messageSubtypes = messageSubtypes;
88  this.searchStartTime = searchStartTime;
89  this.searchTimePeriod = searchTimePeriod;
90  this.limit = limit;
91  this.direction = direction;
92  this.strategy = strategy;
93  this.pageToken = pageToken;
94  }
95 
96  /**
97  * 获取会话ID
98  * @return 会话ID
99  */
100  public String getConversationId() {
101  return conversationId;
102  }
103 
104  /**
105  * 获取关键字列表
106  * @return 关键字列表
107  */
108  public List<String> getKeywordList() {
109  return keywordList;
110  }
111 
112  /**
113  * 获取关键字匹配类型
114  * @return 关键字匹配类型
115  */
117  return keywordMatchType;
118  }
119 
120  /**
121  * 获取发送者列表
122  * @return 发送者列表
123  */
124  public List<String> getSenderAccountIds() {
125  return senderAccountIds;
126  }
127 
128  /**
129  * 获取消息类型列表
130  * @return 消息类型列表
131  */
132  public List<V2NIMMessageType> getMessageTypes() {
133  return messageTypes;
134  }
135 
136  /**
137  * 获取消息子类型列表
138  * @return 消息子类型列表
139  */
140  public List<Integer> getMessageSubtypes() {
141  return messageSubtypes;
142  }
143 
144  /**
145  * 获取搜索起始时间
146  * @return 搜索起始时间
147  */
148  public long getSearchStartTime() {
149  return searchStartTime;
150  }
151 
152  /**
153  * 获取搜索时间范围
154  * @return 搜索时间范围
155  */
156  public long getSearchTimePeriod() {
157  return searchTimePeriod;
158  }
159 
160  /**
161  * 获取搜索数量限制
162  * @return 搜索数量限制
163  */
164  public int getLimit() {
165  return limit;
166  }
167 
168  /**
169  * 获取检索方向
170  * @return 检索方向
171  */
173  return direction;
174  }
175 
176  /**
177  * 获取消息检索的策略
178  * @return 消息检索的策略
179  */
181  return strategy;
182  }
183 
184  /**
185  * 获取搜索起始位置
186  * @return 搜索起始位置
187  */
188  public String getPageToken() {
189  return pageToken;
190  }
191 
192  @Override
193  public String toString() {
194  return "V2NIMMessageSearchExParams{" +
195  "conversationId='" + conversationId + '\'' +
196  ", keywordList=" + keywordList +
197  ", keywordMatchType=" + keywordMatchType +
198  ", senderAccountIds=" + senderAccountIds +
199  ", messageTypes=" + messageTypes +
200  ", messageSubtypes=" + messageSubtypes +
201  ", searchStartTime=" + searchStartTime +
202  ", searchTimePeriod=" + searchTimePeriod +
203  ", limit=" + limit +
204  ", pageToken='" + pageToken + '\'' +
205  '}';
206  }
207 
208  public static final int LIMIT_DEFAULT = 20;
209  public static final int LIMIT_MAX = 100;
210  private static final V2NIMSearchDirection DIRECTION_DEFAULT = V2NIMSearchDirection.V2NIM_SEARCH_DIRECTION_BACKWARD;
211  private static final V2NIMSearchStrategy STRATEGY_DEFAULT = V2NIMSearchStrategy.V2NIM_SEARCH_STRATEGY_FTS;
212 
213  /**
214  * V2NIMMessageSearchExParams 构造器
215  */
216  public static final class V2NIMMessageSearchExParamsBuilder {
217 
218  /**
219  * 搜索 “全部会话” 还是搜索 “指定的会话”
220  * conversationID 为空(null),搜索全部会话;
221  * conversationID 不为空,搜索指定会话。
222  */
223  private String conversationId;
224  /**
225  * 关键字列表,
226  * 最多支持 5 个。当消息发送者以及消息类型均未指定时,必须设置关键字列表;否则,关键字列表可以为空。
227  */
228  private List<String> keywordList;
229  /**
230  * 指定关键字列表匹配类型
231  * 可设置为 “或” 关系搜索,或 “与” 关系搜索。取值分别为 V2TIM_KEYWORD_MATCH_TYPE_OR 和 V2TIM_KEYWORD_MATCH_TYPE_AND。默认为 “或” 关系搜索。
232  * 关键字列表为空或为数量为1,该字段无效
233  */
235  /**
236  * 指定消息发送者,
237  * 最多支持 5 个。
238  * 超过返回参数错误, accountid默认只检查数量, 不检查是否重复
239  * null 和size==0 都表示没有指定人数
240  */
241  private List<String> senderAccountIds;
242  /**
243  * 指定消息类型,
244  * 为null或空列表, 则表示查询所有消息类型
245  * 关键字不为空时, 不支持检索通知类消息
246  * 非文本消息,只检索对应检索字段,如果检索字段为空则该消息不回被检索到
247  */
248  private List<V2NIMMessageType> messageTypes;
249  /**
250  * 指定消息子类型,
251  * 为null或空列表, 则表示查询所有消息子类型
252  * 关键字不为空时, 不支持检索通知类消息
253  * 非文本消息,只检索对应检索字段,如果检索字段为空则该消息不回被检索到
254  */
255  private List<Integer> messageSubtypes;
256  /**
257  * 搜索的起始时间点,
258  * 默认为 0(从现在开始搜索)。UTC 时间戳,单位:毫秒。
259  */
260  private long searchStartTime;
261  /**
262  * 搜索的过去时间范围,
263  * 默认为 0(不限制时间范围)。24 x 60 x 60 x 1000 代表过去一天,单位:毫秒。
264  */
265  private long searchTimePeriod;
266  /**
267  * 搜索的数量限制,
268  * 最大100
269  */
270  private int limit = LIMIT_DEFAULT;
271  /**
272  * 检索方向
273  */
274  private V2NIMSearchDirection direction = DIRECTION_DEFAULT;
275  /**
276  * 消息检索的策略
277  */
278  private V2NIMSearchStrategy strategy = STRATEGY_DEFAULT;
279  /**
280  * 搜索的起始位置,第一次填写空字符串,续拉时填写上一次返回的 V2NIMMessageSearchResult 中的 nextPageToken。
281  * 两次查询参数必须一致
282  */
283  private String pageToken;
284 
285  private V2NIMMessageSearchExParamsBuilder() {
286  }
287 
288  /**
289  * 构建 V2NIMMessageSearchExParamsBuilder 实例
290  * @return V2NIMMessageSearchExParamsBuilder 实例
291  */
292  public static V2NIMMessageSearchExParamsBuilder builder() {
293  return new V2NIMMessageSearchExParamsBuilder();
294  }
295 
296  /**
297  * 设置会话ID
298  * conversationID 为空(null),搜索全部会话;
299  * conversationID 不为空,搜索指定会话。
300  * @param conversationId 会话ID
301  * @return V2NIMMessageSearchExParamsBuilder 实例
302  */
303  public V2NIMMessageSearchExParamsBuilder withConversationId(String conversationId) {
304  this.conversationId = conversationId;
305  return this;
306  }
307 
308  /**
309  * 设置关键字列表,
310  * 最多支持 5 个。当消息发送者以及消息类型均未指定时,必须设置关键字列表;否则,关键字列表可以为空。
311  * @param keywordList 关键字列表
312  * @return V2NIMMessageSearchExParamsBuilder 实例
313  */
314  public V2NIMMessageSearchExParamsBuilder withKeywordList(List<String> keywordList) {
315  this.keywordList = keywordList;
316  return this;
317  }
318 
319  /**
320  * 设置关键字匹配类型
321  * 可设置为 “或” 关系搜索,或 “与” 关系搜索。取值分别为 V2TIM_KEYWORD_MATCH_TYPE_OR 和 V2TIM_KEYWORD_MATCH_TYPE_AND。默认为 “或” 关系搜索。
322  * @param keywordMatchType 关键字匹配类型
323  * @return V2NIMMessageSearchExParamsBuilder 实例
324  */
325  public V2NIMMessageSearchExParamsBuilder withKeywordMatchType(V2NIMSearchKeywordMathType keywordMatchType) {
326  this.keywordMatchType = keywordMatchType;
327  return this;
328  }
329 
330  /**
331  * 设置消息发送者,
332  * 最多支持 5 个。
333  * @param senderAccountIds 消息发送者
334  * @return V2NIMMessageSearchExParamsBuilder 实例
335  */
336  public V2NIMMessageSearchExParamsBuilder withSenderAccountIds(List<String> senderAccountIds) {
337  this.senderAccountIds = senderAccountIds;
338  return this;
339  }
340 
341  /**
342  * 设置消息类型,
343  * 为null或空列表, 则表示查询所有消息类型
344  * @param messageTypes 消息类型
345  * @return V2NIMMessageSearchExParamsBuilder 实例
346  */
347  public V2NIMMessageSearchExParamsBuilder withMessageTypes(List<V2NIMMessageType> messageTypes) {
348  this.messageTypes = messageTypes;
349  return this;
350  }
351  /**
352  * 设置消息子类型,
353  * 为null或空列表, 则表示查询所有消息子类型
354  * @param messageSubtypes 消息子类型
355  * @return V2NIMMessageSearchExParamsBuilder实例
356  */
357  public V2NIMMessageSearchExParamsBuilder withMessageSubtypes(List<Integer> messageSubtypes) {
358  this.messageSubtypes = messageSubtypes;
359  return this;
360  }
361  /**
362  * 设置搜索的起始时间点,
363  * 默认为 0(从现在开始搜索)。UTC 时间戳,单位:毫秒。
364  * @param searchStartTime 搜索的起始时间点
365  * @return V2NIMMessageSearchExParamsBuilder实例
366  */
367  public V2NIMMessageSearchExParamsBuilder withSearchStartTime(long searchStartTime) {
368  this.searchStartTime = searchStartTime;
369  return this;
370  }
371 
372  /**
373  * 设置搜索的过去时间范围,
374  * 默认为 0(不限制时间范围)。24 x 60 x 60 x 1000 代表过去一天,单位:毫秒。
375  * @param searchTimePeriod 搜索的过去时间范围
376  * @return V2NIMMessageSearchExParamsBuilder 实例
377  */
378  public V2NIMMessageSearchExParamsBuilder withSearchTimePeriod(long searchTimePeriod) {
379  this.searchTimePeriod = searchTimePeriod;
380  return this;
381  }
382  /**
383  * 设置搜索的数量限制,
384  * 最大100
385  * @param limit 搜索的数量限制
386  * @return V2NIMMessageSearchExParamsBuilder实例
387  */
388  public V2NIMMessageSearchExParamsBuilder withLimit(int limit) {
389  this.limit = limit;
390  return this;
391  }
392 
393  /**
394  * 设置检索方向
395  * @param direction 检索方向
396  * @return V2NIMMessageSearchExParamsBuilder 实例
397  */
398  public V2NIMMessageSearchExParamsBuilder withSearchDirection(V2NIMSearchDirection direction) {
399  if(direction == null){
400  return this;
401  }
402  this.direction = direction;
403  return this;
404  }
405 
406  /**
407  * 设置消息检索的策略
408  * @param strategy 消息检索的策略
409  * @return V2NIMMessageSearchExParamsBuilder 实例
410  */
411  public V2NIMMessageSearchExParamsBuilder withSearchStrategy(V2NIMSearchStrategy strategy) {
412  this.strategy = strategy;
413  return this;
414  }
415 
416  /**
417  * 设置搜索的起始位置,第一次填写空字符串,续拉时填写上一次返回的 V2NIMMessageSearchResult 中的 nextPageToken。
418  * @param pageToken 搜索的起始位置
419  * @return V2NIMMessageSearchExParamsBuilder实例
420  */
421  public V2NIMMessageSearchExParamsBuilder withPageToken(String pageToken) {
422  this.pageToken = pageToken;
423  return this;
424  }
425 
426  /**
427  * 构建 V2NIMMessageSearchExParams 实例
428  * @return V2NIMMessageSearchExParams 实例
429  */
430  public V2NIMMessageSearchExParams build() {
431  return new V2NIMMessageSearchExParams(conversationId, keywordList, keywordMatchType, senderAccountIds, messageTypes, messageSubtypes, searchStartTime, searchTimePeriod, limit, direction, strategy, pageToken);
432  }
433  }
434 }
V2NIMSearchKeywordMathType getKeywordMatchType()
获取关键字匹配类型
List< V2NIMMessageType > getMessageTypes()
获取消息类型列表