本文整理汇总了C#中Fields.Terms方法的典型用法代码示例。如果您正苦于以下问题:C# Fields.Terms方法的具体用法?C# Fields.Terms怎么用?C# Fields.Terms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fields
的用法示例。
在下文中一共展示了Fields.Terms方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertFieldsEquals
/// <summary>
/// Fields api equivalency
/// </summary>
public void AssertFieldsEquals(string info, IndexReader leftReader, Fields leftFields, Fields rightFields, bool deep)
{
// Fields could be null if there are no postings,
// but then it must be null for both
if (leftFields == null || rightFields == null)
{
Assert.IsNull(leftFields, info);
Assert.IsNull(rightFields, info);
return;
}
AssertFieldStatisticsEquals(info, leftFields, rightFields);
IEnumerator<string> leftEnum = leftFields.GetEnumerator();
IEnumerator<string> rightEnum = rightFields.GetEnumerator();
while (leftEnum.MoveNext())
{
string field = leftEnum.Current;
rightEnum.MoveNext();
Assert.AreEqual(field, rightEnum.Current, info);
AssertTermsEquals(info, leftReader, leftFields.Terms(field), rightFields.Terms(field), deep);
}
Assert.IsFalse(rightEnum.MoveNext());
}
示例2: AssertEquals
protected internal virtual void AssertEquals(RandomDocument doc, Fields fields)
{
// compare field names
Assert.AreEqual(doc == null, fields == null);
Assert.AreEqual(doc.FieldNames.Length, fields.Size);
HashSet<string> fields1 = new HashSet<string>();
HashSet<string> fields2 = new HashSet<string>();
for (int i = 0; i < doc.FieldNames.Length; ++i)
{
fields1.Add(doc.FieldNames[i]);
}
foreach (string field in fields)
{
fields2.Add(field);
}
Assert.IsTrue(fields1.SetEquals(fields2));
for (int i = 0; i < doc.FieldNames.Length; ++i)
{
AssertEquals(doc.TokenStreams[i], doc.FieldTypes[i], fields.Terms(doc.FieldNames[i]));
}
}
示例3: TestTermsOneThread
private void TestTermsOneThread(Fields fieldsSource, ISet<Option> options, FieldInfo.IndexOptions maxTestOptions, FieldInfo.IndexOptions maxIndexOptions, bool alwaysTestMax)
{
ThreadState threadState = new ThreadState();
// Test random terms/fields:
IList<TermState> termStates = new List<TermState>();
IList<FieldAndTerm> termStateTerms = new List<FieldAndTerm>();
AllTerms = CollectionsHelper.Shuffle(AllTerms);
int upto = 0;
while (upto < AllTerms.Count)
{
bool useTermState = termStates.Count != 0 && Random().Next(5) == 1;
FieldAndTerm fieldAndTerm;
TermsEnum termsEnum;
TermState termState = null;
if (!useTermState)
{
// Seek by random field+term:
fieldAndTerm = AllTerms[upto++];
if (VERBOSE)
{
Console.WriteLine("\nTEST: seek to term=" + fieldAndTerm.Field + ":" + fieldAndTerm.Term.Utf8ToString());
}
}
else
{
// Seek by previous saved TermState
int idx = Random().Next(termStates.Count);
fieldAndTerm = termStateTerms[idx];
if (VERBOSE)
{
Console.WriteLine("\nTEST: seek using TermState to term=" + fieldAndTerm.Field + ":" + fieldAndTerm.Term.Utf8ToString());
}
termState = termStates[idx];
}
Terms terms = fieldsSource.Terms(fieldAndTerm.Field);
Assert.IsNotNull(terms);
termsEnum = terms.Iterator(null);
if (!useTermState)
{
Assert.IsTrue(termsEnum.SeekExact(fieldAndTerm.Term));
}
else
{
termsEnum.SeekExact(fieldAndTerm.Term, termState);
}
bool savedTermState = false;
if (options.Contains(Option.TERM_STATE) && !useTermState && Random().Next(5) == 1)
{
// Save away this TermState:
termStates.Add(termsEnum.TermState());
termStateTerms.Add(fieldAndTerm);
savedTermState = true;
}
VerifyEnum(threadState, fieldAndTerm.Field, fieldAndTerm.Term, termsEnum, maxTestOptions, maxIndexOptions, options, alwaysTestMax);
// Sometimes save term state after pulling the enum:
if (options.Contains(Option.TERM_STATE) && !useTermState && !savedTermState && Random().Next(5) == 1)
{
// Save away this TermState:
termStates.Add(termsEnum.TermState());
termStateTerms.Add(fieldAndTerm);
useTermState = true;
}
// 10% of the time make sure you can pull another enum
// from the same term:
if (alwaysTestMax || Random().Next(10) == 7)
{
// Try same term again
if (VERBOSE)
{
Console.WriteLine("TEST: try enum again on same term");
}
VerifyEnum(threadState, fieldAndTerm.Field, fieldAndTerm.Term, termsEnum, maxTestOptions, maxIndexOptions, options, alwaysTestMax);
}
}
}
示例4: VerifyVectors
private void VerifyVectors(Fields vectors, int num)
{
foreach (string field in vectors)
{
Terms terms = vectors.Terms(field);
Debug.Assert(terms != null);
VerifyVector(terms.Iterator(null), num);
}
}
示例5: CheckFields
/// <summary>
/// checks Fields api is consistent with itself.
/// searcher is optional, to verify with queries. Can be null.
/// </summary>
private static Status.TermIndexStatus CheckFields(Fields fields, Bits liveDocs, int maxDoc, FieldInfos fieldInfos, bool doPrint, bool isVectors, TextWriter infoStream, bool verbose)
{
// TODO: we should probably return our own stats thing...?!
Status.TermIndexStatus status = new Status.TermIndexStatus();
int computedFieldCount = 0;
if (fields == null)
{
Msg(infoStream, "OK [no fields/terms]");
return status;
}
DocsEnum docs = null;
DocsEnum docsAndFreqs = null;
DocsAndPositionsEnum postings = null;
string lastField = null;
foreach (string field in fields)
{
// MultiFieldsEnum relies upon this order...
if (lastField != null && field.CompareTo(lastField) <= 0)
{
throw new Exception("fields out of order: lastField=" + lastField + " field=" + field);
}
lastField = field;
// check that the field is in fieldinfos, and is indexed.
// TODO: add a separate test to check this for different reader impls
FieldInfo fieldInfo = fieldInfos.FieldInfo(field);
if (fieldInfo == null)
{
throw new Exception("fieldsEnum inconsistent with fieldInfos, no fieldInfos for: " + field);
}
if (!fieldInfo.Indexed)
{
throw new Exception("fieldsEnum inconsistent with fieldInfos, isIndexed == false for: " + field);
}
// TODO: really the codec should not return a field
// from FieldsEnum if it has no Terms... but we do
// this today:
// assert fields.terms(field) != null;
computedFieldCount++;
Terms terms = fields.Terms(field);
if (terms == null)
{
continue;
}
bool hasFreqs = terms.HasFreqs();
bool hasPositions = terms.HasPositions();
bool hasPayloads = terms.HasPayloads();
bool hasOffsets = terms.HasOffsets();
// term vectors cannot omit TF:
bool expectedHasFreqs = (isVectors || fieldInfo.FieldIndexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS);
if (hasFreqs != expectedHasFreqs)
{
throw new Exception("field \"" + field + "\" should have hasFreqs=" + expectedHasFreqs + " but got " + hasFreqs);
}
if (hasFreqs == false)
{
if (terms.SumTotalTermFreq != -1)
{
throw new Exception("field \"" + field + "\" hasFreqs is false, but Terms.getSumTotalTermFreq()=" + terms.SumTotalTermFreq + " (should be -1)");
}
}
if (!isVectors)
{
bool expectedHasPositions = fieldInfo.FieldIndexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
if (hasPositions != expectedHasPositions)
{
throw new Exception("field \"" + field + "\" should have hasPositions=" + expectedHasPositions + " but got " + hasPositions);
}
bool expectedHasPayloads = fieldInfo.HasPayloads();
if (hasPayloads != expectedHasPayloads)
{
throw new Exception("field \"" + field + "\" should have hasPayloads=" + expectedHasPayloads + " but got " + hasPayloads);
}
bool expectedHasOffsets = fieldInfo.FieldIndexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
if (hasOffsets != expectedHasOffsets)
{
throw new Exception("field \"" + field + "\" should have hasOffsets=" + expectedHasOffsets + " but got " + hasOffsets);
}
}
TermsEnum termsEnum = terms.Iterator(null);
bool hasOrd = true;
//.........这里部分代码省略.........
示例6: DirectFields
public DirectFields(SegmentReadState state, Fields fields, int minSkipCount, int lowFreqCutoff)
{
foreach (string field in fields)
{
this.fields[field] = new DirectField(state, field, fields.Terms(field), minSkipCount, lowFreqCutoff);
}
}
示例7: AddAllDocVectors
/// <summary>
/// Safe (but, slowish) default method to write every
/// vector field in the document.
/// </summary>
protected internal void AddAllDocVectors(Fields vectors, MergeState mergeState)
{
if (vectors == null)
{
StartDocument(0);
FinishDocument();
return;
}
int numFields = vectors.Size();
if (numFields == -1)
{
// count manually! TODO: Maybe enforce that Fields.size() returns something valid?
numFields = 0;
//for (IEnumerator<string> it = vectors.Iterator(); it.hasNext();)
foreach (string it in vectors)
{
numFields++;
}
}
StartDocument(numFields);
string lastFieldName = null;
TermsEnum termsEnum = null;
DocsAndPositionsEnum docsAndPositionsEnum = null;
int fieldCount = 0;
foreach (string fieldName in vectors)
{
fieldCount++;
FieldInfo fieldInfo = mergeState.FieldInfos.FieldInfo(fieldName);
Debug.Assert(lastFieldName == null || fieldName.CompareTo(lastFieldName) > 0, "lastFieldName=" + lastFieldName + " fieldName=" + fieldName);
lastFieldName = fieldName;
Terms terms = vectors.Terms(fieldName);
if (terms == null)
{
// FieldsEnum shouldn't lie...
continue;
}
bool hasPositions = terms.HasPositions();
bool hasOffsets = terms.HasOffsets();
bool hasPayloads = terms.HasPayloads();
Debug.Assert(!hasPayloads || hasPositions);
int numTerms = (int)terms.Size();
if (numTerms == -1)
{
// count manually. It is stupid, but needed, as Terms.size() is not a mandatory statistics function
numTerms = 0;
termsEnum = terms.Iterator(termsEnum);
while (termsEnum.Next() != null)
{
numTerms++;
}
}
StartField(fieldInfo, numTerms, hasPositions, hasOffsets, hasPayloads);
termsEnum = terms.Iterator(termsEnum);
int termCount = 0;
while (termsEnum.Next() != null)
{
termCount++;
int freq = (int)termsEnum.TotalTermFreq();
StartTerm(termsEnum.Term(), freq);
if (hasPositions || hasOffsets)
{
docsAndPositionsEnum = termsEnum.DocsAndPositions(null, docsAndPositionsEnum);
Debug.Assert(docsAndPositionsEnum != null);
int docID = docsAndPositionsEnum.NextDoc();
Debug.Assert(docID != DocIdSetIterator.NO_MORE_DOCS);
Debug.Assert(docsAndPositionsEnum.Freq() == freq);
for (int posUpto = 0; posUpto < freq; posUpto++)
{
int pos = docsAndPositionsEnum.NextPosition();
int startOffset = docsAndPositionsEnum.StartOffset();
int endOffset = docsAndPositionsEnum.EndOffset();
BytesRef payload = docsAndPositionsEnum.Payload;
Debug.Assert(!hasPositions || pos >= 0);
AddPosition(pos, startOffset, endOffset, payload);
}
}
FinishTerm();
}
Debug.Assert(termCount == numTerms);
//.........这里部分代码省略.........