예제 #1
0
        /// <summary>
        /// Private constructor that is used when creating the Tag Server from SCRATCH (<see cref="CreateFromScratchAndSaveToDisk"/>)
        /// </summary>
        /// <param name="questionsList"></param>
        private TagServer(List <Question> questionsList)
        {
            questions = questionsList;
            var groupedTags = CreateTagGroupings();

            allTags = groupedTags.ToDictionary(t => t.Key, t => t.Value.Count);

            // Some of these rely on allTags, so they have to be created AFTER it is
            queryProcessor        = new QueryProcessor(questions, type => GetTagLookupForQueryType(type));
            complexQueryProcessor = new ComplexQueryProcessor(questions, type => GetTagLookupForQueryType(type));
            bitMapQueryProcessor  = new BitMapQueryProcessor(questions, allTags,
                                                             type => GetTagLookupForQueryType(type),
                                                             type => GetTagBitMapIndexForQueryType(type));
            bitMapIndexHandler = new BitMapIndexHandler(questions, allTags,
                                                        type => GetTagLookupForQueryType(type),
                                                        type => GetTagBitMapIndexForQueryType(type));
            validator = new Validator(questions, allTags,
                                      type => GetTagLookupForQueryType(type),
                                      type => GetTagBitMapIndexForQueryType(type));

            // These have to be initialised in the ctor, so they can remain readonly
            tagsByAnswerCount      = new TagByQueryLookup(groupedTags.Count);
            tagsByCreationDate     = new TagByQueryLookup(groupedTags.Count);
            tagsByLastActivityDate = new TagByQueryLookup(groupedTags.Count);
            tagsByScore            = new TagByQueryLookup(groupedTags.Count);
            tagsByViewCount        = new TagByQueryLookup(groupedTags.Count);

            // These have to be initialised in the ctor, so they can remain readonly
            tagsByAnswerCountBitMapIndex      = new TagByQueryBitMapLookup(groupedTags.Count);
            tagsByCreationDateBitMapIndex     = new TagByQueryBitMapLookup(groupedTags.Count);
            tagsByLastActivityDateBitMapIndex = new TagByQueryBitMapLookup(groupedTags.Count);
            tagsByScoreBitMapIndex            = new TagByQueryBitMapLookup(groupedTags.Count);
            tagsByViewCountBitMapIndex        = new TagByQueryBitMapLookup(groupedTags.Count);

            CreateSortedLists(groupedTags, useAlternativeMethod: true);

            Logger.LogStartupMessage(new string('#', Console.WindowWidth));
            bitMapIndexHandler.CreateBitMapIndexes();
            Logger.LogStartupMessage(new string('#', Console.WindowWidth));

            validator.ValidateTagOrdering();
            validator.ValidateBitMapIndexOrdering();

            GC.Collect(2, GCCollectionMode.Forced);
            var mbUsed = GC.GetTotalMemory(true) / 1024.0 / 1024.0;

            Logger.LogStartupMessage("After TagServer created - Using {0:N2} MB ({1:N2} GB) of memory in total\n", mbUsed, mbUsed / 1024.0);
        }
예제 #2
0
        /// <summary>
        /// Private constructor that is used when creating the Tag Server from previously serialised data (<see cref="CreateFromSerialisedData"/>)
        /// </summary>
        private TagServer(List <Question> questionsList, TagLookup allTags,
                          Dictionary <QueryType, TagByQueryLookup> intermediateLookups,
                          Dictionary <QueryType, TagByQueryBitMapLookup> intermediateBitMapIndexes)
        {
            questions    = questionsList;
            this.allTags = allTags;

            // Some of these rely on allTags, so they have to be created AFTER it is
            queryProcessor        = new QueryProcessor(questions, type => GetTagLookupForQueryType(type));
            complexQueryProcessor = new ComplexQueryProcessor(questions, type => GetTagLookupForQueryType(type));
            bitMapQueryProcessor  = new BitMapQueryProcessor(questions, allTags,
                                                             type => GetTagLookupForQueryType(type),
                                                             type => GetTagBitMapIndexForQueryType(type));
            bitMapIndexHandler = new BitMapIndexHandler(questions, allTags,
                                                        type => GetTagLookupForQueryType(type),
                                                        type => GetTagBitMapIndexForQueryType(type));
            validator = new Validator(questions, allTags,
                                      type => GetTagLookupForQueryType(type),
                                      type => GetTagBitMapIndexForQueryType(type));

            // These have to be initialised in the ctor, so they can remain readonly
            tagsByAnswerCount      = intermediateLookups[QueryType.AnswerCount];
            tagsByCreationDate     = intermediateLookups[QueryType.CreationDate];
            tagsByLastActivityDate = intermediateLookups[QueryType.LastActivityDate];
            tagsByScore            = intermediateLookups[QueryType.Score];
            tagsByViewCount        = intermediateLookups[QueryType.ViewCount];

            // These have to be initialised in the ctor, so they can remain readonly
            tagsByAnswerCountBitMapIndex      = intermediateBitMapIndexes[QueryType.AnswerCount];
            tagsByCreationDateBitMapIndex     = intermediateBitMapIndexes[QueryType.CreationDate];
            tagsByLastActivityDateBitMapIndex = intermediateBitMapIndexes[QueryType.LastActivityDate];
            tagsByScoreBitMapIndex            = intermediateBitMapIndexes[QueryType.Score];
            tagsByViewCountBitMapIndex        = intermediateBitMapIndexes[QueryType.ViewCount];

            // This takes a while, maybe don't do it when using Intermediate results (that have already had this check done when they were created)
            //ValidateTagOrdering();
            //ValidateBitMapIndexOrdering();

            GC.Collect(2, GCCollectionMode.Forced);
            var mbUsed = GC.GetTotalMemory(true) / 1024.0 / 1024.0;

            Logger.LogStartupMessage("After TagServer created - Using {0:N2} MB ({1:N2} GB) of memory in total\n", mbUsed, mbUsed / 1024.0);
        }