本文整理汇总了C#中Lucene.Net.Index.IndexReader.IsDeleted方法的典型用法代码示例。如果您正苦于以下问题:C# IndexReader.IsDeleted方法的具体用法?C# IndexReader.IsDeleted怎么用?C# IndexReader.IsDeleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexReader
的用法示例。
在下文中一共展示了IndexReader.IsDeleted方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeLatestVersionLookupPerReader
static void MakeLatestVersionLookupPerReader(IDictionary<string, Tuple<NuGetVersion, string, int>> lookup, IndexReader reader, string readerName, bool includePrerelease, bool includeUnlisted)
{
for (int n = 0; n < reader.MaxDoc; n++)
{
if (reader.IsDeleted(n))
{
continue;
}
Document document = reader.Document(n);
NuGetVersion version = GetVersion(document);
if (version == null)
{
continue;
}
bool isListed = GetListed(document);
if (isListed || includeUnlisted)
{
if (!version.IsPrerelease || includePrerelease)
{
string id = GetId(document);
if (id == null)
{
continue;
}
Tuple<NuGetVersion, string, int> existingVersion;
if (lookup.TryGetValue(id, out existingVersion))
{
if (version > existingVersion.Item1)
{
lookup[id] = Tuple.Create(version, readerName, n);
}
}
else
{
lookup.Add(id, Tuple.Create(version, readerName, n));
}
}
}
}
}
示例2: ProcessReader
void ProcessReader(IndexReader indexReader, string readerName, ref int perIndexDocumentNumber)
{
for (int perReaderDocumentNumber = 0; perReaderDocumentNumber < indexReader.MaxDoc; perReaderDocumentNumber++)
{
if (indexReader.IsDeleted(perReaderDocumentNumber))
{
ProcessDocument(indexReader, readerName, perReaderDocumentNumber, perIndexDocumentNumber, null, isDelete: true);
}
else
{
Document document = indexReader.Document(perReaderDocumentNumber);
ProcessDocument(indexReader, readerName, perReaderDocumentNumber, perIndexDocumentNumber, document, isDelete: false);
}
perIndexDocumentNumber++;
}
}
示例3: GetCustomScoreProvider
protected override CustomScoreProvider GetCustomScoreProvider(IndexReader reader)
{
int maxDoc = reader.MaxDoc;
long[] daysAgo = new long[maxDoc];
long[] publishDate = FieldCache_Fields.DEFAULT.GetLongs(reader, SearchDocument.TimeStampFieldName);
long currentDate = DateTime.UtcNow.ToFileTime();
long timeSpanFromDaysTicks = TimeSpan.FromDays(36500).Ticks;
for (int i = 0; i < maxDoc; i++)
{
if (!reader.IsDeleted(i))
daysAgo[i] = currentDate - publishDate[i];
}
var recencyData = new RecencyOptions(daysAgo, 5, timeSpanFromDaysTicks);
return new RecencyScoreProvider(reader, recencyData);
}
示例4: PackageVersions
public PackageVersions(IndexReader reader)
{
_reader = reader;
_registrations = new Dictionary<string, List<NuGetVersion>>();
for (int i = 0; i < reader.MaxDoc; i++)
{
if (reader.IsDeleted(i))
{
continue;
}
Document document = reader[i];
NuGetVersion currentVersion = GetVersion(document);
if (currentVersion == null)
{
continue;
}
string id = GetId(document);
if (id == null)
{
continue;
}
List<NuGetVersion> versions;
if (!_registrations.TryGetValue(id, out versions))
{
versions = new List<NuGetVersion>();
_registrations.Add(id, versions);
}
versions.Add(currentVersion);
}
foreach (List<NuGetVersion> values in _registrations.Values)
{
values.Sort();
}
}
示例5: Execute
public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
if (_indexDirectory == null)
yield break;
try {
_reader = IndexReader.Open(_indexDirectory, true);
}
catch (Exception) {
Warn("Failed to open lucene index in {0}.", _indexDirectory.Directory.FullName);
yield break;
}
var docCount = _reader.NumDocs();
Info("Found {0} documents in lucene index.", docCount);
for (var i = 0; i < docCount; i++) {
if (_reader.IsDeleted(i))
continue;
var doc = _reader.Document(i);
var row = new Row();
foreach (var field in doc.GetFields().Where(field => field.IsStored)) {
switch (field.Name) {
case "dropped":
row[field.Name] = Convert.ToBoolean(field.StringValue);
break;
default:
row[field.Name] = field.StringValue;
break;
}
}
yield return row;
}
}
示例6: GetDistintTenantId
public static IEnumerable<string> GetDistintTenantId(IndexReader reader)
{
HashSet<string> result = new HashSet<string>();
for (int i = 0; i < reader.MaxDoc; i++)
{
if (reader.IsDeleted(i))
{
continue;
}
Document document = reader[i];
string tenantId = document.Get("TenantId");
if (tenantId != null)
{
result.Add(tenantId);
}
}
return result;
}
示例7: FillCache
private static Dictionary<string, int[]> FillCache(IndexReader reader, int docBase, string field)
{
using (var termDocs = reader.TermDocs())
{
var items = new Dictionary<string, int[]>();
var docsForTerm = new List<int>();
using (var termEnum = reader.Terms(new Term(field)))
{
do
{
if (termEnum.Term == null || field != termEnum.Term.Field)
break;
Term term = termEnum.Term;
if (LowPrecisionNumber(term.Field, term.Text))
continue;
var totalDocCountIncludedDeletes = termEnum.DocFreq();
termDocs.Seek(termEnum.Term);
while (termDocs.Next() && totalDocCountIncludedDeletes > 0)
{
var curDoc = termDocs.Doc;
totalDocCountIncludedDeletes -= 1;
if (reader.IsDeleted(curDoc))
continue;
docsForTerm.Add(curDoc + docBase);
}
docsForTerm.Sort();
items[term.Text] = docsForTerm.ToArray();
docsForTerm.Clear();
} while (termEnum.Next());
}
return items;
}
}
示例8: CopyVectorsWithDeletions
private void CopyVectorsWithDeletions(TermVectorsWriter termVectorsWriter, TermVectorsReader matchingVectorsReader, IndexReader reader)
{
int maxDoc = reader.MaxDoc();
if (matchingVectorsReader != null)
{
// We can bulk-copy because the fieldInfos are "congruent"
for (int docNum = 0; docNum < maxDoc; )
{
if (reader.IsDeleted(docNum))
{
// skip deleted docs
++docNum;
continue;
}
// We can optimize this case (doing a bulk byte copy) since the field
// numbers are identical
int start = docNum, numDocs = 0;
do
{
docNum++;
numDocs++;
if (docNum >= maxDoc)
break;
if (reader.IsDeleted(docNum))
{
docNum++;
break;
}
}
while (numDocs < MAX_RAW_MERGE_DOCS);
matchingVectorsReader.RawDocs(rawDocLengths, rawDocLengths2, start, numDocs);
termVectorsWriter.AddRawDocuments(matchingVectorsReader, rawDocLengths, rawDocLengths2, numDocs);
checkAbort.Work(300 * numDocs);
}
}
else
{
for (int docNum = 0; docNum < maxDoc; docNum++)
{
if (reader.IsDeleted(docNum))
{
// skip deleted docs
continue;
}
// NOTE: it's very important to first assign to vectors then pass it to
// termVectorsWriter.addAllDocVectors; see LUCENE-1282
TermFreqVector[] vectors = reader.GetTermFreqVectors(docNum);
termVectorsWriter.AddAllDocVectors(vectors);
checkAbort.Work(300);
}
}
}
示例9: CopyFieldsWithDeletions
private int CopyFieldsWithDeletions(FieldSelector fieldSelectorMerge, FieldsWriter fieldsWriter, IndexReader reader, FieldsReader matchingFieldsReader)
{
int docCount = 0;
int maxDoc = reader.MaxDoc();
if (matchingFieldsReader != null)
{
// We can bulk-copy because the fieldInfos are "congruent"
for (int j = 0; j < maxDoc; )
{
if (reader.IsDeleted(j))
{
// skip deleted docs
++j;
continue;
}
// We can optimize this case (doing a bulk byte copy) since the field
// numbers are identical
int start = j, numDocs = 0;
do
{
j++;
numDocs++;
if (j >= maxDoc)
break;
if (reader.IsDeleted(j))
{
j++;
break;
}
}
while (numDocs < MAX_RAW_MERGE_DOCS);
IndexInput stream = matchingFieldsReader.RawDocs(rawDocLengths, start, numDocs);
fieldsWriter.AddRawDocuments(stream, rawDocLengths, numDocs);
docCount += numDocs;
checkAbort.Work(300 * numDocs);
}
}
else
{
for (int j = 0; j < maxDoc; j++)
{
if (reader.IsDeleted(j))
{
// skip deleted docs
continue;
}
// NOTE: it's very important to first assign to doc then pass it to
// termVectorsWriter.addAllDocVectors; see LUCENE-1282
Document doc = reader.Document(j, fieldSelectorMerge);
fieldsWriter.AddDocument(doc);
docCount++;
checkAbort.Work(300);
}
}
return docCount;
}
示例10: PerformDefaultTests
/// <summary> 1. Get a norm from the original reader 2. Clone the original reader 3.
/// Delete a document and set the norm of the cloned reader 4. Verify the norms
/// are not the same on each reader 5. Verify the doc deleted is only in the
/// cloned reader 6. Try to delete a document in the original reader, an
/// exception should be thrown
///
/// </summary>
/// <param name="r1">IndexReader to perform tests on
/// </param>
/// <throws> Exception </throws>
private void PerformDefaultTests(IndexReader r1)
{
float norm1 = Similarity.DecodeNorm(r1.Norms("field1")[4]);
IndexReader pr1Clone = (IndexReader) r1.Clone();
pr1Clone.DeleteDocument(10);
pr1Clone.SetNorm(4, "field1", 0.5f);
Assert.IsTrue(Similarity.DecodeNorm(r1.Norms("field1")[4]) == norm1);
Assert.IsTrue(Similarity.DecodeNorm(pr1Clone.Norms("field1")[4]) != norm1);
Assert.IsTrue(!r1.IsDeleted(10));
Assert.IsTrue(pr1Clone.IsDeleted(10));
// try to update the original reader, which should throw an exception
Assert.Throws<LockObtainFailedException>(() => r1.DeleteDocument(11),
"Tried to delete doc 11 and an exception should have been thrown");
pr1Clone.Close();
}
示例11: AssertIndexEquals
public static void AssertIndexEquals(IndexReader index1, IndexReader index2)
{
Assert.AreEqual(index1.NumDocs(), index2.NumDocs(), "IndexReaders have different values for numDocs.");
Assert.AreEqual(index1.MaxDoc, index2.MaxDoc, "IndexReaders have different values for maxDoc.");
Assert.AreEqual(index1.HasDeletions, index2.HasDeletions, "Only one IndexReader has deletions.");
Assert.AreEqual(index1.IsOptimized(), index2.IsOptimized(), "Only one index is optimized.");
// check field names
System.Collections.Generic.ICollection<string> fieldsNames1 = index1.GetFieldNames(FieldOption.ALL);
System.Collections.Generic.ICollection<string> fieldsNames2 = index1.GetFieldNames(FieldOption.ALL);
System.Collections.Generic.ICollection<IFieldable> fields1 = null;
System.Collections.Generic.ICollection<IFieldable> fields2 = null;
Assert.AreEqual(fieldsNames1.Count, fieldsNames2.Count, "IndexReaders have different numbers of fields.");
System.Collections.IEnumerator it1 = fieldsNames1.GetEnumerator();
System.Collections.IEnumerator it2 = fieldsNames2.GetEnumerator();
while (it1.MoveNext() && it2.MoveNext())
{
Assert.AreEqual((System.String) it1.Current, (System.String) it2.Current, "Different field names.");
}
// check norms
it1 = fieldsNames1.GetEnumerator();
while (it1.MoveNext())
{
System.String curField = (System.String) it1.Current;
byte[] norms1 = index1.Norms(curField);
byte[] norms2 = index2.Norms(curField);
if (norms1 != null && norms2 != null)
{
Assert.AreEqual(norms1.Length, norms2.Length);
for (int i = 0; i < norms1.Length; i++)
{
Assert.AreEqual(norms1[i], norms2[i], "Norm different for doc " + i + " and field '" + curField + "'.");
}
}
else
{
Assert.AreSame(norms1, norms2);
}
}
// check deletions
for (int i = 0; i < index1.MaxDoc; i++)
{
Assert.AreEqual(index1.IsDeleted(i), index2.IsDeleted(i), "Doc " + i + " only deleted in one index.");
}
// check stored fields
for (int i = 0; i < index1.MaxDoc; i++)
{
if (!index1.IsDeleted(i))
{
Document doc1 = index1.Document(i);
Document doc2 = index2.Document(i);
fields1 = doc1.GetFields();
fields2 = doc2.GetFields();
Assert.AreEqual(fields1.Count, fields2.Count, "Different numbers of fields for doc " + i + ".");
it1 = fields1.GetEnumerator();
it2 = fields2.GetEnumerator();
while (it1.MoveNext() && it2.MoveNext())
{
Field curField1 = (Field) it1.Current;
Field curField2 = (Field) it2.Current;
Assert.AreEqual(curField1.Name, curField2.Name, "Different fields names for doc " + i + ".");
Assert.AreEqual(curField1.StringValue, curField2.StringValue, "Different field values for doc " + i + ".");
}
}
}
// check dictionary and posting lists
TermEnum enum1 = index1.Terms();
TermEnum enum2 = index2.Terms();
TermPositions tp1 = index1.TermPositions();
TermPositions tp2 = index2.TermPositions();
while (enum1.Next())
{
Assert.IsTrue(enum2.Next());
Assert.AreEqual(enum1.Term, enum2.Term, "Different term in dictionary.");
tp1.Seek(enum1.Term);
tp2.Seek(enum1.Term);
while (tp1.Next())
{
Assert.IsTrue(tp2.Next());
Assert.AreEqual(tp1.Doc, tp2.Doc, "Different doc id in postinglist of term " + enum1.Term + ".");
Assert.AreEqual(tp1.Freq, tp2.Freq, "Different term frequence in postinglist of term " + enum1.Term + ".");
for (int i = 0; i < tp1.Freq; i++)
{
Assert.AreEqual(tp1.NextPosition(), tp2.NextPosition(), "Different positions in postinglist of term " + enum1.Term + ".");
}
}
}
}
示例12: FillCache
private static void FillCache(IndexSearcherHolder.IndexSearcherHoldingState state, IEnumerable<string> fieldsToRead,IndexReader reader)
{
foreach (var field in fieldsToRead)
{
var items = new LinkedList<IndexSearcherHolder.IndexSearcherHoldingState.CacheVal>[reader.MaxDoc];
using (var termDocs = reader.TermDocs())
{
using (var termEnum = reader.Terms(new Term(field)))
{
do
{
if (termEnum.Term == null || field != termEnum.Term.Field)
break;
Term term = termEnum.Term;
if (LowPrecisionNumber(term.Field, term.Text))
continue;
var totalDocCountIncludedDeletes = termEnum.DocFreq();
termDocs.Seek(termEnum.Term);
while (termDocs.Next() && totalDocCountIncludedDeletes > 0)
{
totalDocCountIncludedDeletes -= 1;
if (reader.IsDeleted(termDocs.Doc))
continue;
if(items[termDocs.Doc] == null)
items[termDocs.Doc] = new LinkedList<IndexSearcherHolder.IndexSearcherHoldingState.CacheVal>();
items[termDocs.Doc].AddLast(new IndexSearcherHolder.IndexSearcherHoldingState.CacheVal
{
Term = termEnum.Term
});
}
} while (termEnum.Next());
}
}
state.SetInCache(field, items);
}
}
示例13: PerformDefaultTests
/// <summary> 1. Get a norm from the original reader 2. Clone the original reader 3.
/// Delete a document and set the norm of the cloned reader 4. Verify the norms
/// are not the same on each reader 5. Verify the doc deleted is only in the
/// cloned reader 6. Try to delete a document in the original reader, an
/// exception should be thrown
///
/// </summary>
/// <param name="r1">IndexReader to perform tests on
/// </param>
/// <throws> Exception </throws>
private void PerformDefaultTests(IndexReader r1)
{
float norm1 = Similarity.DecodeNorm(r1.Norms("field1")[4]);
IndexReader pr1Clone = (IndexReader) r1.Clone();
pr1Clone.DeleteDocument(10);
pr1Clone.SetNorm(4, "field1", 0.5f);
Assert.IsTrue(Similarity.DecodeNorm(r1.Norms("field1")[4]) == norm1);
Assert.IsTrue(Similarity.DecodeNorm(pr1Clone.Norms("field1")[4]) != norm1);
Assert.IsTrue(!r1.IsDeleted(10));
Assert.IsTrue(pr1Clone.IsDeleted(10));
// try to update the original reader, which should throw an exception
try
{
r1.DeleteDocument(11);
Assert.Fail("Tried to delete doc 11 and an exception should have been thrown");
}
catch (System.Exception exception)
{
// expectted
}
pr1Clone.Close();
}
示例14: FillCache
private static void FillCache(IndexSearcherHolder.IndexSearcherHoldingState state, List<string> fieldsToRead,IndexReader reader)
{
foreach (var field in fieldsToRead)
{
using (var termDocs = reader.TermDocs())
{
using (var termEnum = reader.Terms(new Term(field)))
{
do
{
if (termEnum.Term == null || field != termEnum.Term.Field)
break;
if (LowPrecisionNumber(termEnum.Term))
continue;
var totalDocCountIncludedDeletes = termEnum.DocFreq();
termDocs.Seek(termEnum.Term);
while (termDocs.Next() && totalDocCountIncludedDeletes > 0)
{
totalDocCountIncludedDeletes -= 1;
if (reader.IsDeleted(termDocs.Doc))
continue;
state.SetInCache(field, termDocs.Doc, termEnum.Term);
}
} while (termEnum.Next());
}
}
}
}