示例#1
0
        public object Any(Ask request)
        {
            AskResponse response = new AskResponse();

            response.Result = ErrorCode.OK;

            Guid creatorId = UserSession.GetUserId();

            DateTime      dateTime      = DateTime.UtcNow;
            QuestionEntry questionEntry = new QuestionEntry(creatorId, Guid.NewGuid())
            {
                Title        = request.Title,
                Detail       = request.Detail,
                Creation     = dateTime,
                Modification = dateTime,
                Tags         = string.Join(",", request.Tags).ToLowerInvariant()
            };

            TableRepository tableRepository = new TableRepository();

            tableRepository.InsertOrReplace(questionEntry, Tables.Questions);

            IndexHelper.CreateIndex(questionEntry.GetId(), request.Title + " " + questionEntry.Tags, Tables.Questions);

            return(response);
        }
        private bool AnnotationIntersectsWith(TimeInterval timeInterval)
        {
            // If there's no annotations at all, we're done
            if ((this.Data == null) || (this.Data.Count <= 0))
            {
                return(false);
            }

            // Find the nearest annotation to the left edge of the interval
            int index = IndexHelper.GetIndexForTime(timeInterval.Left, this.Data.Count, (idx) => this.Data[idx].Data.Interval.Right, SnappingBehavior.Nearest);

            // Check if the annotation intersects with the interval, then keep walking to the right until
            // we find an annotation within the interval or we go past the right hand side of the interval.
            while (index < this.Data.Count)
            {
                TimeIntervalAnnotation annotation = this.Data[index].Data;

                // Check if the annotation intersects with the interval
                if (timeInterval.IntersectsWith(annotation.Interval))
                {
                    return(true);
                }

                // Check if the annotation is completely to the right of the interval
                if (timeInterval.Right <= annotation.Interval.Left)
                {
                    return(false);
                }

                index++;
            }

            return(false);
        }
示例#3
0
        protected override DawgSearchableIndex CreateIndex(string[][] corpus)
        {
            var buildableIndex = new DawgBuildableIndex();

            IndexHelper.BuildIndex(buildableIndex, corpus);
            return(buildableIndex.Build());
        }
        private void btnDelete_Click(Object sender, ImageClickEventArgs e)
        {
            if (lbPages.SelectedIndex > -1)
            {
                foreach (CSiteMapNode page in sitePages)
                {
                    if ((page.PageId.ToString() == lbPages.SelectedValue) && ((canEditAnything) || (WebUser.IsInRoles(page.EditRoles))))
                    {
                        Module.DeletePageModules(page.PageId);
                        PageSettings.DeletePage(page.PageId);
                        FriendlyUrl.DeleteUrlByPageId(page.PageId);
                        PageSettings pageSettings = new PageSettings(siteSettings.SiteId, page.PageId);
                        IndexHelper.ClearPageIndexAsync(pageSettings);
                    }
                }

                CacheHelper.ResetSiteMapCache();

                WebUtils.SetupRedirect(this, Request.RawUrl);
            }
            else
            {
                // no page selected
                litWarning.Text = Resource.PagesNoSelectionWarning;
            }
        }
示例#5
0
        private Guid AddSubmittedValuesToIndex(IPublishedContent content, IEnumerable <FieldWithValue> valueFields)
        {
            var rowId = Guid.NewGuid();

            // extract all index values
            var indexFields = valueFields.ToDictionary(f => f.FormSafeName, f => FormatForIndexAndSanitize(f, content, rowId));

            // add the IP of the user if enabled on the data type
            if (LogIp)
            {
                indexFields.Add("_ip", Request.UserHostAddress);
            }

            // store fields in index
            var index           = IndexHelper.GetIndex(content.Id);
            var statisticsIndex = index as IStatisticsIndex;

            if (UseStatistics && statisticsIndex != null)
            {
                var indexFieldsForStatistics = valueFields.StatisticsFields().ToDictionary(f => f.FormSafeName, f => f.SubmittedValues ?? new string[] {});
                statisticsIndex.Add(indexFields, indexFieldsForStatistics, rowId);
            }
            else
            {
                index.Add(indexFields, rowId);
            }

            return(rowId);
        }
        public override void ContentChangedHandler(object sender, ContentChangedEventArgs e)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }

            Item item = (Item)sender;

            if (e.IsDeleted)
            {
                // get list of pages where this module is published
                Module            module      = new Module(item.ModuleGuid);
                List <PageModule> pageModules = PageModule.GetPageModulesByModule(module.ModuleId);

                foreach (PageModule pageModule in pageModules)
                {
                    IndexHelper.RemoveIndexItem(
                        pageModule.PageId,
                        module.ModuleId,
                        item.ItemID);
                }
            }
            else
            {
                IndexItem(item);
            }
        }
示例#7
0
        public JsonResult CreateIndex(string indexFolder)
        {
            IndexHelper.AddIndex(indexFolder);
            AjaxResponse ajaxResponse = GetIndexAjaxResponse();

            return(Json(ajaxResponse));
        }
 public void TestInitialize()
 {
     var testApiKey = Environment.GetEnvironmentVariable("ALGOLIA_API_KEY");
     var testApplicationID = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID");
     _client = new AlgoliaClient(testApplicationID, testApiKey);
     _indexHelper = new IndexHelper<TestModel>(_client, GetSafeName("àlgol?à-csharp"));
 }
示例#9
0
        public void AddOrUpdate(Object keyObject, AGraphElement graphElement)
        {
            IComparable key;

            if (!IndexHelper.CheckObject(out key, keyObject))
            {
                return;
            }

            if (WriteResource())
            {
                List <AGraphElement> values;
                if (_idx.TryGetValue(key, out values))
                {
                    values.Add(graphElement);
                }
                else
                {
                    values = new List <AGraphElement> {
                        graphElement
                    };
                    _idx.Add(key, values);
                }

                FinishWriteResource();

                return;
            }

            throw new CollisionException();
        }
        public void TestDeleteObjectObjectId()
        {
            ClearTest();
            _indexHelper = new IndexHelper <TestModel>(_client, GetSafeName("àlgol?à-csharp"), "TestModelId");

            var model = BuildTestModel();
            var task  = _indexHelper.SaveObject(model);

            _indexHelper.WaitTask(task["taskID"].ToString());

            var models = BuildTestModelList();
            var tasks  = _indexHelper.SaveObjects(models);

            foreach (var item in tasks)
            {
                _indexHelper.WaitTask(item["taskID"].ToString());
            }

            var res = _indexHelper.Search(new Query(""));

            Assert.Equal(5, res["nbHits"].ToObject <int>());
            Assert.Equal("Sylvain", res["hits"][0]["FirstName"].ToString());
            Assert.Equal("8", res["hits"][0]["objectID"].ToString());

            task = _indexHelper.DeleteObject(model);
            _indexHelper.WaitTask(task["taskID"].ToString());

            res = _indexHelper.Search(new Query(""));

            Assert.Equal(4, res["nbHits"].ToObject <int>());
            Assert.Equal("Sylvain", res["hits"][0]["FirstName"].ToString());
            Assert.Equal("8", res["hits"][0]["objectID"].ToString());
        }
        /// <summary>
        /// Reads instant data from the stream at the given cursor time and pushes it to all registered adapting data providers.
        /// </summary>
        /// <param name="reader">The simple reader that will read the data.</param>
        /// <param name="cursorTime">The cursor time at which to read the data.</param>
        /// <param name="indexCache">The stream reader's index cache.</param>
        public void ReadInstantData(ISimpleReader reader, DateTime cursorTime, ObservableKeyedCache <DateTime, IndexEntry> indexCache)
        {
            // Get the index of the data, given the cursor time
            int index = IndexHelper.GetIndexForTime(cursorTime, indexCache?.Count ?? 0, (idx) => indexCache[idx].OriginatingTime, this.CursorEpsilon);

            T          data       = default;
            IndexEntry indexEntry = default;

            if (index >= 0)
            {
                // Get the index entry
                indexEntry = indexCache[index];

                // Read the data
                data = reader.Read <T>(indexEntry);
            }

            // Notify each adapting data provider of the new data
            foreach (IAdaptingInstantDataProvider <T> adaptingInstantDataProvider in this.dataProviders.ToList())
            {
                adaptingInstantDataProvider.PushData(data, indexEntry);
            }

            // Release the reference to the local copy of the data if it's shared
            if (this.isSharedType && data != null)
            {
                (data as IDisposable).Dispose();
            }
        }
示例#12
0
        public void LoadValues(IPublishedContent content, Guid rowId)
        {
            if (rowId == Guid.Empty)
            {
                return;
            }
            var index    = IndexHelper.GetIndex(content.Id);
            var formData = index.Get(rowId);

            if (formData == null)
            {
                return;
            }

            RowId = rowId;

            var fields = AllFields().ToArray();

            foreach (var field in fields)
            {
                field.CollectSubmittedValue(formData.Fields, content);
            }
            foreach (var field in fields)
            {
                // using ValidateSubmittedValue to load up select boxes
                field.ValidateSubmittedValue(fields, content);
            }
        }
        protected override Index CreateIndex(string[][] corpus)
        {
            var index = new Index();

            IndexHelper.BuildIndex(index, corpus);
            return(index);
        }
示例#14
0
        public HttpResponseMessage PurgeExpiredSubmissions(string authToken)
        {
            // validate authentication token
            if (FormEditor.Configuration.Instance.Jobs == null || FormEditor.Configuration.Instance.Jobs.IsValidAuthToken(authToken) == false)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid authentication token"));
            }

            try
            {
                ContentHelper.ForEachFormModel(ApplicationContext.Services, (formModel, content) =>
                {
                    if (formModel.DaysBeforeSubmissionExpiry.HasValue == false || formModel.DaysBeforeSubmissionExpiry.Value <= 0)
                    {
                        return;
                    }
                    var olderThan = DateTime.UtcNow.AddDays(-1 * formModel.DaysBeforeSubmissionExpiry.Value);
                    if (!(IndexHelper.GetIndex(content.Id) is IAutomationIndex index))
                    {
                        Log.Warning($"Unable to purge expired submissions - the configured storage index is not of type {nameof(IAutomationIndex)}");
                        return;
                    }
                    index.RemoveOlderThan(olderThan);
                });

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
示例#15
0
        public static void RemoveForumIndexItem(object oForumThread)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }

            if (!(oForumThread is KalturaVideoNotification))
            {
                return;
            }

            KalturaVideoNotification forumThread = oForumThread as KalturaVideoNotification;
            // get list of pages where this module is published
            List <PageModule> pageModules = PageModule.GetPageModulesByModule(forumThread.ModuleID);

            // must update index for all pages containing this module
            foreach (PageModule pageModule in pageModules)
            {
                IndexItem indexItem = new IndexItem();
                // note we are just assigning the properties needed to derive the key so it can be found and deleted from the index
                indexItem.SiteId   = forumThread.SiteId;
                indexItem.PageId   = pageModule.PageId;
                indexItem.ModuleId = forumThread.ModuleID;
                indexItem.ItemId   = forumThread.KalturaVideoID;
                IndexHelper.RemoveIndex(indexItem);
            }
            if (debugLog)
            {
                log.Debug("Removed Index ");
            }
        }
        private void BindContent()
        {
            List <IndexItem> recentContent;

            Guid[] guids = config.GetFeatureGuids();

            if (config.GetCreated)
            {
                recentContent = IndexHelper.GetRecentCreatedContent(
                    siteSettings.SiteId,
                    guids,
                    DateTime.UtcNow.AddDays(-config.MaxDaysOldRecentItemsToGet),
                    config.MaxRecentItemsToGet);
            }
            else
            {
                recentContent = IndexHelper.GetRecentModifiedContent(
                    siteSettings.SiteId,
                    guids,
                    DateTime.UtcNow.AddDays(-config.MaxDaysOldRecentItemsToGet),
                    config.MaxRecentItemsToGet);
            }

            rptResults.DataSource = recentContent;
            rptResults.DataBind();

            rptResults.Visible = (rptResults.Items.Count > 0);
        }
        public static DictionaryIndex <string> CreateDictionaryIndex(string[][] corpus)
        {
            var index = new DictionaryIndex <string>(rareWordThreshold: 3);

            IndexHelper.BuildIndex(index, corpus);
            return(index);
        }
        private static void RemoveGalleryImageIndexItem(
            int siteId,
            int pageId,
            int moduleId,
            int itemId)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }

            IndexItem indexItem = new IndexItem();

            indexItem.SiteId              = siteId;
            indexItem.PageId              = pageId;
            indexItem.ModuleId            = moduleId;
            indexItem.ItemId              = itemId;
            indexItem.QueryStringAddendum = "&ItemID" + moduleId.ToString()
                                            + "=" + itemId.ToString();

            IndexHelper.RemoveIndex(indexItem);

            if (log.IsDebugEnabled)
            {
                log.Debug("Removed Index ");
            }
        }
示例#19
0
        private double GetDiscretePointDose(int xSteps, int ySteps, int zSteps)
        {
            int index = IndexHelper.LatticeXYZToIndex(xSteps, ySteps, zSteps, DimensionX, DimensionY);
            var value = DoseValues[index];

            return(value);
        }
示例#20
0
        public JsonResult AddFolderToIndex(Guid indexId, string folderName)
        {
            IndexHelper.AddToIndex(indexId, folderName);
            AjaxResponse ajaxResponse = GetIndexAjaxResponse();

            return(Json(ajaxResponse));
        }
示例#21
0
        protected internal override string FormatSubmittedValueForIndex(IPublishedContent content, Guid rowId)
        {
            var file = GetUploadedFile();

            if (file == null)
            {
                return(null);
            }

            var indexValue = ParseIndexValue(SubmittedValue);

            if (indexValue == null)
            {
                return(null);
            }

            // save the file to the index
            var index = IndexHelper.GetIndex(content.Id);

            if (index.SaveFile(file, indexValue.PersistedFilename, rowId) == false)
            {
                return(null);
            }

            return(SubmittedValue);
        }
示例#22
0
        public JsonResult RunSearch(Guid selectedIndexId, string searchQuery)
        {
            SearchResults results  = IndexHelper.Search(selectedIndexId, searchQuery);
            AjaxResponse  response = GetSearchAjaxResponse(results);

            return(Json(response));
        }
示例#23
0
        public HttpResponseMessage SearchAll(string searchQuery)
        {
            var contentResults = new List <ContentResult>();

            ContentHelper.ForEachFormModel(ApplicationContext.Services, (formModel, content) =>
            {
                if (!(IndexHelper.GetIndex(content.Id) is IFullTextIndex index))
                {
                    return;
                }

                var fields = formModel.AllValueFields().ToArray();
                var result = index.Search(searchQuery, fields.Select(f => f.FormSafeName).ToArray(), null, false, 100, 0);
                if (result == null || result.TotalRows == 0)
                {
                    return;
                }

                var rows = formModel.ExtractSubmittedValues(result, fields, (field, value, row) => value == null ? null : field.FormatValueForDataView(value, content, row.Id));

                contentResults.Add(new ContentResult
                {
                    ContentId   = content.Id,
                    ContentName = content.Name,
                    FieldNames  = fields.Select(f => f.Name).ToArray(),
                    Rows        = rows.ToArray()
                });
            });
示例#24
0
        public bool TryGetValue(out ReadOnlyCollection <AGraphElement> result, Object keyObject)
        {
            IComparable key;

            if (!IndexHelper.CheckObject(out key, keyObject))
            {
                result = null;

                return(false);
            }

            if (ReadResource())
            {
                AGraphElement element;
                var           foundSth = _idx.TryGetValue(key, out element);

                result = foundSth ? new ReadOnlyCollection <AGraphElement>(new List <AGraphElement> {
                    element
                }) : null;

                FinishReadResource();

                return(foundSth);
            }

            throw new CollisionException(this);
        }
示例#25
0
        protected override DictionaryIndex <string> CreateIndex(string[][] corpus)
        {
            var index = new DictionaryIndex <string>(rareWordThreshold: 3);

            IndexHelper.BuildIndex(index, corpus);
            return(index);
        }
        public void AssemblyRef_WhenConstructed_ValuesAreCorrect()
        {
            byte[] content =
            {
                0x04, 0x00,
                0x01, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x63, 0x03,
                0xD9, 0x03,
                0x00, 0x00,
                0x00, 0x00
            };
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2);

            AssemblyRefMetadataTableRow row = new AssemblyRefMetadataTableRow(content, 0, indexDetails);

            Assert.AreEqual("4.1.0.0", row.GetVersion().ToString());
            Assert.AreEqual(AssemblyFlags.SideBySideCompatible, row.Flags);
            Assert.AreEqual(867, row.PublicKeyOrToken);
            Assert.AreEqual(985, row.Name.Value);
            Assert.AreEqual(0, row.Culture.Value);
            Assert.AreEqual(0, row.HashValue);
        }
示例#27
0
        private static void Index()
        {
            IndexHelper indexHelper = new IndexHelper(Config.IndexFolder, Config.TextFilesFolder);

            indexHelper.CreateIndex(new PanGuAnalyzer());
            Console.WriteLine("索引完成!");
        }
示例#28
0
        public override void ContentChangedHandler(
            object sender,
            ContentChangedEventArgs e)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }

            Link link = (Link)sender;

            if (e.IsDeleted)
            {
                // get list of pages where this module is published
                List <PageModule> pageModules
                    = PageModule.GetPageModulesByModule(link.ModuleId);

                foreach (PageModule pageModule in pageModules)
                {
                    IndexHelper.RemoveIndexItem(
                        pageModule.PageId,
                        link.ModuleId,
                        link.ItemId);
                }
            }
            else
            {
                IndexItem(link);
            }
        }
示例#29
0
        public object GetData(int id, int page, string sortField, bool sortDescending, string searchQuery = null)
        {
            // NOTE: this is fine for now, but eventually make it should probably be configurable
            const int PerPage = 10;

            var document = ContentHelper.GetById(id);

            if (document == null)
            {
                return(null);
            }
            var model = ContentHelper.GetFormModel(document);

            if (model == null)
            {
                return(null);
            }

            var preValues         = ContentHelper.GetPreValues(document, FormModel.PropertyEditorAlias);
            var allFields         = GetAllFieldsForDisplay(model, document, preValues);
            var statisticsEnabled = ContentHelper.StatisticsEnabled(preValues);
            var approvalEnabled   = ContentHelper.ApprovalEnabled(preValues);

            var index         = IndexHelper.GetIndex(id);
            var fullTextIndex = index as IFullTextIndex;
            var result        = (fullTextIndex != null && string.IsNullOrWhiteSpace(searchQuery) == false
                                        ? fullTextIndex.Search(searchQuery, allFields.Select(f => f.FormSafeName).ToArray(), sortField, sortDescending, PerPage, (page - 1) * PerPage)
                                        : index.Get(searchQuery, null, sortField, sortDescending, PerPage, (page - 1) * PerPage)
                                 ) ?? Result.Empty(sortField, sortDescending);
            var totalPages = (int)Math.Ceiling((double)result.TotalRows / PerPage);

            // out of bounds request - e.g. right after removing some rows?
            if (page > totalPages && totalPages > 0)
            {
                // repeat the query but get the last page
                page   = totalPages;
                result = index.Get(searchQuery, null, sortField, sortDescending, PerPage, (page - 1) * PerPage);
            }

            var rows = model.ExtractSubmittedValues(result, allFields, (field, value, row) => field.FormatValueForDataView(value, document, row.Id));

            return(new
            {
                fields = allFields.Select(f => new { name = f.Name, sortName = f.FormSafeName }).ToArray(),
                rows = rows.Select(r => new
                {
                    _id = r.Id,
                    _createdDate = r.CreatedDate,
                    _approval = r.ApprovalState.ToString().ToLowerInvariant(),
                    values = r.Fields.Select(f => f.Value)
                }).ToArray(),
                currentPage = page,
                totalPages = totalPages,
                sortField = result.SortField,
                sortDescending = result.SortDescending,
                supportsSearch = fullTextIndex != null,
                supportsStatistics = statisticsEnabled && index is IStatisticsIndex && allFields.StatisticsFields().Any(),
                supportsApproval = approvalEnabled && index is IApprovalIndex
            });
        }
        public HttpResponseMessage DownloadFile(int id, Guid rowId, string fieldName)
        {
            var index = IndexHelper.GetIndex(id);
            var row   = index.Get(rowId);

            if (row == null || row.Fields.ContainsKey(fieldName) == false)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            var indexValue = row.Fields[fieldName];
            var fileData   = UploadField.ParseIndexValue(indexValue);

            if (fileData == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            var stream = index.GetFile(fileData.PersistedFilename);

            if (stream == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StreamContent(stream);
            response.Content.Headers.ContentType        = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = fileData.OriginalFilename
            };
            return(response);
        }
示例#31
0
        public JsonResult DeleteIndex(Guid indexId)
        {
            IndexHelper.DeleteIndex(indexId);
            AjaxResponse ajaxResponse = GetIndexAjaxResponse();

            return(Json(ajaxResponse));
        }
示例#32
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Create our Algolia client
            var algoliaClient = new AlgoliaClient("<APPLICATION_ID>", "<ADMIN_API_KEY>");

            // Create our index helper
            var indexHelper = new IndexHelper<Package>(algoliaClient, "packages", "Id");

            // Store our index helper in an application variable.
            // We don't want to create a new one each time
            // because it will impact performance.
            Application.Add("PackageIndexHelper", indexHelper);
        }
        public void TestSaveObjectObjectId()
        {
            ClearTest();
            _indexHelper = new IndexHelper<TestModel>(_client, GetSafeName("àlgol?à-csharp"), "TestModelId");

            var model = BuildTestModel();
            var task = _indexHelper.SaveObject(model);
            _indexHelper.WaitTask(task["taskID"].ToString());

            var res = _indexHelper.Search(new Query(""));

            Assert.AreEqual(1, res["nbHits"].ToObject<int>());
            Assert.AreEqual("Scott", res["hits"][0]["FirstName"].ToString());
            Assert.AreEqual("10", res["hits"][0]["objectID"].ToString());
        }
        public void TestDeleteObjectObjectId()
        {
            ClearTest();
            _indexHelper = new IndexHelper<TestModel>(_client, GetSafeName("àlgol?à-csharp"), "TestModelId");

            var model = BuildTestModel();
            var task = _indexHelper.SaveObject(model);
            _indexHelper.WaitTask(task["taskID"].ToString());

            var models = BuildTestModelList();
            var tasks = _indexHelper.SaveObjects(models);
            foreach (var item in tasks)
            {
                _indexHelper.WaitTask(item["taskID"].ToString());
            }

            var res = _indexHelper.Search(new Query(""));

            Assert.AreEqual(5, res["nbHits"].ToObject<int>());
            Assert.AreEqual("Sylvain", res["hits"][0]["FirstName"].ToString());
            Assert.AreEqual("8", res["hits"][0]["objectID"].ToString());

            task = _indexHelper.DeleteObject(model);
            _indexHelper.WaitTask(task["taskID"].ToString());

            res = _indexHelper.Search(new Query(""));

            Assert.AreEqual(4, res["nbHits"].ToObject<int>());
            Assert.AreEqual("Sylvain", res["hits"][0]["FirstName"].ToString());
            Assert.AreEqual("8", res["hits"][0]["objectID"].ToString());
        }