public virtual void  TestDocument()
        {
            Assert.IsTrue(_reader.NumDocs() == 1);
            Assert.IsTrue(_reader.MaxDoc >= 1);
            Document result = _reader.Document(0);

            Assert.IsTrue(result != null);
            //There are 2 unstored fields on the document that are not preserved across writing
            Assert.IsTrue(DocHelper.NumFields(result) == DocHelper.NumFields(_testDoc) - DocHelper.Unstored.Count);

            var fields = result.GetFields();

            foreach (var field in fields)
            {
                Assert.IsTrue(field != null);
                Assert.IsTrue(DocHelper.NameValues.Contains(field.Name));
            }
        }
Beispiel #2
0
        /// <summary> Test stored fields for a segment.</summary>
        private Status.StoredFieldStatus TestStoredFields(SegmentInfo info, SegmentReader reader, System.Globalization.NumberFormatInfo format)
        {
            var status = new Status.StoredFieldStatus();

            try
            {
                if (infoStream != null)
                {
                    infoStream.Write("    test: stored fields.......");
                }

                // Scan stored fields for all documents
                for (int j = 0; j < info.docCount; ++j)
                {
                    if (!reader.IsDeleted(j))
                    {
                        status.docCount++;
                        Document.Document doc = reader.Document(j);
                        status.totFields += doc.GetFields().Count;
                    }
                }

                // Validate docCount
                if (status.docCount != reader.NumDocs())
                {
                    throw new System.SystemException("docCount=" + status.docCount + " but saw " + status.docCount + " undeleted docs");
                }

                Msg(string.Format(format, "OK [{0:d} total field count; avg {1:f} fields per doc]", new object[] { status.totFields, (((float)status.totFields) / status.docCount) }));
            }
            catch (System.Exception e)
            {
                Msg("ERROR [" + System.Convert.ToString(e.Message) + "]");
                status.error = e;
                if (infoStream != null)
                {
                    infoStream.WriteLine(e.StackTrace);
                }
            }

            return(status);
        }
        static void UpdateMatchingDocs(IDictionary <string, MatchingDocsEntry> matchingDocsLookup, SegmentReader reader, IDictionary <string, ISet <string> > frameworkCompatibility)
        {
            for (int doc = 0; doc < reader.MaxDoc; doc++)
            {
                if (reader.IsDeleted(doc))
                {
                    continue;
                }

                Document document = reader.Document(doc);

                string id = PackageVersions.GetId(document);

                if (id == null)
                {
                    continue;
                }

                NuGetVersion version = PackageVersions.GetVersion(document);

                if (version == null)
                {
                    continue;
                }

                Field[] frameworks = document.GetFields("TargetFramework");

                foreach (KeyValuePair <string, ISet <string> > frameworkKV in frameworkCompatibility)
                {
                    bool isCompatible = false;

                    if (frameworkKV.Key == "any")
                    {
                        isCompatible = true;
                    }
                    else
                    {
                        foreach (Field frameworkField in frameworks)
                        {
                            string framework = frameworkField.StringValue;
                            if (framework == "any" || framework == "agnostic" || frameworkKV.Value.Contains(framework))
                            {
                                isCompatible = true;
                            }
                        }
                    }

                    MatchingDocsEntry entry = matchingDocsLookup[frameworkKV.Key];

                    if (isCompatible)
                    {
                        if (!version.IsPrerelease)
                        {
                            if (!entry.MatchingDocs.ContainsKey(id) || entry.MatchingDocs[id].Version < version)
                            {
                                entry.MatchingDocs[id] = new MatchingDoc {
                                    Version = version, SegmentName = reader.SegmentName, Doc = doc
                                };
                            }
                        }

                        if (!entry.MatchingDocsPre.ContainsKey(id) || entry.MatchingDocsPre[id].Version < version)
                        {
                            entry.MatchingDocsPre[id] = new MatchingDoc {
                                Version = version, SegmentName = reader.SegmentName, Doc = doc
                            };
                        }
                    }
                }
            }
        }
Beispiel #4
0
		/// <summary> Test stored fields for a segment.</summary>
		private Status.StoredFieldStatus TestStoredFields(SegmentInfo info, SegmentReader reader, System.Globalization.NumberFormatInfo format)
		{
			var status = new Status.StoredFieldStatus();
			
			try
			{
				if (infoStream != null)
				{
					infoStream.Write("    test: stored fields.......");
				}
				
				// Scan stored fields for all documents
				for (int j = 0; j < info.docCount; ++j)
				{
					if (!reader.IsDeleted(j))
					{
						status.docCount++;
						Document.Document doc = reader.Document(j);
						status.totFields += doc.GetFields().Count;
					}
				}
				
				// Validate docCount
				if (status.docCount != reader.NumDocs())
				{
					throw new System.SystemException("docCount=" + status.docCount + " but saw " + status.docCount + " undeleted docs");
				}
				
                Msg(string.Format(format, "OK [{0:d} total field count; avg {1:f} fields per doc]", new object[] { status.totFields, (((float) status.totFields) / status.docCount) }));
            }
			catch (System.Exception e)
			{
				Msg("ERROR [" + System.Convert.ToString(e.Message) + "]");
				status.error = e;
				if (infoStream != null)
				{
					infoStream.WriteLine(e.StackTrace);
				}
			}
			
			return status;
		}