コード例 #1
0
        public void SearchFactory_CreatesCorrectAlgorithm_GivenDifferentCasesOfAlgorithm(string url, Type expectedType)
        {
            var algorithm = SearchFactory.GetSearchAlgorithm(url);

            Assert.IsTrue(algorithm.GetType() == expectedType);
        }
コード例 #2
0
        public void NotEqualityTest()
        {
            IList <SearchElement <string> > list = new List <SearchElement <string> >();

            list.Add(new SearchElement <string> {
                Obj = "1", Oprs = OperatorType.NotEquals
            });

            var search = new DoStrategyQuery <String>(list, _searchlist.AsQueryable(), SearchFactory.GetInstanceOfSearchFactoru());

            Assert.AreEqual(3, search.ExecuteSearch().Count());
        }
コード例 #3
0
        public void SearchFactory_When_Called_With_Bing_Should_Return_BingObject()
        {
            ISearch search = new SearchFactory().GetSearchProvider(SearchEnum.Bing);

            Assert.IsTrue(search is BingSearch);
        }
コード例 #4
0
        public void SearchFactory_CreatesExpectedType_GivenKnownAndUnknownUrls(string url, Type expectedType)
        {
            var algorithm = SearchFactory.GetSearchAlgorithm(url);

            Assert.IsTrue(algorithm.GetType() == expectedType);
        }
コード例 #5
0
        public void SearchFactory_When_Called_With_Google_Should_Return_GoogleSearchObject()
        {
            ISearch search = new SearchFactory().GetSearchProvider(SearchEnum.Google);

            Assert.IsTrue(search is GoogleSearch);
        }
コード例 #6
0
 /// <summary>
 /// Create a search to locate an entity by name
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 protected Search NameSearch(string name)
 {
     return(SearchFactory.SimpleSearch("Name", SearchCondition.Equals, name));
 }
コード例 #7
0
        private Search GetSearch(Table table, FilterRequest request)
        {
            ISearchFactory SearchFactory = new SearchFactory(table, request);

            return(SearchFactory.CreateSearch());
        }
コード例 #8
0
ファイル: RequestQueueHandler.cs プロジェクト: hwebz/NTCWeb
 internal static void Enqueue(IndexRequestItem request, string namedIndexingService)
 {
     SearchFactory.AddToQueue(request, namedIndexingService);
 }
コード例 #9
0
        public Results Get(string algorithm, long size, int blockSize, int parallelism, string id)
        {
            var bufferSize = blockSize * 1000000;
            var totalSize  = size * 1000000;
            var partitions = (totalSize / bufferSize);
            var pattern    = Encoding.ASCII.GetBytes(id.ToString());
            var timer      = new Stopwatch();
            var results    = new Results()
            {
                Pattern = id.ToString()
            };
            var parts        = new List <long>();
            var patternFound = false;

            for (long i = 0; i < partitions; i++)
            {
                parts.Add(Convert.ToInt64(i * bufferSize));
            }

            timer.Start();

            Parallel.ForEach(parts, new ParallelOptions {
                MaxDegreeOfParallelism = parallelism
            }, (x) =>
            {
                using (var stream = new FileStream(HostingEnvironment.MapPath($@"~/App_Data/pi-billion.txt"), FileMode.Open, FileAccess.Read))
                {
                    var result = new Result {
                        TaskId = Task.CurrentId, FromByte = x, ToByte = x + bufferSize
                    };

                    if (!patternFound)
                    {
                        stream.Seek(x, SeekOrigin.Begin);
                        var buffer    = new byte[bufferSize];
                        var bytesRead = stream.Read(buffer, 0, bufferSize);

                        if (bytesRead > 0)
                        {
                            ISearch searcher = SearchFactory.Get(algorithm);
                            searcher.SetPattern(pattern);
                            var position = searcher.Search(buffer);

                            if (position > -1)
                            {
                                patternFound    = true;
                                result.Position = x + position;
                                var digits      = buffer.Skip((position - MyConfig.DigitCount).Min0()).Take(pattern.Length + MyConfig.DigitCount * 2).ToList();
                                result.Digits   = Encoding.ASCII.GetString(digits.ToArray());
                            }
                        }

                        result.ExecutionTime = timer.Elapsed.TotalSeconds;

                        lock (results)
                        {
                            results.Length += bytesRead;
                            results.Tasks.Add(result);
                        }
                    }
                }
            });

            timer.Stop();
            results.ExecutionTime = Math.Round(timer.Elapsed.TotalSeconds, 3);
            return(results);
        }