2 * Copyright 2004 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using IndexReader
= Lucene
.Net
.Index
.IndexReader
;
19 using Term
= Lucene
.Net
.Index
.Term
;
20 using FilteredTermEnum
= Lucene
.Net
.Search
.FilteredTermEnum
;
21 using Pattern
= System
.Text
.RegularExpressions
.Regex
;
23 namespace Lucene
.Net
.Search
.Regex
26 public class RegexTermEnum
: FilteredTermEnum
28 private System
.String field
= "";
29 private System
.String pre
= "";
30 internal bool endEnum
= false;
31 private Pattern pattern
;
33 public RegexTermEnum(IndexReader reader
, Term term
) : base()
36 System
.String text
= term
.Text();
38 pattern
= new Pattern(text
);
40 // Find the first regex character position, to find the
41 // maximum prefix to use for term enumeration
43 while (index
< text
.Length
)
47 if (!System
.Char
.IsLetterOrDigit(c
))
53 pre
= text
.Substring(0, (index
) - (0));
55 SetEnum(reader
.Terms(new Term(term
.Field(), pre
)));
58 protected internal override bool TermCompare(Term term
)
60 if ((System
.Object
) field
== (System
.Object
) term
.Field())
62 System
.String searchText
= term
.Text();
63 if (searchText
.StartsWith(pre
))
65 return pattern
.Match(searchText
).Success
;
72 public override float Difference()
74 // TODO: adjust difference based on distance of searchTerm.text() and term().text()
78 public override bool EndEnum()
83 public override void Close()