本文整理汇总了C#中Lucene.Net.Index.IndexReader.Terms方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Index.IndexReader.Terms方法的具体用法?C# Lucene.Net.Index.IndexReader.Terms怎么用?C# Lucene.Net.Index.IndexReader.Terms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexReader
的用法示例。
在下文中一共展示了Lucene.Net.Index.IndexReader.Terms方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegexTermEnum
public RegexTermEnum(IndexReader reader, Term term)
: base()
{
field = term.Field();
System.String text = term.Text();
pattern = new Pattern(text);
// Find the first regex character position, to find the
// maximum prefix to use for term enumeration
int index = 0;
while (index < text.Length)
{
char c = text[index];
if (!System.Char.IsLetterOrDigit(c))
break;
index++;
}
pre = text.Substring(0, (index) - (0));
SetEnum(reader.Terms(new Term(term.Field(), pre)));
}
示例2: CreateValue
protected internal override System.Object CreateValue(IndexReader reader, System.Object entryKey)
{
Entry entry = (Entry) entryKey;
System.String field = entry.field;
LongParser parser = (LongParser) entry.custom;
long[] retArray = new long[reader.MaxDoc()];
TermDocs termDocs = reader.TermDocs();
TermEnum termEnum = reader.Terms(new Term(field, ""));
try
{
do
{
Term term = termEnum.Term();
if (term == null || (System.Object) term.Field() != (System.Object) field)
break;
long termval = parser.ParseLong(term.Text());
termDocs.Seek(termEnum);
while (termDocs.Next())
{
retArray[termDocs.Doc()] = termval;
}
}
while (termEnum.Next());
}
finally
{
termDocs.Close();
termEnum.Close();
}
return retArray;
}
示例3: Rewrite
public override Query Rewrite(IndexReader reader)
{
BooleanQuery query = new BooleanQuery(true);
TermEnum enumerator = reader.Terms(prefix);
try
{
System.String prefixText = prefix.Text();
System.String prefixField = prefix.Field();
do
{
Term term = enumerator.Term();
if (term != null && term.Text().StartsWith(prefixText) && term.Field() == prefixField)
{
TermQuery tq = new TermQuery(term); // found a match
tq.SetBoost(GetBoost()); // set the boost
query.Add(tq, BooleanClause.Occur.SHOULD); // add to query
//System.out.println("added " + term);
}
else
{
break;
}
}
while (enumerator.Next());
}
finally
{
enumerator.Close();
}
return query;
}
示例4: Rewrite
public override Query Rewrite(IndexReader reader)
{
BooleanQuery query = new BooleanQuery(true);
TermEnum enumerator = reader.Terms(lowerTerm);
try
{
bool checkLower = false;
if (!inclusive)
// make adjustments to set to exclusive
checkLower = true;
System.String testField = GetField();
do
{
Term term = enumerator.Term();
if (term != null && term.Field() == testField)
{
if (!checkLower || String.CompareOrdinal(term.Text(), lowerTerm.Text()) > 0)
{
checkLower = false;
if (upperTerm != null)
{
int compare = String.CompareOrdinal(upperTerm.Text(), term.Text());
/* if beyond the upper term, or is exclusive and
* this is equal to the upper term, break out */
if ((compare < 0) || (!inclusive && compare == 0))
break;
}
TermQuery tq = new TermQuery(term); // found a match
tq.SetBoost(GetBoost()); // set the boost
query.Add(tq, BooleanClause.Occur.SHOULD); // add to query
}
}
else
{
break;
}
}
while (enumerator.Next());
}
finally
{
enumerator.Close();
}
return query;
}
示例5: WildcardTermEnum
/// <summary> Creates a new <c>WildcardTermEnum</c>.
/// <p/>
/// After calling the constructor the enumeration is already pointing to the first
/// valid term if such a term exists.
/// </summary>
public WildcardTermEnum(IndexReader reader, Term term):base()
{
searchTerm = term;
field = searchTerm.Field;
System.String searchTermText = searchTerm.Text;
int sidx = searchTermText.IndexOf((System.Char) WILDCARD_STRING);
int cidx = searchTermText.IndexOf((System.Char) WILDCARD_CHAR);
int idx = sidx;
if (idx == - 1)
{
idx = cidx;
}
else if (cidx >= 0)
{
idx = System.Math.Min(idx, cidx);
}
pre = idx != - 1?searchTerm.Text.Substring(0, (idx) - (0)):"";
preLen = pre.Length;
text = searchTermText.Substring(preLen);
SetEnum(reader.Terms(new Term(searchTerm.Field, pre)));
}
示例6: CreateValue
protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
{
Entry entry = (Entry) entryKey;
System.String field = entry.field;
SortComparator comparator = (SortComparator) entry.custom;
System.IComparable[] retArray = new System.IComparable[reader.MaxDoc()];
TermDocs termDocs = reader.TermDocs();
TermEnum termEnum = reader.Terms(new Term(field));
try
{
do
{
Term term = termEnum.Term();
if (term == null || (System.Object) term.Field() != (System.Object) field)
break;
System.IComparable termval = comparator.GetComparable(term.Text());
termDocs.Seek(termEnum);
while (termDocs.Next())
{
retArray[termDocs.Doc()] = termval;
}
}
while (termEnum.Next());
}
finally
{
termDocs.Close();
termEnum.Close();
}
return retArray;
}
示例7: GetAuto
/// <summary>The pattern used to detect integer values in a field </summary>
/// <summary>removed for java 1.3 compatibility
/// protected static final Pattern pIntegers = Pattern.compile ("[0-9\\-]+");
///
/// </summary>
/// <summary>The pattern used to detect float values in a field </summary>
/// <summary> removed for java 1.3 compatibility
/// protected static final Object pFloats = Pattern.compile ("[0-9+\\-\\.eEfFdD]+");
/// </summary>
// inherit javadocs
public virtual System.Object GetAuto(IndexReader reader, System.String field)
{
field = String.Intern(field);
System.Object ret = Lookup(reader, field, SortField.AUTO);
if (ret == null)
{
TermEnum enumerator = reader.Terms(new Term(field, ""));
try
{
Term term = enumerator.Term();
if (term == null)
{
throw new System.SystemException("no terms in field " + field + " - cannot determine sort type");
}
if (term.Field() == field)
{
System.String termtext = term.Text().Trim();
/**
* Java 1.4 level code:
if (pIntegers.matcher(termtext).matches())
return IntegerSortedHitQueue.comparator (reader, enumerator, field);
else if (pFloats.matcher(termtext).matches())
return FloatSortedHitQueue.comparator (reader, enumerator, field);
*/
// Java 1.3 level code:
try
{
System.Int32.Parse(termtext);
ret = GetInts(reader, field);
}
catch (System.FormatException nfe1)
{
try
{
System.Single.Parse(termtext);
ret = GetFloats(reader, field);
}
catch (System.FormatException nfe2)
{
ret = GetStringIndex(reader, field);
}
}
if (ret != null)
{
Store(reader, field, SortField.AUTO, ret);
}
}
else
{
throw new System.SystemException("field \"" + field + "\" does not appear to be indexed");
}
}
finally
{
enumerator.Close();
}
}
return ret;
}
示例8: CreateValue
protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
{
System.String field = StringHelper.Intern(entryKey.field);
System.String[] retArray = new System.String[reader.MaxDoc];
TermDocs termDocs = reader.TermDocs();
TermEnum termEnum = reader.Terms(new Term(field));
try
{
do
{
Term term = termEnum.Term;
if (term == null || (System.Object) term.Field != (System.Object) field)
break;
System.String termval = term.Text;
termDocs.Seek(termEnum);
while (termDocs.Next())
{
retArray[termDocs.Doc] = termval;
}
}
while (termEnum.Next());
}
finally
{
termDocs.Close();
termEnum.Close();
}
return retArray;
}
示例9: CreateValue
protected internal override object CreateValue(IndexReader reader, object fieldKey)
{
System.String field = String.Intern(((System.String) fieldKey));
System.String[] retArray = new System.String[reader.MaxDoc()];
TermDocs termDocs = reader.TermDocs();
TermEnum termEnum = reader.Terms(new Term(field));
try
{
do
{
Term term = termEnum.Term();
if (term == null || (object) term.Field() != (object) field)
break;
System.String termval = term.Text();
termDocs.Seek(termEnum);
while (termDocs.Next())
{
retArray[termDocs.Doc()] = termval;
}
}
while (termEnum.Next());
}
finally
{
termDocs.Close();
termEnum.Close();
}
return retArray;
}
示例10: NewComparator
public virtual ScoreDocComparator NewComparator(IndexReader reader, System.String fieldname)
{
System.String field = String.Intern(fieldname);
TermEnum enumerator = reader.Terms(new Term(fieldname, ""));
try
{
return new AnonymousClassScoreDocComparator(reader, enumerator, field, this);
}
finally
{
enumerator.Close();
}
}
示例11: Generate
public virtual void Generate(IndexReader reader)
{
TermEnum enumerator = reader.Terms(prefix);
TermDocs termDocs = reader.TermDocs();
try
{
System.String prefixText = prefix.Text();
System.String prefixField = prefix.Field();
do
{
Term term = enumerator.Term();
if (term != null && term.Text().StartsWith(prefixText) && (System.Object) term.Field() == (System.Object) prefixField)
{
termDocs.Seek(term);
while (termDocs.Next())
{
HandleDoc(termDocs.Doc());
}
}
else
{
break;
}
}
while (enumerator.Next());
}
finally
{
termDocs.Close();
enumerator.Close();
}
}
示例12: Bits
/// <summary> Returns a BitSet with true for documents which should be
/// permitted in search results, and false for those that should
/// not.
/// </summary>
public override System.Collections.BitArray Bits(IndexReader reader)
{
System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64);
TermEnum enumerator = reader.Terms(new Term(field, start));
TermDocs termDocs = reader.TermDocs();
if (enumerator.Term() == null)
{
return bits;
}
try
{
Term stop = new Term(field, end);
while (enumerator.Term().CompareTo(stop) <= 0)
{
termDocs.Seek(enumerator.Term());
while (termDocs.Next())
{
bits.Set(termDocs.Doc(), true);
}
if (!enumerator.Next())
{
break;
}
}
}
finally
{
enumerator.Close();
termDocs.Close();
}
return bits;
}
示例13: PrefixTermEnum
public PrefixTermEnum(IndexReader reader, Term prefix)
{
this.prefix = prefix;
SetEnum(reader.Terms(new Term(prefix.Field, prefix.Text)));
}
示例14: Rewrite
public override Query Rewrite(IndexReader reader)
{
BooleanQuery query = new BooleanQuery(true);
string testField = GetField();
if (collator != null)
{
TermEnum enumerator = reader.Terms(new Term(testField, ""));
string lowerTermText = lowerTerm != null ? lowerTerm.Text() : null;
string upperTermText = upperTerm != null ? upperTerm.Text() : null;
try
{
do
{
Term term = enumerator.Term();
if (term != null && term.Field() == testField) // interned comparison
{
if ((lowerTermText == null ||
(inclusive ? collator.Compare(term.Text(), lowerTermText) >= 0 : collator.Compare(term.Text(), lowerTermText) > 0))
&&
(upperTermText == null ||
(inclusive ? collator.Compare(term.Text(), upperTermText) <= 0 : collator.Compare(term.Text(), upperTermText) < 0))
)
{
AddTermToQuery(term, query);
}
}
}
while (enumerator.Next());
}
finally
{
enumerator.Close();
}
}
else
{
TermEnum enumerator = reader.Terms(lowerTerm);
try
{
bool checkLower = false;
if (!inclusive)
// make adjustments to set to exclusive
checkLower = true;
do
{
Term term = enumerator.Term();
if (term != null && term.Field() == testField)
{
// interned comparison
if (!checkLower || String.CompareOrdinal(term.Text(), lowerTerm.Text()) > 0)
{
checkLower = false;
if (upperTerm != null)
{
int compare = String.CompareOrdinal(upperTerm.Text(), term.Text());
/* if beyond the upper term, or is exclusive and
* this is equal to the upper term, break out */
if ((compare < 0) || (!inclusive && compare == 0))
break;
}
AddTermToQuery(term, query); // Found a match
}
}
else
{
break;
}
}
while (enumerator.Next());
}
finally
{
enumerator.Close();
}
}
return query;
}
示例15: CreateValue
protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
{
Entry entry = (Entry) entryKey;
System.String field = entry.field;
ByteParser parser = (ByteParser) entry.custom;
if (parser == null)
{
return wrapper.GetBytes(reader, field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_BYTE_PARSER);
}
byte[] retArray = new byte[reader.MaxDoc()];
TermDocs termDocs = reader.TermDocs();
TermEnum termEnum = reader.Terms(new Term(field));
try
{
do
{
Term term = termEnum.Term();
if (term == null || (System.Object) term.Field() != (System.Object) field)
break;
byte termval = parser.ParseByte(term.Text());
termDocs.Seek(termEnum);
while (termDocs.Next())
{
retArray[termDocs.Doc()] = termval;
}
}
while (termEnum.Next());
}
catch (StopFillCacheException stop)
{
}
finally
{
termDocs.Close();
termEnum.Close();
}
return retArray;
}