Example #1
0
 private void RemoveLettercheckBox_CheckedChanged(object sender, EventArgs e) //To add or remove the filter from the array
 {
     if (RemoveLettercheckBox.Checked == true)
     {
         RandomFilter Randfilt = new RandomFilter();
         filters[0] = Randfilt;
     }
     else
     {
         for (int i = 0; i < filters.Count(); i++)
         {
             filters[0] = null;
         }
     }
 }
Example #2
0
        public virtual void TestRandomStringSort()
        {
            Random random = new Random(Random().Next());

            int               NUM_DOCS  = AtLeast(100);
            Directory         dir       = NewDirectory();
            RandomIndexWriter writer    = new RandomIndexWriter(random, dir, Similarity, TimeZone);
            bool              allowDups = random.NextBoolean();
            HashSet <string>  seen      = new HashSet <string>();
            int               maxLength = TestUtil.NextInt(random, 5, 100);

            if (VERBOSE)
            {
                Console.WriteLine("TEST: NUM_DOCS=" + NUM_DOCS + " maxLength=" + maxLength + " allowDups=" + allowDups);
            }

            int numDocs = 0;
            IList <BytesRef> docValues = new List <BytesRef>();

            // TODO: deletions
            while (numDocs < NUM_DOCS)
            {
                Document doc = new Document();

                // 10% of the time, the document is missing the value:
                BytesRef br;
                if (Random().Next(10) != 7)
                {
                    string s;
                    if (random.NextBoolean())
                    {
                        s = TestUtil.RandomSimpleString(random, maxLength);
                    }
                    else
                    {
                        s = TestUtil.RandomUnicodeString(random, maxLength);
                    }

                    if (!allowDups)
                    {
                        if (seen.Contains(s))
                        {
                            continue;
                        }
                        seen.Add(s);
                    }

                    if (VERBOSE)
                    {
                        Console.WriteLine("  " + numDocs + ": s=" + s);
                    }

                    br = new BytesRef(s);
                    if (DefaultCodecSupportsDocValues())
                    {
                        doc.Add(new SortedDocValuesField("stringdv", br));
                        doc.Add(new NumericDocValuesField("id", numDocs));
                    }
                    else
                    {
                        doc.Add(NewStringField("id", Convert.ToString(numDocs), Field.Store.NO));
                    }
                    doc.Add(NewStringField("string", s, Field.Store.NO));
                    docValues.Add(br);
                }
                else
                {
                    br = null;
                    if (VERBOSE)
                    {
                        Console.WriteLine("  " + numDocs + ": <missing>");
                    }
                    docValues.Add(null);
                    if (DefaultCodecSupportsDocValues())
                    {
                        doc.Add(new NumericDocValuesField("id", numDocs));
                    }
                    else
                    {
                        doc.Add(NewStringField("id", Convert.ToString(numDocs), Field.Store.NO));
                    }
                }

                doc.Add(new StoredField("id", numDocs));
                writer.AddDocument(doc);
                numDocs++;

                if (random.Next(40) == 17)
                {
                    // force flush
                    writer.Reader.Dispose();
                }
            }

            IndexReader r = writer.Reader;

            writer.Dispose();
            if (VERBOSE)
            {
                Console.WriteLine("  reader=" + r);
            }

            IndexSearcher idxS  = NewSearcher(r, false, Similarity);
            int           ITERS = AtLeast(100);

            for (int iter = 0; iter < ITERS; iter++)
            {
                bool reverse = random.NextBoolean();

                TopFieldDocs hits;
                SortField    sf;
                bool         sortMissingLast;
                bool         missingIsNull;
                if (DefaultCodecSupportsDocValues() && random.NextBoolean())
                {
                    sf = new SortField("stringdv", SortField.Type_e.STRING, reverse);
                    // Can only use sort missing if the DVFormat
                    // supports docsWithField:
                    sortMissingLast = DefaultCodecSupportsDocsWithField() && Random().NextBoolean();
                    missingIsNull   = DefaultCodecSupportsDocsWithField();
                }
                else
                {
                    sf = new SortField("string", SortField.Type_e.STRING, reverse);
                    sortMissingLast = Random().NextBoolean();
                    missingIsNull   = true;
                }
                if (sortMissingLast)
                {
                    sf.MissingValue = SortField.STRING_LAST;
                }

                Sort sort;
                if (random.NextBoolean())
                {
                    sort = new Sort(sf);
                }
                else
                {
                    sort = new Sort(sf, SortField.FIELD_DOC);
                }
                int          hitCount  = TestUtil.NextInt(random, 1, r.MaxDoc + 20);
                RandomFilter f         = new RandomFilter(random, (float)random.NextDouble(), docValues);
                int          queryType = random.Next(3);
                if (queryType == 0)
                {
                    // force out of order
                    BooleanQuery bq = new BooleanQuery();
                    // Add a Query with SHOULD, since bw.Scorer() returns BooleanScorer2
                    // which delegates to BS if there are no mandatory clauses.
                    bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
                    // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
                    // the clause instead of BQ.
                    bq.MinimumNumberShouldMatch = 1;
                    hits = idxS.Search(bq, f, hitCount, sort, random.NextBoolean(), random.NextBoolean());
                }
                else if (queryType == 1)
                {
                    hits = idxS.Search(new ConstantScoreQuery(f), null, hitCount, sort, random.NextBoolean(), random.NextBoolean());
                }
                else
                {
                    hits = idxS.Search(new MatchAllDocsQuery(), f, hitCount, sort, random.NextBoolean(), random.NextBoolean());
                }

                if (VERBOSE)
                {
                    Console.WriteLine("\nTEST: iter=" + iter + " " + hits.TotalHits + " hits; topN=" + hitCount + "; reverse=" + reverse + "; sortMissingLast=" + sortMissingLast + " sort=" + sort);
                }

                // Compute expected results:
                var expected = f.MatchValues.ToList();
                expected.Sort(new ComparatorAnonymousInnerClassHelper(this, sortMissingLast));
                if (reverse)
                {
                    expected.Reverse();
                }

                if (VERBOSE)
                {
                    Console.WriteLine("  expected:");
                    for (int idx = 0; idx < expected.Count; idx++)
                    {
                        BytesRef br = expected[idx];
                        if (br == null && missingIsNull == false)
                        {
                            br = new BytesRef();
                        }
                        Console.WriteLine("    " + idx + ": " + (br == null ? "<missing>" : br.Utf8ToString()));
                        if (idx == hitCount - 1)
                        {
                            break;
                        }
                    }
                }

                if (VERBOSE)
                {
                    Console.WriteLine("  actual:");
                    for (int hitIDX = 0; hitIDX < hits.ScoreDocs.Length; hitIDX++)
                    {
                        FieldDoc fd = (FieldDoc)hits.ScoreDocs[hitIDX];
                        BytesRef br = (BytesRef)fd.Fields[0];

                        Console.WriteLine("    " + hitIDX + ": " + (br == null ? "<missing>" : br.Utf8ToString()) + " id=" + idxS.Doc(fd.Doc).Get("id"));
                    }
                }
                for (int hitIDX = 0; hitIDX < hits.ScoreDocs.Length; hitIDX++)
                {
                    FieldDoc fd = (FieldDoc)hits.ScoreDocs[hitIDX];
                    BytesRef br = expected[hitIDX];
                    if (br == null && missingIsNull == false)
                    {
                        br = new BytesRef();
                    }

                    // Normally, the old codecs (that don't support
                    // docsWithField via doc values) will always return
                    // an empty BytesRef for the missing case; however,
                    // if all docs in a given segment were missing, in
                    // that case it will return null!  So we must map
                    // null here, too:
                    BytesRef br2 = (BytesRef)fd.Fields[0];
                    if (br2 == null && missingIsNull == false)
                    {
                        br2 = new BytesRef();
                    }

                    Assert.AreEqual(br, br2, "hit=" + hitIDX + " has wrong sort value");
                }
            }

            r.Dispose();
            dir.Dispose();
        }
Example #3
0
 /// <summary>
 /// Construct a new <see cref="FilteredRandomBool"/>.
 /// </summary>
 /// <param name="generator">The generator used to generate random values. If left null, <see cref="RandomGenerator.Instance"/> will be used.</param>
 /// <param name="filter">The filter that is applied on generated values. If left null, <see cref="DefaultPatterns.All"/> will be used.</param>
 public FilteredRandomBool(IRandomGenerator generator = null, RandomFilter <bool> filter = null)
     : base(generator, filter)
 {
     Generator = new BoolGenerator(this.RNG);
 }
 /// <inheritdoc />
 public override void InitializeGenerator(RandomFilter <float> filter = null)
 {
     _filteredGuassian = new FilteredGuassian(_mean, _standardDeviation, filter: filter);
 }
        /// <summary>
        /// Constructs a new Filtered random float generator.
        /// </summary>
        /// <param name="rangeMin">The underbound of the range of possible values.</param>
        /// <param name="rangeMax">The upper bound of the range of possible values.</param>
        /// <param name="generator">The generator used to generate random values. If left null, <see cref="RandomGenerator.Instance"/> will be used.</param>
        /// <param name="filter">The filter that is applied on generated values. If left null, <see cref="DefaultPatterns.All"/> will be used.</param>
        public FilteredRandomFloat(float rangeMin, float rangeMax, IRandomGenerator generator = null, RandomFilter <float> filter = null)
            : base(generator, filter)
        {
            //Set the range.
            RangeMin = rangeMin;
            RangeMax = rangeMax;

            //Initialize the generator.
            Generator = new FloatGenerator(this.RNG, rangeMin, rangeMax);
            SetRange(rangeMin, rangeMax);
        }
Example #6
0
 /// <inheritdoc />
 public override void InitializeGenerator(RandomFilter <bool> filter = null)
 {
     _filteredRandomBool = new FilteredRandomBool(filter: filter);
 }
 /// <inheritdoc />
 public override void InitializeGenerator(RandomFilter <int> filter = null)
 {
     _filteredRandomInt = new FilteredRandomInt(_rangeMin, _rangeMax, filter: filter);
 }
Example #8
0
        /// <summary>
        /// Constructs a new Filtered random int generator.
        /// </summary>
        /// <param name="rangeMin">The underbound of the range of possible values.</param>
        /// <param name="rangeMax">The upper bound of the range of possible values.</param>
        /// <param name="generator">The generator used to generate random values. If left null, <see cref="RandomGenerator.Instance"/> will be used.</param>
        /// <param name="filter">The filter that is applied on generated values. If left null, <see cref="DefaultPatterns.All"/> will be used.</param>
        public FilteredRandomInt(int rangeMin, int rangeMax, IRandomGenerator generator = null, RandomFilter <int> filter = null)
            : base(generator, filter)
        {
            RangeMin = rangeMin;
            RangeMax = rangeMax;

            Generator = new IntGenerator(this.RNG, rangeMin, rangeMax);
            SetRange(rangeMin, rangeMax);
        }