Beispiel #1
0
        /// <summary>
        /// Find witch index will be used and run Execute method - define ExecuteMode here
        /// </summary>
        internal virtual IEnumerable <IndexNode> Run <T>(LiteCollection <T> collection)
            where T : new()
        {
            // get collection page - no collection, no results
            var col = collection.GetCollectionPage(false);

            // no collection just returns an empty list of indexnode
            if (col == null)
            {
                return(new List <IndexNode>());
            }

            // get index
            var index = col.GetIndex(this.Field);

            // if index not found, lets check if type T has [BsonIndex]
            if (index == null && typeof(T) != typeof(BsonDocument))
            {
                var options = collection.Database.Mapper.GetIndexFromAttribute <T>(this.Field);

                // create a new index using BsonIndex options
                if (options != null)
                {
                    collection.EnsureIndex(this.Field, options);

                    index = col.GetIndex(this.Field);
                }
            }

            // if no index, let's auto create an index with default index options
            if (index == null)
            {
                collection.EnsureIndex(this.Field);

                index = col.GetIndex(this.Field);
            }

            // execute query to get all IndexNodes
            return(this.ExecuteIndex(collection.Database.Indexer, index));
        }
Beispiel #2
0
        /// <summary>
        /// Find witch index will be used and run Execute method - define ExecuteMode here
        /// </summary>
        internal virtual IEnumerable <IndexNode> Run <T>(LiteCollection <T> collection)
            where T : new()
        {
            // get collection page - no collection, no results
            var col = collection.GetCollectionPage(false);

            // no collection just returns an empty list of indexnode
            if (col == null)
            {
                return(new List <IndexNode>());
            }

            // get index
            var index = col.GetIndex(this.Field);

            // if index not found, lets check if type T has [BsonIndex]
            if (index == null && typeof(T) != typeof(BsonDocument))
            {
                var options = collection.Database.Mapper.GetIndexFromAttribute <T>(this.Field);

                // create a new index
                if (options != null)
                {
                    collection.EnsureIndex(this.Field, options);

                    index = col.GetIndex(this.Field);
                }
            }

            if (index == null)
            {
                this.ExecuteMode = QueryExecuteMode.FullScan;

                // normalize query values before run full scan
                this.NormalizeValues(new IndexOptions());

                // if there is no index, returns all index nodes - will be used Full Scan
                return(collection.Database.Indexer.FindAll(col.PK, Query.Ascending));
            }
            else
            {
                this.ExecuteMode = QueryExecuteMode.IndexSeek;

                // execute query to get all IndexNodes
                return(this.ExecuteIndex(collection.Database.Indexer, index));
            }
        }