public void Search_JoinQuery() { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogNodeDto nodes = system.GetCatalogNodesDto(catalogName); foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode) { CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = true; pars.CatalogNames.Add(catalogName); pars.CatalogNodes.Add(node.Code); pars.JoinType = "inner join"; pars.Language = "en-us"; pars.JoinSourceTable = "CatalogEntry"; pars.JoinTargetQuery = "(select distinct ObjectId, DisplayName from CatalogEntryEx) CatalogEntryEx"; pars.JoinSourceTableKey = "CatalogEntryId"; pars.JoinTargetTableKey = "CatalogEntryEx.ObjectId"; pars.OrderByClause = "CatalogEntryEx.DisplayName"; Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); } } }
/// <summary> /// Gets the total records. /// </summary> /// <returns></returns> private int GetTotalRecords() { int numRecords = 0; ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = false; pars.CatalogNames.Add(catalogName); options.RecordsToRetrieve = 1; options.StartingRecord = 0; int totalCount = 0; CatalogEntryDto entryDto = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount); numRecords += totalCount; } return(numRecords); }
public void Search_BrowseEntries() { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogNodeDto nodes = system.GetCatalogNodesDto(catalogName); foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode) { CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = true; pars.CatalogNames.Add(catalogName); pars.CatalogNodes.Add(node.Code); Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); } } }
public void CatalogSystem_UnitTest_SearchEntries() { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); // Search phrase arbitrary pars.FreeTextSearchPhrase = "policy"; // Set language pars.Language = "en-us"; pars.CatalogNames.Add(catalogName); Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); // Meaningless assert - to be replaced with appropriate assert once the problem with search is figured out Assert.IsTrue(entries.TotalResults == entries.TotalResults); Console.WriteLine("Number of entries matching \"{0}\" in the {1} catalog: {2}", pars.FreeTextSearchPhrase, catalogName, entries.TotalResults); } //Assert.Inconclusive("Verify the correctness of this test method."); }
protected void PrimeCacheImpl() { ICatalogSystem catalog = ServiceLocator.Current.GetInstance <ICatalogSystem>(); IContentRepository repository = ServiceLocator.Current.GetInstance <IContentRepository>(); ReferenceConverter referenceConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>(); CatalogContentLoader contentLoader = ServiceLocator.Current.GetInstance <CatalogContentLoader>(); // Get all catalogs CatalogDto catalogDto = catalog.GetCatalogDto(); _log.Debug("Found {0} catalogs. Start iterating.", catalogDto.Catalog.Count); foreach (CatalogDto.CatalogRow catalogRow in catalogDto.Catalog) { _log.Debug("Loading all categories for catalog {0} ({1})", catalogRow.Name, catalogRow.CatalogId); // Get all Categories on first level CatalogNodes nodes = catalog.GetCatalogNodes(catalogRow.CatalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo)); _log.Debug("Loaded {0} categories using ICatalogSystem", nodes.CatalogNode.Count()); // Get them as content too foreach (CatalogNode node in nodes.CatalogNode) { ContentReference nodeReference = referenceConverter.GetContentLink(node.CatalogNodeId, CatalogContentType.CatalogNode, 0); NodeContent content = repository.Get <EPiServer.Commerce.Catalog.ContentTypes.NodeContent>(nodeReference); _log.Debug("Loded Category Content: {0}", content.Name); WalkCategoryTree(content, repository, contentLoader, catalog, referenceConverter); } } }
protected IEnumerable <int> GetCatalogIds() { ICatalogSystem catalogSystem = ServiceLocator.Current.GetInstance <ICatalogSystem>(); CatalogDto catalogDto = catalogSystem.GetCatalogDto(); foreach (CatalogDto.CatalogRow row in catalogDto.Catalog) { yield return(row.CatalogId); } }
public void Search_Lucene_WithinCatalogsWithSorting() { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); // Create Entry Criteria CatalogEntrySearchCriteria criteria = new CatalogEntrySearchCriteria(); // Bind default catalogs if none found if (criteria.CatalogNames.Count == 0) { if (catalogs.Catalog.Count > 0) { foreach (CatalogDto.CatalogRow row in catalogs.Catalog) { if (row.IsActive && row.StartDate <= FrameworkContext.Current.CurrentDateTime && row.EndDate >= FrameworkContext.Current.CurrentDateTime) { criteria.CatalogNames.Add(row.Name); } } } } // Define phrase we want to search criteria.SearchPhrase = "canon"; // Create a manager SearchManager manager = new SearchManager(AppContext.Current.ApplicationName); SearchResults results = null; // Define sort parameter criteria.Sort = new SearchSort("DisplayName"); // Perform search results = manager.Search(criteria); Assert.IsTrue(results.TotalCount > 0, "No hits were found in Lucene index."); // Get IDs we need int[] resultIndexes = results.GetIntResults(0, 10 + 5); // we add padding here to accomodate entries that might have been deleted since last indexing // Retrieve actual entry objects, with no caching Entries entries = CatalogContext.Current.GetCatalogEntries(resultIndexes, false, new TimeSpan(), new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); entries.TotalResults = results.TotalCount; Assert.IsTrue(entries.TotalResults > 0, "No entries were returned from the database."); }
protected void WalkCatalog(ICatalogSystem catalogSystem, Dictionary <int, CatalogEntryDto.CatalogEntryRow> catalogEntryRows) { // Get all catalogs CatalogDto catalogs = catalogSystem.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { // string catalogName = catalog.Name; int catalogId = catalog.CatalogId; // Get Catalog Nodes CatalogNodeDto nodes = catalogSystem.GetCatalogNodesDto(catalogId); WalkCatalogNodes(catalogSystem, nodes, catalog, catalogEntryRows); } }
public void CatalogSystem_UnitTest_BrowseEntries() { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); // Number of entries in CatalogEntry table int entryCount = 0; foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogNodeDto nodes = system.GetCatalogNodesDto(catalogName); foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode) { CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = true; pars.Language = "en-us"; pars.CatalogNames.Add(catalogName); pars.CatalogNodes.Add(node.Code); // Test does not seem to be working: entries are mostly returning empty. Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); try { foreach (Entry entry in entries.Entry) { // Something to do? Just looking at entries entryCount++; } } catch (Exception e) { Assert.IsFalse(new NullReferenceException().Equals(e)); } } } // As of testing 4/19/09, entryCount incremented 22 times (there are over 1300 entries in the table CatalogEntry) Console.WriteLine("Number of entries browsed: {0:d}", entryCount); Assert.Inconclusive("Verify the correctness of this test method."); }
private PromotionEntry CreatePromotionEntry(EntryContentBase entry, IPriceValue price) { var catalogNodes = string.Empty; var catalogs = string.Empty; foreach (var node in entry.GetNodeRelations(_linksRepository).Select(x => _contentLoader.Get <NodeContent>(x.Target))) { var entryCatalogName = _catalogSystem.GetCatalogDto(node.CatalogId).Catalog[0].Name; catalogs = string.IsNullOrEmpty(catalogs) ? entryCatalogName : catalogs + ";" + entryCatalogName; catalogNodes = string.IsNullOrEmpty(catalogNodes) ? node.Code : catalogNodes + ";" + node.Code; } var promotionEntry = new PromotionEntry(catalogs, catalogNodes, entry.Code, price.UnitPrice.Amount); Populate(promotionEntry, entry, price); return(promotionEntry); }
public ActionResult Index(StartPage currentPage) { //get catalog list ICatalogSystem target = CatalogContext.Current; CatalogDto catalogs = target.GetCatalogDto(); List <MyNodeVM> listCatelog = new List <MyNodeVM>(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { listCatelog.Add(new MyNodeVM() { CatalogName = catalog.Name }); } currentPage.Catelogs = listCatelog; return(View(currentPage)); }
public void Search_AdvancedFTS() { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); pars.AdvancedFreeTextSearchPhrase = "(\"sweet and savory\" NEAR sauces) OR (\"sweet and savory\" NEAR candies)"; pars.CatalogNames.Add(catalogName); Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); } }
public ClearCatalogAndModelsResult ClearCatalogAndModels() { List <string> logList = new List <string>(); ClearCatalogAndModelsResult result = new ClearCatalogAndModelsResult(); ICatalogSystem catalogSystem = ServiceLocator.Current.GetInstance <ICatalogSystem>(); CatalogDto catalogDto = catalogSystem.GetCatalogDto(); foreach (CatalogDto.CatalogRow row in catalogDto.Catalog) { _log.Debug("Deleting catalog: " + row.Name); try { CatalogContext.Current.DeleteCatalog(row.CatalogId); result.CatalogsDeleted++; } catch (Exception e) { result.CatalogsFailed++; _log.Error("Failed to delete catalog: " + row.Name, e); } } DeleteAllMetaClasses(true, result); // Remove all imported inRiver Resources _log.Debug("Deleting inRiver Media Folder"); DeleteFileFolder("inRiver", result); // Cache is invalid now, clear it _log.Debug("Clearing Cache"); ClearCache(); _log.Debug("Syncing Content Type Models"); return(result); }
/// <summary> /// Indexes the catalog. /// </summary> private static void IndexCatalog(string indexType) { ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; Console.WriteLine(String.Format("Indexing {0} catalog ...", catalogName)); int currentRecord = 0; int totalIndexed = 0; int currentRecordIndex = 0; int origRow = Console.CursorTop; int origCol = Console.CursorLeft; int overallTotalCount = 0; while (true) { // Get Catalog Nodes CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = false; pars.CatalogNames.Add(catalogName); options.RecordsToRetrieve = 500; options.StartingRecord = currentRecord; if (!indexType.Equals("all", StringComparison.OrdinalIgnoreCase)) { pars.SqlWhereClause = "SerializedData is null"; } int totalCount = 0; CatalogEntryDto entryDto = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (!indexType.Equals("all", StringComparison.OrdinalIgnoreCase)) { currentRecord = 0; if (overallTotalCount == 0) { overallTotalCount = totalCount; } } else { if (currentRecord == 0) { overallTotalCount = totalCount; } currentRecord += options.RecordsToRetrieve; } List <string> languages = new List <string>(); languages.Add(catalog.DefaultLanguage); foreach (CatalogDto.CatalogLanguageRow row in catalog.GetCatalogLanguageRows()) { languages.Add(row.LanguageCode); } int currentBatchCount = 0; foreach (CatalogEntryDto.CatalogEntryRow row in entryDto.CatalogEntry) { Console.SetCursorPosition(origCol, origRow); Console.WriteLine(String.Format("Indexing {0}/{1} record ", currentRecordIndex + 1, overallTotalCount)); currentBatchCount += IndexCatalogEntryDto(row, languages.ToArray()); totalIndexed += currentBatchCount; currentRecordIndex++; } Console.SetCursorPosition(origCol, origRow); Console.WriteLine(String.Format("Saving {0}-{1}/{2} records ", currentRecordIndex - currentBatchCount + 1, currentRecordIndex, overallTotalCount)); system.SaveCatalogEntry(entryDto); // Break the loop if we retrieved all the record if (currentRecord > overallTotalCount || totalCount <= 0) { break; } } Console.WriteLine(String.Format("Successfully indexed {0} language records in {1} catalog", totalIndexed.ToString(), catalogName)); } }
public CatalogDto.CatalogDataTable GetCatalogs() { return(_catalogSystem.GetCatalogDto().Catalog); }
/// <summary> /// Builds the index. /// </summary> /// <param name="rebuild">if set to <c>true</c> [rebuild].</param> public override void BuildIndex(bool rebuild) { OnEvent(String.Format("CatalogIndexBuilder Started"), 0); IndexBuilder indexer = this.Indexer; DateTime lastBuild = DateTime.MinValue; // Parameters used to restart build from the previous error //string restartCatalogName = String.Empty; //int restartRecordKey = 0; // On complete rebuild no need to check date if (!rebuild) { lastBuild = indexer.GetBuildConfig().LastBuildDate; } ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); double percentage = 0; bool incremental = false; int allRecords = 0; int allCurrentRecord = 0; int allRecordsCount = GetTotalRecords(); int catalogCount = 1; // If date is set, we do incremental rebuild if (lastBuild != DateTime.MinValue) { incremental = true; } // remove deleted items first if (incremental) { int startingRecord = 0; int totalRemoved = 0; while (true) { int count = 0; LogDto dto = LogManager.GetAppLog("catalog", DataRowState.Deleted.ToString(), "entry", lastBuild.ToUniversalTime(), startingRecord, 100, ref count); // add up to a total number to calculate percentage correctly if (startingRecord == 0) { allRecordsCount += count; } if (count <= 0) { break; } foreach (LogDto.ApplicationLogRow row in dto.ApplicationLog) { allCurrentRecord++; if (allCurrentRecord % 20 == 0) { percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; OnEvent(String.Format("Removing old entry from index ({1}/{2}) ...", allCurrentRecord, count), percentage); } totalRemoved += indexer.DeleteContent("_id", row.ObjectKey); } startingRecord += 100; } percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; OnEvent(String.Format("CatalogIndexBuilder Removed {0} records.", totalRemoved), percentage); } // Index new or updated items foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; string defaultCurrency = catalog.DefaultCurrency; OnEvent(String.Format("Indexing {0} catalog ...", catalogName), percentage); int currentRecord = 0; int startingRecord = 0; int totalIndexed = 0; int lastRecordKey = 0; catalogCount++; while (true) { // Get Catalog Nodes CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = false; pars.CatalogNames.Add(catalogName); options.RecordsToRetrieve = 100; options.StartingRecord = startingRecord; if (incremental) { pars.SqlMetaWhereClause = String.Format("META.Modified > '{0}'", lastBuild.ToUniversalTime().ToString("s")); } int count = 0; CatalogEntryDto entryDto = CatalogContext.Current.FindItemsDto(pars, options, ref count, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (count <= 0) { break; } startingRecord += options.RecordsToRetrieve; List <string> languages = new List <string>(); languages.Add(catalog.DefaultLanguage); foreach (CatalogDto.CatalogLanguageRow row in catalog.GetCatalogLanguageRows()) { languages.Add(row.LanguageCode); } foreach (CatalogEntryDto.CatalogEntryRow row in entryDto.CatalogEntry) { currentRecord++; allCurrentRecord++; // Do not index non active entries if (!row.IsActive) { continue; } // In case of incremental, check if item already exists and delete it if (incremental) { indexer.DeleteContent("_id", row.CatalogEntryId.ToString()); } try { lastRecordKey = row.CatalogEntryId; totalIndexed += IndexCatalogEntryDto(indexer, row, defaultCurrency, languages.ToArray()); } catch (Exception) { percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; OnEvent(String.Format("Failed to index catalog entry {0}({1}) in {2}.", row.Name, row.CatalogEntryId, catalogName), percentage); throw; } if (allCurrentRecord % 20 == 0) { percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; OnEvent(String.Format("Indexing {0} catalog entries ({1}/{2}) ...", catalogName, allCurrentRecord, allRecordsCount), percentage); } } // Save index every 500 records if (allCurrentRecord % 500 == 0) { percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; OnEvent(String.Format("Saving {0} catalog index file.", catalogName), percentage); Build config = indexer.GetBuildConfig(); // Preserve the information needed to restart the indexing on the exact same location as before BuildProperty prop1 = new BuildProperty(); prop1.name = "StartingRecord"; prop1.value = startingRecord.ToString(); BuildProperty prop2 = new BuildProperty(); prop2.name = "LastRecordKey"; prop2.value = lastRecordKey.ToString(); BuildProperty prop3 = new BuildProperty(); prop3.name = "CatalogName"; prop3.value = catalogName; config.Properties = new BuildProperty[] { prop1, prop2, prop3 }; indexer.SaveBuild(Status.Started); indexer.Close(); } if (startingRecord > count) { break; } } percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100; catalogCount++; allRecords += totalIndexed; } OnEvent(String.Format("CatalogIndexBuilder Indexed {0} language records in {1} catalog(s)", allRecords.ToString(), (catalogCount - 1).ToString()), 99); OnEvent(String.Format("CatalogIndexBuilder Finished"), 100); }
/// <summary> /// Gets the catalog dto. /// </summary> /// <param name="siteId">The site id.</param> /// <param name="responseGroup">The response group.</param> /// <returns></returns> public CatalogDto GetCatalogDto(Guid siteId, CatalogResponseGroup responseGroup) { return(_Proxy.GetCatalogDto(siteId, responseGroup)); }