Esempio n. 1
0
        /// <summary> Tests that a query matches the an expected set of documents using a
        /// HitCollector.
        ///
        /// <p/>
        /// Note that when using the HitCollector API, documents will be collected
        /// if they "match" regardless of what their score is.
        /// <p/>
        /// </summary>
        /// <param name="query">the query to test
        /// </param>
        /// <param name="searcher">the searcher to test the query against
        /// </param>
        /// <param name="defaultFieldName">used for displaying the query in assertion messages
        /// </param>
        /// <param name="results">a list of documentIds that must match the query
        /// </param>
        /// <seealso cref="Searcher.Search(Query,HitCollector)">
        /// </seealso>
        /// <seealso cref="checkHits">
        /// </seealso>
        public static void  CheckHitCollector(Query query, System.String defaultFieldName, Searcher searcher, int[] results)
        {
            QueryUtils.Check(query, searcher);

            System.Collections.Hashtable correct = new System.Collections.Hashtable();
            for (int i = 0; i < results.Length; i++)
            {
                CollectionsHelper.AddIfNotContains(correct, (System.Int32)results[i]);
            }
            System.Collections.Hashtable actual = new System.Collections.Hashtable();
            Collector c = new SetCollector(actual);

            searcher.Search(query, c, null);
            Assert.AreEqual(correct, actual, "Simple: " + query.ToString(defaultFieldName));

            for (int i = -1; i < 2; i++)
            {
                actual.Clear();
                QueryUtils.WrapSearcher(searcher, i).Search(query, c, null);
                Assert.AreEqual(correct, actual, "Wrap Searcher " + i + ": " + query.ToString(defaultFieldName));
            }

            if (!(searcher is IndexSearcher))
            {
                return;
            }

            for (int i = -1; i < 2; i++)
            {
                actual.Clear();
                QueryUtils.WrapUnderlyingReader((IndexSearcher)searcher, i).Search(query, c, null);
                Assert.AreEqual(correct, actual, "Wrap Reader " + i + ": " + query.ToString(defaultFieldName));
            }
        }
Esempio n. 2
0
        /// <summary> Tests that a query matches the an expected set of documents using Hits.
        ///
        /// <p/>
        /// Note that when using the Hits API, documents will only be returned
        /// if they have a positive normalized score.
        /// <p/>
        /// </summary>
        /// <param name="query">the query to test
        /// </param>
        /// <param name="searcher">the searcher to test the query against
        /// </param>
        /// <param name="defaultFieldName">used for displaing the query in assertion messages
        /// </param>
        /// <param name="results">a list of documentIds that must match the query
        /// </param>
        /// <seealso cref="Searcher.Search(Query)">
        /// </seealso>
        /// <seealso cref="checkHitCollector">
        /// </seealso>
        public static void  CheckHits_Renamed_Method(Query query, System.String defaultFieldName, Searcher searcher, int[] results)
        {
            if (searcher is IndexSearcher)
            {
                QueryUtils.Check(query, searcher);
            }

            ScoreDoc[] hits = searcher.Search(query, null, 1000, null).ScoreDocs;

            System.Collections.ArrayList correct = new System.Collections.ArrayList();
            for (int i = 0; i < results.Length; i++)
            {
                CollectionsHelper.AddIfNotContains(correct, results[i]);
            }
            correct.Sort();

            System.Collections.ArrayList actual = new System.Collections.ArrayList();
            for (int i = 0; i < hits.Length; i++)
            {
                CollectionsHelper.AddIfNotContains(actual, hits[i].Doc);
            }
            actual.Sort();

            Assert.AreEqual(correct, actual, query.ToString(defaultFieldName));

            QueryUtils.Check(query, searcher);
        }
 private static System.Collections.Hashtable DifFiles(System.String[] files1, System.String[] files2)
 {
     System.Collections.Hashtable set1  = new System.Collections.Hashtable();
     System.Collections.Hashtable set2  = new System.Collections.Hashtable();
     System.Collections.Hashtable extra = new System.Collections.Hashtable();
     for (int x = 0; x < files1.Length; x++)
     {
         CollectionsHelper.AddIfNotContains(set1, files1[x]);
     }
     for (int x = 0; x < files2.Length; x++)
     {
         CollectionsHelper.AddIfNotContains(set2, files2[x]);
     }
     System.Collections.IEnumerator i1 = set1.GetEnumerator();
     while (i1.MoveNext())
     {
         System.Object o = i1.Current;
         if (!set2.Contains(o))
         {
             CollectionsHelper.AddIfNotContains(extra, o);
         }
     }
     System.Collections.IEnumerator i2 = set2.GetEnumerator();
     while (i2.MoveNext())
     {
         System.Object o = i2.Current;
         if (!set1.Contains(o))
         {
             CollectionsHelper.AddIfNotContains(extra, o);
         }
     }
     return(extra);
 }
Esempio n. 4
0
 public PayloadFilter(TestPayloadSpans enclosingInstance, TokenStream input, System.String fieldName) : base(input)
 {
     InitBlock(enclosingInstance);
     this.fieldName = fieldName;
     pos            = 0;
     CollectionsHelper.AddIfNotContains(entities, "xx");
     CollectionsHelper.AddIfNotContains(entities, "one");
     CollectionsHelper.AddIfNotContains(nopayload, "nopayload");
     CollectionsHelper.AddIfNotContains(nopayload, "np");
     termAtt    = AddAttribute <ITermAttribute>();
     posIncrAtt = AddAttribute <IPositionIncrementAttribute>();
     payloadAtt = AddAttribute <IPayloadAttribute>();
 }
Esempio n. 5
0
        public virtual void TestShrinkToAfterShortestMatch3()
        {
            RAMDirectory directory = new RAMDirectory();
            IndexWriter  writer    = new IndexWriter(directory, new TestPayloadAnalyzer(this), IndexWriter.MaxFieldLength.LIMITED);
            Document     doc       = new Document();

            doc.Add(new Field("content", new System.IO.StreamReader(new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes("j k a l f k k p a t a k l k t a")))));
            writer.AddDocument(doc);
            writer.Close();

            IndexSearcher is_Renamed = new IndexSearcher(directory, true);

            SpanTermQuery stq1 = new SpanTermQuery(new Term("content", "a"));
            SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));

            SpanQuery[]   sqs   = new SpanQuery[] { stq1, stq2 };
            SpanNearQuery snq   = new SpanNearQuery(sqs, 0, true);
            Spans         spans = snq.GetSpans(is_Renamed.IndexReader);

            TopDocs topDocs = is_Renamed.Search(snq, 1);

            System.Collections.Hashtable payloadSet = new System.Collections.Hashtable();
            for (int i = 0; i < topDocs.ScoreDocs.Length; i++)
            {
                while (spans.Next())
                {
                    System.Collections.Generic.ICollection <byte[]> payloads = spans.GetPayload();

                    for (System.Collections.IEnumerator it = payloads.GetEnumerator(); it.MoveNext();)
                    {
                        CollectionsHelper.AddIfNotContains(payloadSet, new System.String(System.Text.UTF8Encoding.UTF8.GetChars((byte[])it.Current)));
                    }
                }
            }
            Assert.AreEqual(2, payloadSet.Count);
            if (DEBUG)
            {
                System.Collections.IEnumerator pit = payloadSet.GetEnumerator();
                while (pit.MoveNext())
                {
                    System.Console.Out.WriteLine("match:" + pit.Current);
                }
            }
            Assert.IsTrue(payloadSet.Contains("a:Noise:10"));
            Assert.IsTrue(payloadSet.Contains("k:Noise:11"));
        }
Esempio n. 6
0
        public static float EXPLAIN_SCORE_TOLERANCE_DELTA = 0.00025f;           // {{See: LUCENENET-288}} Intentional diversion from Java Lucene per above comment

        /// <summary> Tests that all documents up to maxDoc which are *not* in the
        /// expected result set, have an explanation which indicates no match
        /// (ie: Explanation value of 0.0f)
        /// </summary>
        public static void  CheckNoMatchExplanations(Query q, System.String defaultFieldName, Searcher searcher, int[] results)
        {
            System.String d = q.ToString(defaultFieldName);
            System.Collections.Hashtable ignore = new System.Collections.Hashtable();
            for (int i = 0; i < results.Length; i++)
            {
                CollectionsHelper.AddIfNotContains(ignore, (System.Int32)results[i]);
            }

            int maxDoc = searcher.MaxDoc;

            for (int doc = 0; doc < maxDoc; doc++)
            {
                if (ignore.Contains((System.Int32)doc))
                {
                    continue;
                }

                Explanation exp = searcher.Explain(q, doc, null);
                Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
                Assert.AreEqual(0.0f, exp.Value, 0.0f, "Explanation of [[" + d + "]] for #" + doc + " doesn't indicate non-match: " + exp.ToString());
            }
        }
Esempio n. 7
0
 public override void  Collect(int doc, IState state)
 {
     CollectionsHelper.AddIfNotContains(bag, (System.Int32)(doc + base_Renamed));
 }