Beispiel #1
0
        private void CreateIndex(Closet closet)
        {
#if !DEBUG
            //if (closet.Id == 144 || closet.Id == 30 || closet.Id == 11 || closet.Id == 2)
            //    return;

            //if (closet.Id != 144 && closet.Id != 30 && closet.Id != 11 && closet.Id != 2)
            //    return;
#endif
            using (SearchEngineService ses = SearchEngineService.GetByCloset(closet.Id))
            {
                int start = 0;
                int count = _closetOutfitRepository.GetCountByCloset(closet.Id);

                while (start < count)
                {
                    IList <SearchEngineEntry> lst = new List <SearchEngineEntry>();

                    IList <ClosetOutfit> lstOutfits = _closetOutfitRepository.GetByClosetPaged(closet.Id, start, Quantity);
                    if (lstOutfits == null)
                    {
                        break;
                    }

                    foreach (ClosetOutfit closetOutfit in lstOutfits)
                    {
                        SearchEngineEntry see = closetOutfit.ToSearchEngineEntry();
                        lst.Add(see);
                    }

                    ses.AddEntries(lst);

                    start += Quantity;
                    GC.Collect();
                }
            }

            NHibernateSession.Current.Clear();
            GC.Collect();
        }
Beispiel #2
0
 public IndexingError(SearchEngineEntry entry, Exception exception)
 {
     Entry     = entry;
     Exception = exception;
 }
        protected virtual Document CreateDocument(SearchEngineEntry post)
        {
            var doc = new Document();

            var field = new Field(Entryid,
                                  NumericUtils.IntToPrefixCoded(post.EntryId),
                                  Field.Store.YES,
                                  Field.Index.NOT_ANALYZED,
                                  Field.TermVector.NO);

            doc.Add(field);

            field = new Field(Categories, post.Categories, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.YES);
            doc.Add(field);

            field = new Field(Colors, post.Colors, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.YES);
            doc.Add(field);

            field = new Field(Silouhettes, post.Silouhettes, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.YES);
            doc.Add(field);

            field = new Field(Fabrics, post.Fabrics, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.YES);
            doc.Add(field);

            field = new Field(Seasons, post.Seasons, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.YES);
            doc.Add(field);

            field = new Field(EventTypes, post.EventTypes, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.YES);
            doc.Add(field);

            field = new Field(Tags, post.Tags, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.YES);
            doc.Add(field);

            field = new Field(Tags, (post.LastWornDate != null) ?
                              post.LastWornDate.Value.ToString("yyyyMMdd", CultureInfo.InvariantCulture)
                : string.Empty,
                              Field.Store.NO,
                              Field.Index.ANALYZED,
                              Field.TermVector.YES);
            doc.Add(field);

            // Boolean field just 1/0 on a text field
            field = new Field(CreatedByMe,
                              Convert.ToInt32(post.CreatedByMe).ToString(),
                              Field.Store.NO,
                              Field.Index.NOT_ANALYZED,
                              Field.TermVector.NO);
            doc.Add(field);

            field = new Field(IsUpToDate,
                              Convert.ToInt32(post.IsUpToDate).ToString(),
                              Field.Store.NO,
                              Field.Index.NOT_ANALYZED,
                              Field.TermVector.NO);
            doc.Add(field);

            NumericField fieldNumber = new NumericField(FlavorId).SetIntValue(post.FlavorId);

            doc.Add(fieldNumber);

            fieldNumber = new NumericField(MyRating).SetIntValue(post.MyRating);
            doc.Add(fieldNumber);

            fieldNumber = new NumericField(EditorRating).SetIntValue(post.EditorRating);
            doc.Add(fieldNumber);

            fieldNumber = new NumericField(FriendRating).SetIntValue(post.FriendRating);
            doc.Add(fieldNumber);

            return(doc);
        }
        public static SearchEngineEntry ToSearchEngineEntry(this ClosetOutfit closetOutfit)
        {
            SearchEngineEntry see = new SearchEngineEntry();

            see.EntryId = closetOutfit.Id;

            var categories  = new HashSet <string>();
            var colors      = new HashSet <string>();
            var silouhettes = new HashSet <string>();
            var eventtypes  = new HashSet <string>();
            var fabrics     = new HashSet <string>();
            var seasons     = new HashSet <string>();
            var keywords    = new HashSet <string>();

            foreach (Garment g in closetOutfit.Components)
            {
                categories.Add(g.Tags.Category.Description);
                colors.Add(g.Tags.DefaultColor.Description);
                silouhettes.Add(g.Tags.Silouhette.Description);
                fabrics.Add(g.Tags.Fabric.Description);

                if (!string.IsNullOrEmpty(g.Tags.Silouhette.Keywords))
                {
                    foreach (string keyword in g.Tags.Silouhette.Keywords.Split(','))
                    {
                        keywords.Add(keyword.Trim());
                    }
                }

                foreach (EventType ev in g.Tags.EventTypes)
                {
                    eventtypes.Add(ev.ShortName);
                }

                foreach (Season s in g.Tags.Seasons)
                {
                    seasons.Add(s.ToString());
                }
            }

            see.CreatedByMe  = closetOutfit.User != null;
            see.EditorRating = Convert.ToInt32(closetOutfit.Rating.EditorRating);
            see.FriendRating = Convert.ToInt32(Math.Round(closetOutfit.Rating.FriendRatingAverage));
            see.MyRating     = Convert.ToInt32(closetOutfit.Rating.MyRating);
            see.FlavorId     = closetOutfit.FashionFlavor.Id;

            if (closetOutfit.Detail != null)
            {
                // Mark as up to date, save last worndate and add all locations to the keywords.
                see.IsUpToDate   = true;
                see.LastWornDate = closetOutfit.Detail.WornDate;
                foreach (OutfitDetails od in closetOutfit.Details)
                {
                    keywords.Add(od.Location);
                }
            }

            see.Categories  = string.Join(" ", categories.ToArray());
            see.Silouhettes = string.Join(" ", silouhettes.ToArray());
            see.Colors      = string.Join(" ", colors.ToArray());
            see.EventTypes  = string.Join(" ", eventtypes.ToArray());
            see.Fabrics     = string.Join(" ", fabrics.ToArray());
            see.Seasons     = string.Join(" ", seasons.ToArray());
            see.Tags        = string.Join(" ", keywords.ToArray());

            return(see);
        }
 public IEnumerable <IndexingError> AddEntry(SearchEngineEntry post)
 {
     return(AddEntries(new[] { post }, false));
 }