Sfoglia il codice sorgente

关键词限制 - 字数太少的过滤

lihai 5 anni fa
parent
commit
82ac17b6d4

+ 48 - 0
CallCenterCommon/CallCenter.Utility/KeywordSpliterHelper.cs

@@ -32,6 +32,7 @@ namespace CallCenter.Utility
32 32
         public static string DoGetKeyword(string keyText)
33 33
         {
34 34
             if (String.IsNullOrEmpty(keyText)) return "";
35
+            if (JudgementStr(keyText)) return "";
35 36
 
36 37
             LoadDict();
37 38
             LoadDictBaidu();
@@ -389,5 +390,52 @@ namespace CallCenter.Utility
389 390
         {
390 391
             return _StopWordsList.Contains(str);
391 392
         }
393
+
394
+        /// <summary>
395
+        ///  用正则表达式来验证字符串是否为数字字符串
396
+        /// </summary>
397
+        /// <param name="message"></param>
398
+        /// <param name="result"></param>
399
+        /// <returns></returns>
400
+        private static bool isNumberic(string message, out int result)
401
+        {
402
+            System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$");
403
+            result = -1;
404
+            if (rex.IsMatch(message))
405
+            {
406
+                result = int.Parse(message);
407
+                return true;
408
+            }
409
+            else
410
+                return false;
411
+        }
412
+
413
+        /// <summary>
414
+        /// 字符串过滤
415
+        /// 1、纯数字大于4个数字
416
+        /// 2、不是纯数字大于2个字
417
+        /// </summary>
418
+        /// <param name="key"></param>
419
+        /// <returns></returns>
420
+        private static bool JudgementStr(string key)
421
+        {
422
+            bool b = false;
423
+            byte[] keyText2 = Encoding.Default.GetBytes(key);
424
+            int key_l = keyText2.Length;
425
+            int result = 0;
426
+            if (isNumberic(key, out result))
427
+            {
428
+                // 4个数字
429
+                if (key_l < 5)
430
+                    b = true;
431
+            }
432
+            else
433
+            {
434
+                // 2个字
435
+                if (key_l < 4)
436
+                    b = true;
437
+            }
438
+            return b;
439
+        }
392 440
     }
393 441
 }

+ 48 - 0
CallCenterCommon/CallCenter.WebChatServer/KeywordSpliter.cs

@@ -32,6 +32,7 @@ namespace CallCenter.WebChatServer
32 32
         public static string DoGetKeyword(string keyText)
33 33
         {
34 34
             if (String.IsNullOrEmpty(keyText)) return "";
35
+            if (JudgementStr(keyText)) return "";
35 36
 
36 37
             LoadDict();
37 38
             LoadDictBaidu();
@@ -390,5 +391,52 @@ namespace CallCenter.WebChatServer
390 391
         {
391 392
             return _StopWordsList.Contains(str);
392 393
         }
394
+        
395
+        /// <summary>
396
+        ///  用正则表达式来验证字符串是否为数字字符串
397
+        /// </summary>
398
+        /// <param name="message"></param>
399
+        /// <param name="result"></param>
400
+        /// <returns></returns>
401
+        private static bool isNumberic(string message, out int result)
402
+        {
403
+            System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$");
404
+            result = -1;
405
+            if (rex.IsMatch(message))
406
+            {
407
+                result = int.Parse(message);
408
+                return true;
409
+            }
410
+            else
411
+                return false;
412
+        }
413
+
414
+        /// <summary>
415
+        /// 字符串过滤
416
+        /// 1、纯数字大于4个数字
417
+        /// 2、不是纯数字大于2个字
418
+        /// </summary>
419
+        /// <param name="key"></param>
420
+        /// <returns></returns>
421
+        private static bool JudgementStr(string key)
422
+        {
423
+            bool b = false;
424
+            byte[] keyText2 = Encoding.Default.GetBytes(key);
425
+            int key_l = keyText2.Length;
426
+            int result = 0;
427
+            if (isNumberic(key, out result))
428
+            {
429
+                // 4个数字
430
+                if (key_l < 5)
431
+                    b = true;
432
+            }
433
+            else
434
+            {
435
+                // 2个字
436
+                if (key_l < 4)
437
+                    b = true;
438
+            }
439
+            return b;
440
+        }
393 441
     }
394 442
 }