Пример #1
0
        private void GetAllIdValuesFromIndex(out int[] nodeIds, out int[] versionIds)
        {
            var nodeIdList     = new List <int>();
            var versionIdLists = new List <int>();

            using (var rf = Lucene29LocalIndexingEngine.GetReaderFrame())
            {
                var reader = rf.IndexReader;
                for (var d = 0; d < reader.NumDocs(); d++)
                {
                    var doc = reader.Document(d);

                    var nodeIdString = doc.Get(IndexFieldName.NodeId);
                    if (!string.IsNullOrEmpty(nodeIdString))
                    {
                        nodeIdList.Add(int.Parse(nodeIdString));
                    }

                    var versionIdString = doc.Get(IndexFieldName.VersionId);
                    if (!string.IsNullOrEmpty(versionIdString))
                    {
                        versionIdLists.Add(int.Parse(versionIdString));
                    }
                }
            }
            nodeIds    = nodeIdList.ToArray();
            versionIds = versionIdLists.ToArray();
        }
Пример #2
0
        /* ======================================================================================= */

        protected async Task L29Test(Action <RepositoryBuilder> initialize, Func <Task> callback, bool saveInitialDocuments = true, [CallerMemberName] string memberName = "")
        {
            var indexFolderName = $"Test_{memberName}_{Guid.NewGuid()}";
            var indexingEngine  = new Lucene29LocalIndexingEngine(new IndexDirectory(indexFolderName));
            var searchEngine    = new Lucene29SearchEngine(indexingEngine, new Lucene29LocalQueryEngine());

            await base.Test(builder =>
            {
                // important: use a real local search engine instead of in-memory search
                builder.UseSearchEngine(searchEngine);

                initialize?.Invoke(builder);
            },
                            async() =>
            {
                if (saveInitialDocuments)
                {
                    using (new SystemAccount())
                    {
                        await SaveInitialIndexDocumentsAsync(CancellationToken.None);
                    }
                }

                await callback();
            });
        }
Пример #3
0
        public override ISearchEngine GetSearchEngine()
        {
            //TODO:<?IntT: Customize indexDirectoryPath if there is more than one platform that uses a local lucene index.
            var indexingEngine = new Lucene29LocalIndexingEngine(null);
            var x = indexingEngine.LuceneSearchManager.IndexDirectory.CurrentDirectory;

            return(new Lucene29SearchEngine(indexingEngine, new Lucene29LocalQueryEngine()));
        }
Пример #4
0
        public override ISearchEngine GetSearchEngine()
        {
            //TODO:<?IntT: Customize indexDirectoryPath if there is more than one platform that uses a local lucene index.
            var indexingEngine = new Lucene29LocalIndexingEngine(null);
            var x = indexingEngine.LuceneSearchManager.IndexDirectory.CurrentDirectory;

            //UNDONE:<?IntT: Force delete "write.lock" when getting the platform the first time.
            return(new Lucene29SearchEngine(indexingEngine, new Lucene29LocalQueryEngine()));
        }
Пример #5
0
        private async Task StartNewEngineAsync(string name, string path)
        {
            var sb             = new StringBuilder();
            var console        = new StringWriter(sb);
            var indexDirectory = new IndexDirectory(name, path);
            var engine         = new Lucene29LocalIndexingEngine(indexDirectory);

            SnTrace.Write("100 starting");
            await engine.StartAsync(console, false, CancellationToken.None).ConfigureAwait(false);

            SnTrace.Write("101 started");

            while (!File.Exists(indexDirectory.IndexLockFilePath))
            {
                Task.Delay(50).ConfigureAwait(false).GetAwaiter().GetResult();
            }
            await engine.ShutDownAsync(CancellationToken.None).ConfigureAwait(false);
        }
Пример #6
0
        static void Main(string[] args)
        {
            try
            {
                var delay = int.Parse(args[0]);
                var name  = args[1];
                var path  = args[2];

                var indexDirectory = new IndexDirectory(name, path);
                var engine         = new Lucene29LocalIndexingEngine(indexDirectory);
                engine.StartAsync(null, false, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult();
                Task.Delay(delay).ConfigureAwait(false).GetAwaiter().GetResult();
                engine.ShutDownAsync(CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press <enter> to exit...");
            Console.ReadLine();
        }
Пример #7
0
        private async Task <(string Name, string Path, string LockPath)> EnsureIndexDirectoryAsync()
        {
            var indexDirectory = new IndexDirectory("WriteLockTests", null);
            var engine         = new Lucene29LocalIndexingEngine(indexDirectory);
            await engine.StartAsync(null, false, CancellationToken.None).ConfigureAwait(false);

            while (!File.Exists(indexDirectory.IndexLockFilePath))
            {
                Task.Delay(50).ConfigureAwait(false).GetAwaiter().GetResult();
            }

            await engine.ShutDownAsync(CancellationToken.None).ConfigureAwait(false);

            while (File.Exists(indexDirectory.IndexLockFilePath))
            {
                Task.Delay(50).ConfigureAwait(false).GetAwaiter().GetResult();
            }

            var name = indexDirectory.Name;
            var path = Path.GetDirectoryName(indexDirectory.CurrentDirectory);

            return(name, path, indexDirectory.IndexLockFilePath);
        }
Пример #8
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);
            }
        }