예제 #1
0
        /// <summary>
        /// Redirects to document.
        /// </summary>
        /// <param name="documentType">Type of the document.</param>
        /// <param name="documentId">The document identifier.</param>
        private void RedirectToDocument(string documentType, string documentId)
        {
            var indexDocumentEntityType = EntityTypeCache.Get(documentType);

            var indexDocumentType = indexDocumentEntityType.GetEntityType();

            var client = IndexContainer.GetActiveComponent();

            if (indexDocumentType != null)
            {
                var document = client.GetDocumentById(indexDocumentType, documentId);

                var documentUrl = document.GetDocumentUrl();

                if (!string.IsNullOrWhiteSpace(documentUrl))
                {
                    Response.Redirect(documentUrl);
                }
                else
                {
                    lResults.Text = "<div class='alert alert-warning'>No url is available for the provided index document.</div>";
                }
            }
            else
            {
                lResults.Text = "<div class='alert alert-warning'>Invalid document type.</div>";
            }
        }
예제 #2
0
        /// <summary>
        /// Crawls a page.
        /// </summary>
        /// <param name="url">The url to crawl.</param>
        private void CrawlPage(string url)
        {
            // clean up the url a bit
            url = StandardizeUrl(url);

            try
            {
                if (!PageHasBeenCrawled(url) && _robotHelper.IsPathAllowed(_userAgent, url) && url.StartsWith(_baseUrl))
                {
                    string rawPage = GetWebText(url);

                    if (!string.IsNullOrWhiteSpace(rawPage))
                    {
                        var htmlDoc = new HtmlDocument();
                        htmlDoc.LoadHtml(rawPage);

                        // ensure the page should be indexed by looking at the robot and rock conventions
                        HtmlNode metaRobot = htmlDoc.DocumentNode.SelectSingleNode("//meta[@name='robot']");
                        if (metaRobot == null || metaRobot.Attributes["content"] == null || !metaRobot.Attributes["content"].Value.Contains("noindex"))
                        {
                            _previouslyCrawledPages.Add(url);

                            // index the page
                            SitePageIndex sitePage = new SitePageIndex();

                            sitePage.Content             = GetPageText(htmlDoc);
                            sitePage.Url                 = url;
                            sitePage.Id                  = url.MakeInt64HashCode();
                            sitePage.SourceIndexModel    = "Rock.Model.Site";
                            sitePage.PageTitle           = GetPageTitle(htmlDoc, url);
                            sitePage.DocumentName        = sitePage.PageTitle;
                            sitePage.SiteName            = _site.Name;
                            sitePage.SiteId              = _site.Id;
                            sitePage.LastIndexedDateTime = RockDateTime.Now;

                            HtmlNode metaDescription = htmlDoc.DocumentNode.SelectSingleNode("//meta[@name='description']");
                            if (metaDescription != null && metaDescription.Attributes["content"] != null)
                            {
                                sitePage.PageSummary = metaDescription.Attributes["content"].Value;
                            }

                            HtmlNode metaKeynotes = htmlDoc.DocumentNode.SelectSingleNode("//meta[@name='keywords']");
                            if (metaKeynotes != null && metaKeynotes.Attributes["content"] != null)
                            {
                                sitePage.PageKeywords = metaKeynotes.Attributes["content"].Value;
                            }

                            IndexContainer.IndexDocument(sitePage);

                            // crawl all the links found on the page.
                            foreach (string link in ParseLinks(htmlDoc))
                            {
                                CrawlPage(link);
                            }
                        }
                    }
                }
            }
            catch { }
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (!File.Exists("_.index.bin"))
            {
                Console.WriteLine("File not found: _.index.bin");
                Console.WriteLine("Click enter to exit . . .");
                Console.ReadLine();
                return;
            }
            Console.WriteLine("Loading . . .");
            var gc = new IndexContainer("_.index.bin");
            var fl = File.CreateText("FileList.yml");

            foreach (var b in gc.Bundles)
            {
                fl.WriteLine(b.Name + ":");
                foreach (var f in b.Files)
                {
                    if (gc.Hashes.ContainsKey(f.Hash))
                    {
                        fl.WriteLine("- " + gc.Hashes[f.Hash]);
                    }
                }
            }
            fl.Flush();
            fl.Close();
            Console.WriteLine("Done!");
            Console.WriteLine("Click enter to exit . . .");
            Console.ReadLine();
        }
        /// <summary>
        /// Handles the SaveClick event of the MdEditEntityType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        private void MdEditEntityType_SaveClick(object sender, EventArgs e)
        {
            using (RockContext rockContext = new RockContext())
            {
                EntityTypeService entityTypeService = new EntityTypeService(rockContext);
                var entityType = entityTypeService.Get(hfIdValue.ValueAsInt());

                entityType.IsIndexingEnabled = cbEnabledIndexing.Checked;

                rockContext.SaveChanges();

                if (cbEnabledIndexing.Checked)
                {
                    IndexContainer.CreateIndex(entityType.IndexModelType);

                    // call for bulk indexing
                    BulkIndexEntityTypeTransaction bulkIndexTransaction = new BulkIndexEntityTypeTransaction();
                    bulkIndexTransaction.EntityTypeId = entityType.Id;

                    RockQueue.TransactionQueue.Enqueue(bulkIndexTransaction);
                }
                else
                {
                    IndexContainer.DeleteIndex(entityType.IndexModelType);
                }
            }

            mdEditEntityType.Hide();
            LoadEntities();
        }
예제 #5
0
        /// <summary>
        /// Bulks the index documents.
        /// </summary>
        public void BulkIndexDocuments()
        {
            List <IndexModelBase> indexableItems = new List <IndexModelBase>();

            RockContext rockContext = new RockContext();

            // return people
            var documents = new DocumentService(rockContext).Queryable().AsNoTracking();

            int recordCounter = 0;

            foreach (var document in documents)
            {
                var indexableDocument = DocumentIndex.LoadByModel(document);
                indexableItems.Add(indexableDocument);

                recordCounter++;

                if (recordCounter > 100)
                {
                    IndexContainer.IndexDocuments(indexableItems);
                    indexableItems = new List <IndexModelBase>();
                    recordCounter  = 0;
                }
            }

            IndexContainer.IndexDocuments(indexableItems);
        }
예제 #6
0
        /// <summary>
        /// Bulks the index documents.
        /// </summary>
        public void BulkIndexDocuments()
        {
            List <IndexModelBase> indexableItems = new List <IndexModelBase>();

            RockContext rockContext = new RockContext();

            // return people
            var groups = new GroupService(rockContext).Queryable().AsNoTracking()
                         .Where(g =>
                                g.IsActive == true &&
                                g.GroupType.IsIndexEnabled == true);

            int recordCounter = 0;

            foreach (var group in groups)
            {
                var indexableGroup = GroupIndex.LoadByModel(group);
                indexableItems.Add(indexableGroup);

                recordCounter++;

                if (recordCounter > 100)
                {
                    IndexContainer.IndexDocuments(indexableItems);
                    indexableItems = new List <IndexModelBase>();
                    recordCounter  = 0;
                }
            }

            IndexContainer.IndexDocuments(indexableItems);
        }
예제 #7
0
        /// <summary>
        /// Bulks the index documents.
        /// </summary>
        public void BulkIndexDocuments()
        {
            List <ContentChannelItemIndex> indexableChannelItems = new List <ContentChannelItemIndex>();

            // return all approved content channel items that are in content channels that should be indexed
            RockContext rockContext         = new RockContext();
            var         contentChannelItems = new ContentChannelItemService(rockContext).Queryable()
                                              .Where(i =>
                                                     i.ContentChannel.IsIndexEnabled &&
                                                     (i.ContentChannel.RequiresApproval == false || i.ContentChannel.ContentChannelType.DisableStatus || i.Status == ContentChannelItemStatus.Approved));

            int recordCounter = 0;

            foreach (var item in contentChannelItems)
            {
                var indexableChannelItem = ContentChannelItemIndex.LoadByModel(item);
                indexableChannelItems.Add(indexableChannelItem);

                recordCounter++;

                if (recordCounter > 100)
                {
                    IndexContainer.IndexDocuments(indexableChannelItems);
                    indexableChannelItems = new List <ContentChannelItemIndex>();
                    recordCounter         = 0;
                }
            }

            IndexContainer.IndexDocuments(indexableChannelItems);
        }
예제 #8
0
        /// <summary>
        /// Handles the SaveClick event of the MdEditEntityType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        private void MdEditEntityType_SaveClick(object sender, EventArgs e)
        {
            using (RockContext rockContext = new RockContext())
            {
                EntityTypeService entityTypeService = new EntityTypeService(rockContext);
                var entityType = entityTypeService.Get(hfIdValue.ValueAsInt());

                entityType.IsIndexingEnabled = cbEnabledIndexing.Checked;

                rockContext.SaveChanges();

                if (cbEnabledIndexing.Checked)
                {
                    IndexContainer.CreateIndex(entityType.IndexModelType);

                    // call for bulk indexing
                    var processEntityTypeBulkIndexMsg = new ProcessEntityTypeBulkIndex.Message
                    {
                        EntityTypeId = entityType.Id
                    };

                    processEntityTypeBulkIndexMsg.Send();
                }
                else
                {
                    IndexContainer.DeleteIndex(entityType.IndexModelType);
                }
            }

            mdEditEntityType.Hide();
            LoadEntities();
        }
예제 #9
0
        /// <summary>
        /// Indexes the document.
        /// </summary>
        /// <param name="id"></param>
        public void IndexDocument(int id)
        {
            var documentEntity = new DocumentService(new RockContext()).Get(id);

            var indexItem = DocumentIndex.LoadByModel(documentEntity);

            IndexContainer.IndexDocument(indexItem);
        }
예제 #10
0
        public IActionResult Index()
        {
            IndexContainer index = new IndexContainer();

            index.LoginForm    = new Login();
            index.RegisterForm = new Register();
            return(View(index));
        }
예제 #11
0
        private void OnButtonAddClick(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(
                    "This will import all files to the smallest bundle of all loaded bundles (doesn't contain which were filtered)." + Environment.NewLine
                    + "All files to be imported must be defined by the _.index.bin." + Environment.NewLine
                    + "Are you sure you want to do this?",
                    "Import Confirm",
                    MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.OK)
            {
                var fbd = new OpenFolderDialog();
                if (fbd.ShowDialog() == true)
                {
                    var          fileNames    = Directory.GetFiles(fbd.DirectoryPath, "*", SearchOption.AllDirectories);
                    int          l            = loadedBundles[0].UncompressedSize;
                    BundleRecord bundleToSave = loadedBundles[0];
                    RunBackground(() =>
                    {
                        Dispatcher.Invoke(() => { CurrentBackground.Message.Text = "Checking files . . ."; });
                        foreach (var f in fileNames)
                        {
                            var path = f.Remove(0, fbd.DirectoryPath.Length + 1).Replace("\\", "/");
                            if (!paths.Contains(path))
                            {
                                MessageBox.Show("The index didn't define the file:" + Environment.NewLine + path, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }
                        }

                        foreach (var b in loadedBundles)
                        {
                            if (b.UncompressedSize < l)
                            {
                                l            = b.UncompressedSize;
                                bundleToSave = b;
                            }
                        }
                        string str = "Imported {0}/" + fileNames.Length.ToString() + " Files";
                        int count  = 0;
                        foreach (var f in fileNames)
                        {
                            var path = f.Remove(0, fbd.DirectoryPath.Length + 1).Replace("\\", "/");
                            var fr   = ic.FindFiles[IndexContainer.FNV1a64Hash(path)];
                            fr.Write(File.ReadAllBytes(f));
                            fr.Move(bundleToSave);
                            ++count;
                            Dispatcher.Invoke(() => { CurrentBackground.Message.Text = string.Format(str, count); });
                        }
                        if (count > 0)
                        {
                            changed.Add(bundleToSave);
                        }
                    });
                    ButtonSave.IsEnabled = true;
                    MessageBox.Show("Imported " + fileNames.Length.ToString() + " files into " + bundleToSave.Name, "Done");
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Deletes the indexed documents by content channel.
        /// </summary>
        /// <param name="contentChannelId">The content channel identifier.</param>
        public void DeleteIndexedDocumentsByContentChannel(int contentChannelId)
        {
            var contentItems = new ContentChannelItemService(new RockContext()).Queryable()
                               .Where(i => i.ContentChannelId == contentChannelId);

            foreach (var item in contentItems)
            {
                var indexableChannelItem = ContentChannelItemIndex.LoadByModel(item);
                IndexContainer.DeleteDocument <ContentChannelItemIndex>(indexableChannelItem);
            }
        }
예제 #13
0
파일: GroupType.cs 프로젝트: sjison/Rock
        /// <summary>
        /// Deletes the indexed documents by group type.
        /// </summary>
        /// <param name="groupTypeId">The group type identifier.</param>
        public void DeleteIndexedDocumentsByGroupType(int groupTypeId)
        {
            var groups = new GroupService(new RockContext()).Queryable()
                         .Where(i => i.GroupTypeId == groupTypeId);

            foreach (var group in groups)
            {
                var indexableGroup = GroupIndex.LoadByModel(group);
                IndexContainer.DeleteDocument <GroupIndex>(indexableGroup);
            }
        }
예제 #14
0
        /// <summary>
        /// Indexes the document.
        /// </summary>
        /// <param name="id"></param>
        public void IndexDocument(int id)
        {
            var groupEntity = new GroupService(new RockContext()).Get(id);

            // check that this group type is set to be indexed.
            if (groupEntity.GroupType.IsIndexEnabled && groupEntity.IsActive)
            {
                var indexItem = GroupIndex.LoadByModel(groupEntity);
                IndexContainer.IndexDocument(indexItem);
            }
        }
예제 #15
0
        /// <summary>
        /// Indexes the document.
        /// </summary>
        /// <param name="id">The identifier.</param>
        public void IndexDocument(int id)
        {
            var eventItemEntity = new EventItemService(new RockContext()).Get(id);

            // Check to ensure that the event item is on a calendar that is indexed
            if (eventItemEntity != null && eventItemEntity.EventCalendarItems.Any(c => c.EventCalendar.IsIndexEnabled))
            {
                var indexItem = EventItemIndex.LoadByModel(eventItemEntity);
                IndexContainer.IndexDocument(indexItem);
            }
        }
예제 #16
0
        /// <summary>
        /// Load GGPK
        /// </summary>
        /// <param name="path">Path to GGPK file</param>
        public GGPKContainer(string path, bool BundleMode = false)
        {
            // Open File
            fileStream = File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
            Reader     = new BinaryReader(fileStream);
            Writer     = new BinaryWriter(fileStream);

            // Read ROOT Directory Record
            BaseRecord ggpk;

            while (!((ggpk = GetRecord()) is GGPKRecord))
            {
                ;
            }
            ggpkRecord         = ggpk as GGPKRecord;
            rootDirectory      = GetRecord(ggpkRecord.RootDirectoryOffset) as DirectoryRecord;
            rootDirectory.Name = "ROOT";

            // Build Linked FreeRecord List
            long NextFreeOffset = ggpkRecord.FirstFreeRecordOffset;

            while (NextFreeOffset > 0)
            {
                FreeRecord current = GetRecord(NextFreeOffset) as FreeRecord;
                LinkedFreeRecords.AddLast(current);
                NextFreeOffset = current.NextFreeOffset;
            }

            if (BundleMode)
            {
                return;
            }
            // Read Bundles
            var Bundles2DirectoryNameHash = MurmurHash2Unsafe.Hash("bundles2", 0);

            OriginalBundles2 = rootDirectory.Children.First(d => d.GetNameHash() == Bundles2DirectoryNameHash) as DirectoryRecord;
            if (OriginalBundles2.Children.FirstOrDefault(r => r.Name == "_.index.bin") is FileRecord _index)
            {
                IndexRecord = _index;
                fileStream.Seek(_index.DataBegin, SeekOrigin.Begin);
                Index        = new IndexContainer(Reader);
                FakeBundles2 = new BundleDirectoryNode("Bundles2", "", MurmurHash2Unsafe.Hash("bundles2", 0), (int)OriginalBundles2.Offset, OriginalBundles2.Length, this);
                rootDirectory.Children.Remove(OriginalBundles2);
                rootDirectory.Children.Add(FakeBundles2);
                foreach (var f in Index.Files)
                {
                    BuildBundleTree(f, FakeBundles2);
                }
            }
            foreach (var br in Index.Bundles)
            {
                RecordOfBundle[br] = (FileRecord)FindRecord(br.Name, OriginalBundles2);
            }
        }
예제 #17
0
        /// <summary>
        /// Builds a very basic index configuration in-memory given state.
        /// </summary>
        /// <returns>Contents of the index file.</returns>
        protected override void BuildIndex(State state)
        {
            // Google automatically builds single property indexes
            if (state.QueryBuilder.Count(x => x.ComponentType == QueryComponentType.MemberName ||
                                         (x.ComponentType == QueryComponentType.QueryPartSelectProjection && x.Component != "*")) <= 1)
            {
                return;
            }

            var indexPath = Configuration.IndexFileLocation;
            var indexes   = IndexContainer.GetIndexList();

            // Load indexes into memory if necessary
            if (indexes.Count == 0)
            {
                // Create index file it it does not exist
                if (!File.Exists(indexPath))
                {
                    File.WriteAllText(indexPath, string.Empty);
                }

                var indexYaml = File.ReadAllLines(indexPath);
                indexes.AddRange(IndexParser.Deserialize(indexYaml));
            }

            var kind       = typeof(T).Name;
            var properties = state.QueryBuilder.Where(x => x.ComponentType == QueryComponentType.MemberName)
                             .Select(x => x.Component).ToList();

            // Add projections
            properties.AddRange(state.QueryBuilder.Where(x => x.ComponentType == QueryComponentType.QueryPartSelectProjection)
                                .SelectMany(x => x.Component.Split(',').Select(y => y.Trim())));

            // Create index if it does not have the properties with the specified ordering
            // TODO ordering of index properties + orderingtype (sorting) of indexes
            if (!indexes.Any(x => x.Properties.Select(y => y.PropertyName).SequenceEqual(properties)))
            {
                var index = new Index
                {
                    Kind       = kind,
                    Properties = properties.Select(
                        x => new Index.IndexProperty
                    {
                        OrderingType = Index.OrderingType.NotSpecified,
                        PropertyName = x
                    })
                                 .ToList()
                };
                indexes.Add(index);

                // Save it to file
                File.WriteAllText(indexPath, IndexParser.Serialize(indexes));
            }
        }
예제 #18
0
        public void Save(string directory)
        {
            IndexContainer?.Save(directory, ConfigContainer);
            RootFile?.Write(directory, this);
            DownloadFile?.Write(directory, this);
            DownloadSizeFile?.Write(directory, this);
            InstallFile?.Write(directory, this);
            EncodingFile?.Write(directory, ConfigContainer);
            ConfigContainer?.Save(directory);

            RootFile?.FileLookup?.Close();
        }
예제 #19
0
        /// <summary>
        /// Re-indexes the selected entity types in Universal Search
        ///
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            string     selectedEntitiesSetting = dataMap.GetString("EntityFilter");
            bool       allEntities             = dataMap.GetBoolean("IndexAllEntities");

            RockContext rockContext = new RockContext();

            var selectedEntityTypes = EntityTypeCache.All().Where(e => e.IsIndexingSupported && e.IsIndexingEnabled && e.FriendlyName != "Site");

            // if 'All' wasn't selected the filter out the ones that weren't selected
            if (!allEntities)
            {
                if (selectedEntitiesSetting.IsNotNullOrWhiteSpace())
                {
                    var selectedEntityIds = selectedEntitiesSetting.Split(',').Select(int.Parse).ToList();
                    selectedEntityTypes = selectedEntityTypes.Where(e => selectedEntityIds.Contains(e.Id));
                }
            }

            string results    = string.Empty;
            var    timerTotal = System.Diagnostics.Stopwatch.StartNew();

            foreach (var entityTypeCache in selectedEntityTypes)
            {
                EntityTypeService entityTypeService = new EntityTypeService(rockContext);
                var entityType = entityTypeService.Get(entityTypeCache.Id);

                IndexContainer.DeleteIndex(entityType.IndexModelType);
                IndexContainer.CreateIndex(entityType.IndexModelType);

                Type type = entityTypeCache.GetEntityType();

                if (type != null)
                {
                    object     classInstance   = Activator.CreateInstance(type, null);
                    MethodInfo bulkItemsMethod = type.GetMethod("BulkIndexDocuments");

                    if (classInstance != null && bulkItemsMethod != null)
                    {
                        var timer = System.Diagnostics.Stopwatch.StartNew();
                        bulkItemsMethod.Invoke(classInstance, null);
                        timer.Stop();
                        results += $"{entityType.FriendlyName}: {timer.ElapsedMilliseconds/1000}s,";
                    }
                }
            }

            results       += $"Total Time: {timerTotal.ElapsedMilliseconds / 1000}s,";
            context.Result = "Indexing results: " + results.Trim(',');
        }
        /// <summary>
        /// Handles the Click event of the gRefresh control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gRefresh_Click(object sender, RowEventArgs e)
        {
            RockContext       rockContext       = new RockContext();
            EntityTypeService entityTypeService = new EntityTypeService(rockContext);
            var entityType = entityTypeService.Get(e.RowKeyId);

            if (entityType != null)
            {
                IndexContainer.DeleteIndex(entityType.IndexModelType);
                IndexContainer.CreateIndex(entityType.IndexModelType);

                maMessages.Show(string.Format("The index for {0} has been re-created.", entityType.FriendlyName), ModalAlertType.Information);
            }
        }
예제 #21
0
파일: Site.cs 프로젝트: ewin66/rockrms
        /// <summary>
        /// Bulks the index documents.
        /// </summary>
        public void BulkIndexDocuments()
        {
            // get list of sites that with indexing enabled
            var sites = new SiteService(new RockContext()).Queryable().Where(s => s.IsIndexEnabled);

            foreach (var site in sites)
            {
                // delete current items index
                IndexContainer.DeleteDocumentByProperty(typeof(SitePageIndex), "SiteId", site.Id);

                // clear current documents out
                var pageCount = new Crawler().CrawlSite(site);
            }
        }
예제 #22
0
        /// <summary>
        /// Crawls a site.
        /// </summary>
        /// <param name="site">The site.</param>
        /// <param name="loginId">The login identifier.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public int CrawlSite(Site site, string loginId, string password)
        {
            // Delete the indicies for the site that is being indexed.
            IndexContainer.DeleteDocumentByProperty(typeof(SitePageIndex), "SiteId", site.Id);

            _site = site;

            _startUrl = _site.IndexStartingLocation;
            var startingUri = new Uri(_startUrl);

            _baseUrl = startingUri.Scheme + "://" + startingUri.Authority;
            var baseUri = new Uri(_baseUrl);

            // get the robot helper class up and running
            var robotsUri = new Uri(baseUri, "robots.txt");
            var robotsTxt = GetWebText(robotsUri);

            _robotHelper = Robots.Load(robotsTxt);

            _cookieContainer = new CookieContainer();

            // If a loginId and password were included, get an authentication cookie
            if (loginId.IsNotNullOrWhiteSpace() && password.IsNotNullOrWhiteSpace())
            {
                var loginParam = new LoginParameters();
                loginParam.Username  = loginId;
                loginParam.Password  = password;
                loginParam.Persisted = false;

                var authUri    = new Uri(baseUri, "api/Auth/Login");
                var restClient = new RestClient(authUri);
                restClient.CookieContainer = _cookieContainer;

                var request = new RestRequest(Method.POST);
                request.RequestFormat = DataFormat.Json;
                request.AddBody(loginParam);

                var response = restClient.Execute(request);
            }

            _urlQueue.Enqueue(_site.IndexStartingLocation);
            while (_urlQueue.Any())
            {
                string url = _urlQueue.Dequeue().Replace("?", "\\?");
                CrawlPage(url);
            }

            return(_previouslyCrawledPages.Count);
        }
예제 #23
0
        /// <summary>
        /// Indexes the document.
        /// </summary>
        /// <param name="id"></param>
        public void IndexDocument(int id)
        {
            var itemEntity = new ContentChannelItemService(new RockContext()).Get(id);

            // only index if the content channel is set to be indexed
            if (itemEntity.ContentChannel != null && itemEntity.ContentChannel.IsIndexEnabled)
            {
                // ensure it's meant to be indexed
                if (itemEntity.ContentChannel.IsIndexEnabled && (itemEntity.ContentChannel.RequiresApproval == false || itemEntity.ContentChannel.ContentChannelType.DisableStatus || itemEntity.Status == ContentChannelItemStatus.Approved))
                {
                    var indexItem = ContentChannelItemIndex.LoadByModel(itemEntity);
                    IndexContainer.IndexDocument(indexItem);
                }
            }
        }
예제 #24
0
        public void Save(string directory)
        {
            // if this field exists and mismatches the generated file; the client will error
            // if this field is missing the client will generate the file and variable itself
            ConfigContainer?.CDNConfig?.GetValues("archive-group")?.Clear();

            IndexContainer?.Save(directory, ConfigContainer);
            RootFile?.Write(directory, this);
            DownloadFile?.Write(directory, this);
            DownloadSizeFile?.Write(directory, this);
            InstallFile?.Write(directory, this);
            EncodingFile?.Write(directory, ConfigContainer);
            ConfigContainer?.Save(directory);

            RootFile?.FileLookup?.Close();
        }
예제 #25
0
        private void OnButtonAddClick(object sender, RoutedEventArgs e)
        {
            var tvi = GetSelectedBundle();

            if (tvi == null)
            {
                return;
            }
            var br = tvi.Record as BundleRecord;

            if (br != null) //Selected Bundle File
            {
                var fbd = new OpenFileDialog()
                {
                    ValidateNames   = false,
                    CheckFileExists = false,
                    CheckPathExists = true,
                    FileName        = "(In Bundle2 Folder)"
                };
                if (fbd.ShowDialog() == true)
                {
                    var Bundle2_path = Path.GetDirectoryName(fbd.FileName);
                    var fs           = Directory.GetFiles(Bundle2_path, "*", SearchOption.AllDirectories);
                    var paths        = ic.Hashes.Values;
                    foreach (var f in fs)
                    {
                        var path = f.Remove(0, Bundle2_path.Length + 1).Replace("\\", "/");
                        if (!paths.Contains(path))
                        {
                            MessageBox.Show("The index didn't define the file:" + Environment.NewLine + path, "Error");
                            return;
                        }
                    }
                    foreach (var f in fs)
                    {
                        var path = f.Remove(0, Bundle2_path.Length + 1).Replace("\\", "/");
                        var fr   = ic.FindFiles[IndexContainer.FNV1a64Hash(path)];
                        fr.Write(File.ReadAllBytes(f));
                        fr.Move(br);
                    }
                    changed.Add(br);
                    ButtonSave.IsEnabled = true;
                    MessageBox.Show("Added " + fs.Length.ToString() + " files to " + br.Name, "Done");
                }
            }
        }
예제 #26
0
        /// <summary>
        /// Returns a list of matching people
        /// </summary>
        /// <param name="searchterm"></param>
        /// <returns></returns>
        public override IQueryable <string> Search(string searchterm)
        {
            // get configured entities and turn it into a list of entity ids
            List <int> entityIds = new List <int>();

            var searchEntitiesSetting = Rock.Web.SystemSettings.GetValue("core_SmartSearchUniversalSearchEntities");

            if (!string.IsNullOrWhiteSpace(searchEntitiesSetting))
            {
                entityIds = searchEntitiesSetting.Split(',').Select(int.Parse).ToList();
            }

            // get the field critiera
            var fieldCriteriaSetting          = Rock.Web.SystemSettings.GetValue("core_SmartSearchUniversalSearchFieldCriteria");
            SearchFieldCriteria fieldCriteria = new SearchFieldCriteria();

            // get the search type
            var searchType = SearchType.Wildcard;

            if (!string.IsNullOrWhiteSpace(Rock.Web.SystemSettings.GetValue("core_SmartSearchUniversalSearchSearchType")))
            {
                searchType = (SearchType)Enum.Parse(typeof(SearchType), Rock.Web.SystemSettings.GetValue("core_SmartSearchUniversalSearchSearchType"));
            }

            if (!string.IsNullOrWhiteSpace(fieldCriteriaSetting))
            {
                foreach (var queryString in fieldCriteriaSetting.ToKeyValuePairList())
                {
                    // check that multiple values were not passed
                    var values = queryString.Value.ToString().Split(',');

                    foreach (var value in values)
                    {
                        fieldCriteria.FieldValues.Add(new FieldValue {
                            Field = queryString.Key, Value = value
                        });
                    }
                }
            }

            var client  = IndexContainer.GetActiveComponent();
            var results = client.Search(searchterm, searchType, entityIds, fieldCriteria);

            // NOTE: Put a bunch of whitespace before and after it so that the Search box shows blank instead of stringified html
            return(results.Select(r => $"                                                                       <data return-type='{r.IndexModelType}' return-id={r.Id}></data><i class='{ r.IconCssClass}'></i> {r.DocumentName}                                                                               ").ToList().AsQueryable());
        }
예제 #27
0
        /// <summary>
        /// Gets the search result queryable that matches the search term.
        /// </summary>
        /// <param name="searchTerm">The search term used to find results.</param>
        /// <returns>A queryable of index models that match the search term.</returns>
        private List <UniversalSearch.IndexModels.IndexModelBase> GetSearchResults(string searchTerm)
        {
            // get configured entities and turn it into a list of entity ids
            List <int> entityIds = new List <int>();

            var searchEntitiesSetting = Rock.Web.SystemSettings.GetValue("core_SmartSearchUniversalSearchEntities");

            if (!string.IsNullOrWhiteSpace(searchEntitiesSetting))
            {
                entityIds = searchEntitiesSetting.Split(',').Select(int.Parse).ToList();
            }

            // get the field criteria
            var fieldCriteriaSetting          = Rock.Web.SystemSettings.GetValue("core_SmartSearchUniversalSearchFieldCriteria");
            SearchFieldCriteria fieldCriteria = new SearchFieldCriteria();

            // get the search type
            var searchType = SearchType.Wildcard;

            if (!string.IsNullOrWhiteSpace(Rock.Web.SystemSettings.GetValue("core_SmartSearchUniversalSearchSearchType")))
            {
                searchType = ( SearchType )Enum.Parse(typeof(SearchType), Rock.Web.SystemSettings.GetValue("core_SmartSearchUniversalSearchSearchType"));
            }

            if (!string.IsNullOrWhiteSpace(fieldCriteriaSetting))
            {
                foreach (var queryString in fieldCriteriaSetting.ToKeyValuePairList())
                {
                    // check that multiple values were not passed
                    var values = queryString.Value.ToString().Split(',');

                    foreach (var value in values)
                    {
                        fieldCriteria.FieldValues.Add(new FieldValue {
                            Field = queryString.Key, Value = value
                        });
                    }
                }
            }

            var client = IndexContainer.GetActiveComponent();

            return(client.Search(searchTerm, searchType, entityIds, fieldCriteria));
        }
예제 #28
0
파일: GroupType.cs 프로젝트: sjison/Rock
        /// <summary>
        /// Bulks the index documents by content channel.
        /// </summary>
        /// <param name="groupTypeId">The content channel identifier.</param>
        public void BulkIndexDocumentsByGroupType(int groupTypeId)
        {
            List <GroupIndex> indexableGroups = new List <GroupIndex>();

            // return all approved content channel items that are in content channels that should be indexed
            RockContext rockContext = new RockContext();
            var         groups      = new GroupService(rockContext).Queryable()
                                      .Where(g =>
                                             g.GroupTypeId == groupTypeId &&
                                             g.IsActive);

            foreach (var group in groups)
            {
                var indexableChannelItem = GroupIndex.LoadByModel(group);
                indexableGroups.Add(indexableChannelItem);
            }

            IndexContainer.IndexDocuments(indexableGroups);
        }
예제 #29
0
        private void ButtonReplaceAllClick(object sender, RoutedEventArgs e)
        {
            var fbd = OpenBundles2Dialog();

            if (fbd.ShowDialog() == true)
            {
                if (MessageBox.Show(
                        "This will replace all files to every loaded bundles (doesn't contain which were filtered)." + Environment.NewLine
                        + "And bundles which weren't loaded won't be changed." + Environment.NewLine
                        + "Are you sure you want to do this?",
                        "Replace All Confirm",
                        MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel) == MessageBoxResult.OK)
                {
                    var count = 0;
                    var size  = 0;
                    RunBackground(() =>
                    {
                        var Bundles2_path = Path.GetDirectoryName(fbd.FileName);
                        var fs            = Directory.GetFiles(Bundles2_path, "*", SearchOption.AllDirectories);
                        foreach (var f in fs)
                        {
                            var path = f.Remove(0, Bundles2_path.Length + 1).Replace("\\", "/");
                            if (!ic.FindFiles.TryGetValue(IndexContainer.FNV1a64Hash(path), out FileRecord fr))
                            {
                                continue;
                            }
                            var br = fr.bundleRecord;
                            if (loadedBundles.Contains(br))
                            {
                                fr.Write(File.ReadAllBytes(f));
                                changed.Add(br);
                                ++count;
                                size += fr.Size;
                                Dispatcher.Invoke(() => { CurrentBackground.Message.Text = "Replaced " + count.ToString() + " Files"; });
                            }
                        }
                    });
                    ButtonSave.IsEnabled = true;
                    MessageBox.Show("Imported " + count.ToString() + " Files." + Environment.NewLine
                                    + "Total " + size.ToString() + " Bytes.", "Done");
                }
            }
        }
예제 #30
0
        /// <summary>
        /// Job that will run quick SQL queries on a schedule.
        ///
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap  = context.JobDetail.JobDataMap;
            var        siteId   = dataMap.GetString("Site").AsIntegerOrNull();
            string     loginId  = dataMap.GetString("LoginId");
            string     password = dataMap.GetString("Password");

            Uri startingUri;

            if (siteId.HasValue)
            {
                _site = new SiteService(new RockContext()).Get(siteId.Value);

                if (_site != null)
                {
                    var startingUrl = _site.IndexStartingLocation;

                    if (Uri.TryCreate(startingUrl, UriKind.Absolute, out startingUri) && (startingUri.Scheme == Uri.UriSchemeHttp || startingUri.Scheme == Uri.UriSchemeHttps))
                    {
                        // ensure that an index is configured for site pages, if not create it
                        IndexContainer.CreateIndex(typeof(SitePageIndex), false);

                        // release the crawler, like the kraken... but not...
                        var pages = new Crawler().CrawlSite(_site, loginId, password);

                        context.Result = string.Format("Crawler indexed {0} pages.", pages, _indexedPageCount);
                    }
                    else
                    {
                        context.Result = "An invalid starting URL was provided.";
                    }
                }
                else
                {
                    context.Result = "Could not locate the site provided.";
                }
            }
            else
            {
                context.Result = "An invalid site was provided.";
            }
        }