예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="docId"></param>
        /// <param name="rng"></param>
        /// <param name="ctx"></param>
        /// <param name="percentageWithSpatialFields">ensures that some documents are missing spatial fields. This forces the cache to use FixedBitSet rather than MatchAllBits or MatchNoBits</param>
        /// <returns></returns>
        private Document CreateRandomDoc(int docId, Random rng, SpatialContext ctx, double percentageWithSpatialFields)
        {
            var doc = new Document();

            var idField = new NumericField("locationId", Field.Store.YES, true);

            idField.SetIntValue(docId);

            doc.Add(idField);

            if (rng.NextDouble() > percentageWithSpatialFields)
            {
                return(doc);
            }

            Point shape = ctx.MakePoint(DistanceUtils.NormLonDEG(rng.NextDouble() * 360.0), DistanceUtils.NormLatDEG(rng.NextDouble() * 180.0));

            foreach (AbstractField field in _spatialStrategy.CreateIndexableFields(shape))
            {
                doc.Add(field);
            }

            doc.Add(_spatialStrategy.CreateStoredField(shape));

            return(doc);
        }