Ejemplo n.º 1
0
        public Query Test(string queryText, string expected = null)
        {
            expected = expected ?? queryText;

            var indexingInfo = new Dictionary <string, IPerFieldIndexingInfo>
            {
                //{"_Text", new TestPerfieldIndexingInfoString()},
                { "#Field1", new TestPerfieldIndexingInfoString() },
                { "Field1", new TestPerfieldIndexingInfoString() },
                { "Field2", new TestPerfieldIndexingInfoString() },
                { "Field3", new TestPerfieldIndexingInfoString() },
                { "F1", new TestPerfieldIndexingInfoString() },
                { "F2", new TestPerfieldIndexingInfoString() },
                { "F3", new TestPerfieldIndexingInfoString() },
                { "F4", new TestPerfieldIndexingInfoString() },
                { "f1", new TestPerfieldIndexingInfoString() },
                { "f2", new TestPerfieldIndexingInfoString() },
                { "f3", new TestPerfieldIndexingInfoString() },
                { "f4", new TestPerfieldIndexingInfoString() },
                { "f5", new TestPerfieldIndexingInfoString() },
                { "f6", new TestPerfieldIndexingInfoString() },
                { "mod_date", new TestPerfieldIndexingInfoInt() },
                { "title", new TestPerfieldIndexingInfoString() },
                { "Name", new TestPerfieldIndexingInfoString() },
                { "Id", new TestPerfieldIndexingInfoInt() },
                { "LongField1", new TestPerfieldIndexingInfoLong() },
                { "SingleField1", new TestPerfieldIndexingInfoSingle() },
                { "DoubleField1", new TestPerfieldIndexingInfoDouble() },
                { "DateTimeField1", new TestPerfieldIndexingInfoDateTime() },
            };

            //using (new ContentRepository.Tests.Tools.RepositorySupportSwindler(new TestSearchEngineSupport(indexingInfo)))
            using (SenseNet.Tests.Tools.Swindle(typeof(SearchManager), "_searchEngineSupport", new TestSearchEngineSupport(indexingInfo)))
            {
                var queryContext = new TestQueryContext(QuerySettings.Default, 0, indexingInfo);
                var parser       = new CqlParser();
                var snQuery      = parser.Parse(queryText, queryContext);

                var analyzers       = indexingInfo.ToDictionary(kvp => kvp.Key, kvp => Lucene29LocalIndexingEngine.GetAnalyzer(kvp.Value));
                var indexFieldTypes = indexingInfo.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.IndexFieldHandler.IndexFieldType);

                // This is a non-functional object that's only purpose is
                // to hold the indexing info for the visitor to work.
                var sm = new LuceneSearchManager(new IndexDirectory());
                sm.SetIndexingInfo(analyzers, indexFieldTypes);

                var compiler = new Lucene29Compiler(sm.GetAnalyzer());
                var lucQuery = compiler.Compile(snQuery, queryContext);

                var lqVisitor = new LucQueryToStringVisitor(sm);
                lqVisitor.Visit(lucQuery.Query);
                var actual = lqVisitor.ToString();

                Assert.AreEqual(expected, actual);

                return(lucQuery.Query);
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <LucObject> Execute()
        {
            using (var op = SnTrace.Query.StartOperation("LuceneQueryExecutor. CQL:{0}", LucQuery))
            {
                SearchResult result;

                var top = LucQuery.Top != 0 ? LucQuery.Top : LucQuery.PageSize;
                if (top == 0)
                {
                    top = int.MaxValue;
                }

                using (var readerFrame = LuceneSearchManager.GetIndexReaderFrame(LucQuery.QueryExecutionMode == QueryExecutionMode.Quick))
                {
                    var idxReader = readerFrame.IndexReader;
                    var searcher  = new IndexSearcher(idxReader);

                    var searchParams = new SearchParams
                    {
                        query    = LucQuery.Query,
                        top      = top,
                        executor = this,
                        searcher = searcher,
                        numDocs  = idxReader.NumDocs()
                    };

                    try
                    {
                        result = DoExecute(searchParams);
                    }
                    finally
                    {
                        if (searchParams.searcher != null)
                        {
                            searchParams.searcher.Close();
                            searchParams.searcher = null;
                        }
                    }
                }

                TotalCount = result.totalCount;

                op.Successful = true;
                return(result.result);
            }
        }
            /// <summary>
            /// RUNS NOT EXCLUSIVE. DO NOT CALL TWICE.
            /// </summary>
            public void Backup(IndexingActivityStatus state, string backupDirectoryPath,
                               LuceneSearchManager indexManager, CancellationToken cancellationToken)
            {
                BackupInfo.StartedAt = DateTime.UtcNow;

                BackupInfo.TotalBytes   = 3 * 42L;
                BackupInfo.CountOfFiles = 3;

                Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult();
                BackupInfo.CurrentlyCopiedFile = "File1";

                for (int i = 0; i < 3; i++)
                {
                    Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult();

                    BackupInfo.CopiedBytes += 42;
                    BackupInfo.CopiedFiles++;
                    BackupInfo.CurrentlyCopiedFile = i < 2 ? $"File{i + 2}" : null;
                }

                BackupInfo.FinishedAt = DateTime.UtcNow;
            }
            /// <summary>
            /// RUNS NOT EXCLUSIVE. DO NOT CALL TWICE.
            /// </summary>
            public void Backup(IndexingActivityStatus state, string backupDirectoryPath,
                               LuceneSearchManager indexManager, CancellationToken cancellationToken)
            {
                BackupInfo.StartedAt = DateTime.UtcNow;

                BackupInfo.TotalBytes   = 333333333L;
                BackupInfo.CountOfFiles = 33333;

                Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult();
                BackupInfo.CurrentlyCopiedFile = "File1";

                var i = 0;

                while (true)
                {
                    Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult();

                    BackupInfo.CopiedBytes += 42;
                    BackupInfo.CopiedFiles++;
                    BackupInfo.CurrentlyCopiedFile = $"File{++i + 1}";
                }
                // ReSharper disable once FunctionNeverReturns
            }
 public void Backup(IndexingActivityStatus state, string backupDirectoryPath,
                    LuceneSearchManager indexManager, CancellationToken cancellationToken)
 {
     Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).GetAwaiter().GetResult();
 }