示例#1
0
 public override void TestSetup()
 {
     _luceneDir = new RAMDirectory();
     _indexer   = IndexInitializer.GetUmbracoIndexer(_luceneDir);
     _indexer.RebuildIndex();
     _searcher = IndexInitializer.GetUmbracoSearcher(_luceneDir);
 }
示例#2
0
        public void TestSetup()
        {
            UmbracoExamineSearcher.DisableInitializationCheck = true;
            BaseUmbracoIndexer.DisableInitializationCheck     = true;
            //we'll copy over the pdf files first
            var svc  = new TestDataService();
            var path = svc.MapPath("/App_Data/Converting_file_to_PDF.pdf");
            var f    = new FileInfo(path);
            var dir  = f.Directory;

            //ensure the folder is there
            System.IO.Directory.CreateDirectory(dir.FullName);
            var pdfs  = new[] { TestFiles.Converting_file_to_PDF, TestFiles.PDFStandards, TestFiles.SurviorFlipCup, TestFiles.windows_vista };
            var names = new[] { "Converting_file_to_PDF.pdf", "PDFStandards.pdf", "SurviorFlipCup.pdf", "windows_vista.pdf" };

            for (int index = 0; index < pdfs.Length; index++)
            {
                var p = pdfs[index];
                using (var writer = File.Create(Path.Combine(dir.FullName, names[index])))
                {
                    writer.Write(p, 0, p.Length);
                }
            }

            _luceneDir = new RAMDirectory();
            _indexer   = IndexInitializer.GetPdfIndexer(_luceneDir);
            _indexer.RebuildIndex();
            _searcher = IndexInitializer.GetUmbracoSearcher(_luceneDir);
        }
示例#3
0
        /// <summary>
        /// Boot-up is completed, this allows you to perform any other boot-up logic required for the application.
        /// Resolution is frozen so now they can be used to resolve instances.
        /// </summary>
        /// <param name="umbracoApplication">
        /// The current <see cref="UmbracoApplicationBase"/>
        /// </param>
        /// <param name="applicationContext">
        /// The Umbraco <see cref="ApplicationContext"/> for the current application.
        /// </param>
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            // Try and install the package.
            if (!ZoombracoBootstrapper.Install(umbracoApplication, applicationContext))
            {
                return;
            }

            // Register custom routes.
            RouteBuilder.RegisterRoutes(RouteTable.Routes);

            // Ensure that the xml formatter does not interfere with API controllers.
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

            // Clear out any CDN url requests on new image processing.
            // This ensures that when we update an image the cached CDN result for rendering is deleted.
            ImageProcessingModule.OnPostProcessing += (s, e) => { ZoombracoApplicationCache.RemoveItem(e.Context.Request.Unvalidated.RawUrl); };

            // Assign indexer for full text searching.
            UmbracoContentIndexer  indexProvider  = ExamineManager.Instance.IndexProviderCollection[ZoombracoConstants.Search.IndexerName] as UmbracoContentIndexer;
            UmbracoExamineSearcher searchProvider = ExamineManager.Instance.SearchProviderCollection[ZoombracoConstants.Search.SearcherName] as UmbracoExamineSearcher;

            if (indexProvider == null)
            {
                throw new ArgumentOutOfRangeException($"{ZoombracoConstants.Search.IndexerName} is missing. Please check the ExamineSettings.config file.");
            }

            if (searchProvider == null)
            {
                throw new ArgumentOutOfRangeException($"{ZoombracoConstants.Search.SearcherName} is missing. Please check the ExamineSettings.config file.");
            }

            UmbracoHelper helper        = new UmbracoHelper(UmbracoContext.Current);
            ContentHelper contentHelper = new ContentHelper(helper);

            indexProvider.GatheringNodeData += (sender, e) => this.GatheringNodeData(sender, e, helper, contentHelper, applicationContext);

            // Register the VortoPropertyAttribute as the default property processor so that any property can be made multilingual.
            Ditto.RegisterDefaultProcessorType <VortoPropertyAttribute>();
        }
示例#4
0
        /// <summary>
        /// Executes the search. If the <paramref name="rootId"/> value is set the search will be executed for the site containing
        /// that content node only.
        /// </summary>
        /// <param name="rootId">The root id of the site to search within.</param>
        /// <returns>The <see cref="SearchResponse"/> containing the search results.</returns>
        public SearchResponse Execute(string rootId = "")
        {
            SearchResponse         searchResponse = new SearchResponse();
            UmbracoExamineSearcher searchProvider = (UmbracoExamineSearcher)ExamineManager.Instance.SearchProviderCollection[ZoombracoConstants.Search.SearcherName];
            Analyzer analyzer = searchProvider.IndexingAnalyzer;

            // Wildcards are only supported using the languages using the standard analyzer.
            this.UseWildcards = this.UseWildcards && typeof(StandardAnalyzer) == analyzer.GetType();

            IBooleanOperation searchCriteria = searchProvider.CreateSearchCriteria().OrderBy(string.Empty);

            if (!string.IsNullOrWhiteSpace(this.Query))
            {
                string[] mergedFields = new string[this.Cultures.Length];
                for (int i = 0; i < this.Cultures.Length; i++)
                {
                    mergedFields[i] = string.Format(ZoombracoConstants.Search.MergedDataFieldTemplate, this.Cultures[i].Name);
                }

                if (this.UseWildcards)
                {
                    searchCriteria = searchProvider
                                     .CreateSearchCriteria()
                                     .GroupedOr(
                        mergedFields,
                        this.Query.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(w => w.Trim().MultipleCharacterWildcard())
                        .ToArray());
                }
                else
                {
                    searchCriteria = searchProvider
                                     .CreateSearchCriteria()
                                     .GroupedAnd(mergedFields, this.Query);
                }
            }

            if (this.Categories != null && this.Categories.Any())
            {
                searchCriteria.And().Field(ZoombracoConstants.Search.CategoryField, string.Join(" ", this.Categories));
            }

            if (!string.IsNullOrWhiteSpace(rootId))
            {
                searchCriteria.And().Field(ZoombracoConstants.Search.SiteField, rootId);
            }

            if (searchCriteria != null)
            {
                ISearchResults searchResults = null;
                try
                {
                    searchResults = searchProvider.Search(searchCriteria.Compile());
                }
                catch (NullReferenceException)
                {
                    // If the query object can't be compiled then an exception within Examine is raised
                }

                if (searchResults != null)
                {
                    Formatter formatter = new SimpleHTMLFormatter("<strong>", "</strong>");

                    foreach (SearchResult searchResult in searchResults.Skip(this.Skip).Take(this.Take))
                    {
                        foreach (CultureInfo culture in this.Cultures)
                        {
                            string fieldName   = string.Format(ZoombracoConstants.Search.MergedDataFieldTemplate, culture.Name);
                            string fieldResult = searchResult.Fields[fieldName];
                            this.AddSearchMatch(analyzer, formatter, searchResults, searchResponse, searchResult, fieldName, fieldResult);
                        }
                    }

                    searchResponse.TotalCount = searchResults.TotalItemCount;
                }
            }

            return(searchResponse);
        }