21 using Term = Lucene.Net.Index.Term;
23 namespace Lucene.Net.Search
34 internal Term searchTerm;
35 internal System.String field;
36 internal System.String text;
37 internal System.String pre;
39 internal bool endEnum =
false;
49 field = searchTerm.Field;
50 System.String searchTermText = searchTerm.Text;
52 int sidx = searchTermText.IndexOf((System.Char) WILDCARD_STRING);
53 int cidx = searchTermText.IndexOf((System.Char) WILDCARD_CHAR);
61 idx = System.Math.Min(idx, cidx);
63 pre = idx != - 1?searchTerm.Text.Substring(0, (idx) - (0)):
"";
66 text = searchTermText.Substring(preLen);
67 SetEnum(reader.Terms(
new Term(searchTerm.Field, pre)));
70 protected internal override bool TermCompare(
Term term)
72 if ((System.Object) field == (System.Object) term.Field)
74 System.String searchText = term.Text;
75 if (searchText.StartsWith(pre))
77 return WildcardEquals(text, 0, searchText, preLen);
84 public override float Difference()
89 public override bool EndEnum()
99 public const char WILDCARD_STRING =
'*';
100 public const char WILDCARD_CHAR =
'?';
106 public static bool WildcardEquals(System.String pattern,
int patternIdx, System.String string_Renamed,
int stringIdx)
110 for (
int s = stringIdx; ; ++p, ++s)
113 bool sEnd = (s >= string_Renamed.Length);
115 bool pEnd = (p >= pattern.Length);
121 bool justWildcardsLeft =
true;
124 int wildcardSearchPos = p;
127 while (wildcardSearchPos < pattern.Length && justWildcardsLeft)
130 char wildchar = pattern[wildcardSearchPos];
134 if (wildchar != WILDCARD_CHAR && wildchar != WILDCARD_STRING)
136 justWildcardsLeft =
false;
141 if (wildchar == WILDCARD_CHAR)
153 if (justWildcardsLeft)
167 if (pattern[p] == WILDCARD_CHAR)
173 if (pattern[p] == WILDCARD_STRING)
176 while (p < pattern.Length && pattern[p] == WILDCARD_STRING)
179 for (
int i = string_Renamed.Length; i >= s; --i)
181 if (WildcardEquals(pattern, p, string_Renamed, i))
188 if (pattern[p] != string_Renamed[s])