lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject lucenenet git commit: use regex as logic expects
Date Thu, 05 Mar 2015 08:35:14 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 141f838f7 -> dd7dba7a6


use regex as logic expects


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/dd7dba7a
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/dd7dba7a
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/dd7dba7a

Branch: refs/heads/master
Commit: dd7dba7a68f6e22d65d40551857aa9c57674f698
Parents: 141f838
Author: Laimonas Simutis <laimis@gmail.com>
Authored: Wed Mar 4 17:07:42 2015 -0500
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Wed Mar 4 17:07:42 2015 -0500

----------------------------------------------------------------------
 .../core/Search/Payloads/TestPayloadNearQuery.cs    | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/dd7dba7a/src/Lucene.Net.Tests/core/Search/Payloads/TestPayloadNearQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/Payloads/TestPayloadNearQuery.cs b/src/Lucene.Net.Tests/core/Search/Payloads/TestPayloadNearQuery.cs
index 7ac3334..9b9bada 100644
--- a/src/Lucene.Net.Tests/core/Search/Payloads/TestPayloadNearQuery.cs
+++ b/src/Lucene.Net.Tests/core/Search/Payloads/TestPayloadNearQuery.cs
@@ -1,3 +1,4 @@
+using System.Text.RegularExpressions;
 using Lucene.Net.Analysis.Tokenattributes;
 using System;
 using Lucene.Net.Documents;
@@ -48,6 +49,7 @@ namespace Lucene.Net.Search.Payloads
         private static BoostingSimilarity Similarity = new BoostingSimilarity();
         private static byte[] Payload2 = { 2 };
         private static byte[] Payload4 = { 4 };
+        private static readonly Regex _whiteSpaceRegex = new Regex("[\\s]+", RegexOptions.Compiled);
 
         private class PayloadAnalyzer : Analyzer
         {
@@ -71,7 +73,7 @@ namespace Lucene.Net.Search.Payloads
                 PayAtt = AddAttribute<IPayloadAttribute>();
             }
 
-            public override bool IncrementToken()
+            public sealed override bool IncrementToken()
             {
                 bool result = false;
                 if (input.IncrementToken())
@@ -99,9 +101,9 @@ namespace Lucene.Net.Search.Payloads
 
         private PayloadNearQuery NewPhraseQuery(string fieldName, string phrase, bool inOrder,
PayloadFunction function)
         {
-            string[] words = phrase.Split("[\\s]+".ToCharArray());
-            SpanQuery[] clauses = new SpanQuery[words.Length];
-            for (int i = 0; i < clauses.Length; i++)
+            var words = _whiteSpaceRegex.Split(phrase);
+            var clauses = new SpanQuery[words.Length];
+            for (var i = 0; i < clauses.Length; i++)
             {
                 clauses[i] = new SpanTermQuery(new Term(fieldName, words[i]));
             }
@@ -290,9 +292,9 @@ namespace Lucene.Net.Search.Payloads
 
         private SpanNearQuery SpanNearQuery(string fieldName, string words)
         {
-            string[] wordList = words.Split("[\\s]+".ToCharArray());
-            SpanQuery[] clauses = new SpanQuery[wordList.Length];
-            for (int i = 0; i < clauses.Length; i++)
+            var wordList = _whiteSpaceRegex.Split(words);
+            var clauses = new SpanQuery[wordList.Length];
+            for (var i = 0; i < clauses.Length; i++)
             {
                 clauses[i] = new PayloadTermQuery(new Term(fieldName, wordList[i]), new AveragePayloadFunction());
             }


Mime
View raw message