Esempio n. 1
0
        /// <summary>
        /// Indexes the catalog entry dto.
        /// </summary>
        /// <param name="indexer">The indexer.</param>
        /// <param name="account">The account.</param>
        /// <returns></returns>
        private int IndexAccount(IndexBuilder indexer, Account account)
        {
            int      indexCounter = 0;
            Document doc          = new Document();

            // Add constant fields
            doc.Add(new Field("_id", account.PrincipalId.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
            doc.Add(new Field("_providerkey", account.ProviderKey, Field.Store.YES, Field.Index.UN_TOKENIZED));
            doc.Add(new Field("_type", account.Type, Field.Store.YES, Field.Index.UN_TOKENIZED));
            doc.Add(new Field("_metaclass", account.MetaClass.Name, Field.Store.YES, Field.Index.UN_TOKENIZED));

            foreach (MetaField field in account.MetaClass.MetaFields)
            {
                AddField(doc, field, account.GetValues());
            }

            CustomerAddressCollection addresses = account.Addresses;

            if (addresses != null)
            {
                foreach (CustomerAddress address in addresses)
                {
                    foreach (MetaField field in address.MetaClass.MetaFields)
                    {
                        AddField(doc, field, account.GetValues());
                    }
                }
            }

            indexer.AddDocument(doc);

            indexCounter++;

            return(indexCounter);
        }
Esempio n. 2
0
        /// <summary>
        /// Indexes the catalog entry dto.
        /// </summary>
        /// <param name="indexer">The indexer.</param>
        /// <param name="entryRow">The entry row.</param>
        /// <param name="defaultCurrency">The default currency.</param>
        /// <param name="languages">The languages.</param>
        /// <returns></returns>
        private int IndexCatalogEntryDto(IndexBuilder indexer, CatalogEntryDto.CatalogEntryRow entryRow, string defaultCurrency, string[] languages)
        {
            int indexCounter = 0;

            CatalogContext.MetaDataContext.UseCurrentUICulture = false;

            // Import categories
            CatalogRelationDto relationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, entryRow.CatalogEntryId, "", new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));

            foreach (string language in languages)
            {
                Document doc = new Document();

                // Add constant fields
                doc.Add(new Field("_id", entryRow.CatalogEntryId.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("Code", entryRow.Code, Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("_content", entryRow.Code, Field.Store.NO, Field.Index.TOKENIZED));
                doc.Add(new Field("Name", entryRow.Name, Field.Store.YES, Field.Index.TOKENIZED));
                doc.Add(new Field("_content", entryRow.Name, Field.Store.NO, Field.Index.TOKENIZED));
                doc.Add(new Field("_lang", language, Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("StartDate", entryRow.StartDate.ToString("s"), Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("EndDate", entryRow.EndDate.ToString("s"), Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("_classtype", entryRow.ClassTypeId, Field.Store.YES, Field.Index.UN_TOKENIZED));
                AddPriceFields(doc, entryRow, defaultCurrency);

                bool sortOrderAdded = false;
                foreach (CatalogRelationDto.NodeEntryRelationRow relation in relationDto.NodeEntryRelation)
                {
                    CatalogDto catalogDto  = CatalogContext.Current.GetCatalogDto(relation.CatalogId);
                    string     catalogName = String.Empty;
                    if (catalogDto != null && catalogDto.Catalog != null && catalogDto.Catalog.Count > 0)
                    {
                        catalogName = catalogDto.Catalog[0].Name;
                    }
                    else
                    {
                        continue;
                    }

                    CatalogNodeDto catalogNodeDto  = CatalogContext.Current.GetCatalogNodeDto(relation.CatalogNodeId);
                    string         catalogNodeCode = String.Empty;
                    if (catalogNodeDto != null && catalogNodeDto.CatalogNode != null && catalogNodeDto.CatalogNode.Count > 0)
                    {
                        catalogNodeCode = catalogNodeDto.CatalogNode[0].Code;
                    }
                    else
                    {
                        continue;
                    }

                    BuildPath(doc, catalogDto, catalogNodeDto, 0);

                    /*
                     * BuildPath(doc, entryRow.CatalogId, relation.CatalogNodeId);
                     * string path = BuildPath(entryRow.CatalogId, relation.CatalogNodeId);
                     * doc.Add(new Field(String.Format("_outline"), path, Field.Store.YES, Field.Index.UN_TOKENIZED));
                     * */
                    doc.Add(new Field(String.Format("_sortorder-{0}-{1}", catalogName, catalogNodeCode), relation.SortOrder.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
                    if (!sortOrderAdded && entryRow.CatalogId == relation.CatalogId) // add default sort order, which will be the first node added in the default catalog
                    {
                        doc.Add(new Field(String.Format("_sortorder"), relation.SortOrder.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
                        sortOrderAdded = true;
                    }
                }

                CatalogContext.MetaDataContext.Language = language;

                if (entryRow.MetaClassId != 0)
                {
                    // load list of MetaFields for MetaClass
                    MetaClass metaClass = MetaHelper.LoadMetaClassCached(CatalogContext.MetaDataContext, entryRow.MetaClassId);

                    if (metaClass != null)
                    {
                        MetaFieldCollection mfs = metaClass.MetaFields;
                        if (mfs != null)
                        {
                            //MetaObject metaObj = null;
                            //metaObj = MetaObject.Load(CatalogContext.MetaDataContext, entryRow.CatalogEntryId, entryRow.MetaClassId);

                            Hashtable hash = ObjectHelper.GetMetaFieldValues(entryRow);

                            if (hash != null)
                            {
                                foreach (MetaField field in mfs)
                                {
                                    AddField(doc, field, hash);
                                }
                            }
                        }
                    }

                    doc.Add(new Field("_metaclass", metaClass.Name, Field.Store.YES, Field.Index.UN_TOKENIZED));
                }
                indexer.AddDocument(doc);

                indexCounter++;
            }

            CatalogContext.MetaDataContext.UseCurrentUICulture = true;
            return(indexCounter);
        }