You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2016/10/02 10:22:19 UTC
[08/12] lucenenet git commit: Finished implementation of
QueryParser.Surround.Query.SrndTruncQuery
Finished implementation of QueryParser.Surround.Query.SrndTruncQuery
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/dee8fb41
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/dee8fb41
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/dee8fb41
Branch: refs/heads/master
Commit: dee8fb41c8149a73ef090b6ce902eda27c9ba9fc
Parents: 1757a60
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Thu Sep 22 14:38:11 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Thu Sep 22 14:38:11 2016 +0700
----------------------------------------------------------------------
.../Surround/Query/SrndTruncQuery.cs | 89 +++++++++-----------
1 file changed, 42 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/dee8fb41/src/Lucene.Net.QueryParser/Surround/Query/SrndTruncQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Surround/Query/SrndTruncQuery.cs b/src/Lucene.Net.QueryParser/Surround/Query/SrndTruncQuery.cs
index fc3e4e1..2925ce9 100644
--- a/src/Lucene.Net.QueryParser/Surround/Query/SrndTruncQuery.cs
+++ b/src/Lucene.Net.QueryParser/Surround/Query/SrndTruncQuery.cs
@@ -83,57 +83,52 @@ namespace Lucene.Net.QueryParsers.Surround.Query
pattern = new Regex(re.ToString(), RegexOptions.Compiled);
}
- // TODO: Finish implementation
public override void VisitMatchingTerms(IndexReader reader, string fieldName, SimpleTerm.IMatchingTermVisitor mtv)
{
- throw new NotImplementedException("Need to translate this from Java's whacky RegEx syntax");
- //int prefixLength = prefix.Length;
- //Terms terms = MultiFields.GetTerms(reader, fieldName);
- //if (terms != null)
- //{
- // MatchCollection matcher = pattern.Matches("");
- // try
- // {
- // TermsEnum termsEnum = terms.Iterator(null);
+ int prefixLength = prefix.Length;
+ Terms terms = MultiFields.GetTerms(reader, fieldName);
+ if (terms != null)
+ {
+ TermsEnum termsEnum = terms.Iterator(null);
- // TermsEnum.SeekStatus status = termsEnum.SeekCeil(prefixRef);
- // BytesRef text;
- // if (status == TermsEnum.SeekStatus.FOUND)
- // {
- // text = prefixRef;
- // }
- // else if (status == TermsEnum.SeekStatus.NOT_FOUND)
- // {
- // text = termsEnum.Term();
- // }
- // else
- // {
- // text = null;
- // }
+ TermsEnum.SeekStatus status = termsEnum.SeekCeil(prefixRef);
+ BytesRef text;
+ if (status == TermsEnum.SeekStatus.FOUND)
+ {
+ text = prefixRef;
+ }
+ else if (status == TermsEnum.SeekStatus.NOT_FOUND)
+ {
+ text = termsEnum.Term();
+ }
+ else
+ {
+ text = null;
+ }
- // while (text != null)
- // {
- // if (text != null && StringHelper.StartsWith(text, prefixRef))
- // {
- // string textString = text.Utf8ToString();
- // matcher.Reset(textString.Substring(prefixLength));
- // if (matcher.Success)
- // {
- // mtv.VisitMatchingTerm(new Term(fieldName, textString));
- // }
- // }
- // else
- // {
- // break;
- // }
- // text = termsEnum.Next();
- // }
- // }
- // finally
- // {
- // matcher.Reset();
- // }
- //}
+ while (text != null)
+ {
+ if (text != null && StringHelper.StartsWith(text, prefixRef))
+ {
+ string textString = text.Utf8ToString();
+ // LUCENENET NOTE: Java's matches() method checks to see if the
+ // entire string is a match with the regex, so we mimic that
+ // by testing to ensure the lengths of the input and match are equal
+ // as well as whether it is successful.
+ string toMatchEntirely = textString.Substring(prefixLength);
+ Match matcher = pattern.Match(toMatchEntirely);
+ if (matcher.Success && matcher.Length == toMatchEntirely.Length)
+ {
+ mtv.VisitMatchingTerm(new Term(fieldName, textString));
+ }
+ }
+ else
+ {
+ break;
+ }
+ text = termsEnum.Next();
+ }
+ }
}
}
}