Esempio n. 1
0
        private void FlushText(RTF rtf, bool newline)
        {
            var length = _line.Length;

            if (!newline && (length == 0))
            {
                document.Add(null, null, 0, newline);
                return;
            }

            if (_style.FontName == null)
            {
                // First font in table is default
                _style.FontName = global::Limaki.Common.Text.RTF.Parser.Font.GetFont(rtf, 0).Name;
            }

            var font = XD.Font.FromName(_style.FontName + " " + _style.FontSize.ToString());

            if (_style.Color == XD.Colors.Black)
            {
                // First color in table is default
                var color = Color.GetColor(rtf, 0);

                if ((color == null) || (color.Red == -1 && color.Green == -1 && color.Blue == -1))
                {
                    _style.Color = SystemColors.WindowText;
                }
                else
                {
                    _style.Color = XD.Color.FromBytes((byte)color.Red, (byte)color.Green, (byte)color.Blue);
                }
            }

            _charCount += _line.Length;

            document.Add(_line.ToString(), _style, _cursorX, newline);

            if (newline)
            {
                _cursorX = 0;
                _cursorY++;
            }
            else
            {
                _cursorX += length;
            }
            _line.Length = 0;   // Empty line
        }
Esempio n. 2
0
        protected virtual void IndexItemPrices(IDocument document, IList <Price> prices, CatalogProduct item)
        {
            if (prices != null)
            {
                foreach (var price in prices)
                {
                    document.Add(new DocumentField(string.Format(CultureInfo.InvariantCulture, "price_{0}_{1}", price.Currency, price.PricelistId).ToLowerInvariant(), price.EffectiveValue, new[] { IndexStore.No, IndexType.NotAnalyzed }));

                    // now save additional pricing fields for convinient user searches, store price with currency and without one
                    document.Add(new DocumentField(string.Format(CultureInfo.InvariantCulture, "price_{0}", price.Currency), price.EffectiveValue, new[] { IndexStore.No, IndexType.NotAnalyzed }));
                    document.Add(new DocumentField("price", price.EffectiveValue, new[] { IndexStore.No, IndexType.NotAnalyzed }));
                }
            }

            IndexIsProperty(document, prices?.Count > 0 ? "priced" : "unpriced");
        }
Esempio n. 3
0
        protected virtual void IndexItemCustomProperties(IDocument document, CatalogProduct item)
        {
            var properties = item.Properties;

            foreach (var propValue in item.PropertyValues.Where(x => x.Value != null))
            {
                var propertyName     = (propValue.PropertyName ?? "").ToLowerInvariant();
                var property         = properties.FirstOrDefault(x => string.Equals(x.Name, propValue.PropertyName, StringComparison.InvariantCultureIgnoreCase) && x.ValueType == propValue.ValueType);
                var contentField     = string.Concat("__content", property != null && property.Multilanguage && !string.IsNullOrWhiteSpace(propValue.LanguageCode) ? "_" + propValue.LanguageCode.ToLowerInvariant() : string.Empty);
                var stringCollection = property?.Multivalue == true ? IndexDataType.StringCollection : string.Empty;

                switch (propValue.ValueType)
                {
                case PropertyValueType.LongText:
                case PropertyValueType.ShortText:
                    var stringValue = propValue.Value.ToString();

                    if (!string.IsNullOrWhiteSpace(stringValue))     // don't index empty values
                    {
                        document.Add(new DocumentField(contentField, stringValue.ToLower(), new[] { IndexStore.Yes, IndexType.Analyzed, IndexDataType.StringCollection }));
                    }

                    break;
                }

                switch (propValue.ValueType)
                {
                case PropertyValueType.Boolean:
                case PropertyValueType.DateTime:
                case PropertyValueType.Number:
                    document.Add(new DocumentField(propertyName, propValue.Value, new[] { IndexStore.Yes, IndexType.Analyzed }));
                    break;

                case PropertyValueType.LongText:
                    document.Add(new DocumentField(propertyName, propValue.Value.ToString().ToLowerInvariant(), new[] { IndexStore.Yes, IndexType.Analyzed, stringCollection }));
                    break;

                case PropertyValueType.ShortText:     // do not tokenize small values as they will be used for lookups and filters
                    document.Add(new DocumentField(propertyName, propValue.Value.ToString(), new[] { IndexStore.Yes, IndexType.NotAnalyzed, stringCollection }));
                    break;
                }
            }
        }
        /// <summary>
        /// Returns a new Document with the same meta-data as <tt>in</tt> and the same words
        /// except those on the stop list this filter was constructed with.
        /// </summary>
        public virtual IDocument <L, F, Word> ProcessDocument(IDocument <L, F, Word> @in)
        {
            IDocument <L, F, Word> @out = @in.BlankDocument();

            foreach (Word w in @in)
            {
                if (!stoplist.Contains(w))
                {
                    @out.Add(w);
                }
            }
            return(@out);
        }
 /// <summary>
 /// is:hidden, property can be used to provide user friendly way of searching products
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="value"></param>
 protected virtual void IndexIsProperty(IDocument doc, string value)
 {
     doc.Add(new DocumentField("is", value, new[] { IndexStore.No, IndexType.NotAnalyzed }));
 }
        public virtual bool UpdateDocument(IDocument document, Category item, object context)
        {
            var indexStoreNotAnalyzed = new[] { IndexStore.Yes, IndexType.NotAnalyzed };
            var indexStoreNotAnalyzedStringCollection = new[] { IndexStore.Yes, IndexType.NotAnalyzed, IndexDataType.StringCollection };
            var indexStoreAnalyzedStringCollection    = new[] { IndexStore.Yes, IndexType.Analyzed, IndexDataType.StringCollection };

            document.Add(new DocumentField("__key", item.Id.ToLowerInvariant(), indexStoreNotAnalyzed));
            document.Add(new DocumentField("__type", item.GetType().Name, indexStoreNotAnalyzed));
            document.Add(new DocumentField("__sort", item.Name, indexStoreNotAnalyzed));
            IndexIsProperty(document, "category");
            var statusField = (item.IsActive != true || item.Id != null) ? "hidden" : "visible";

            IndexIsProperty(document, statusField);
            document.Add(new DocumentField("status", statusField, indexStoreNotAnalyzed));
            document.Add(new DocumentField("code", item.Code, indexStoreNotAnalyzed));
            IndexIsProperty(document, item.Code);
            document.Add(new DocumentField("name", item.Name, indexStoreNotAnalyzed));
            document.Add(new DocumentField("createddate", item.CreatedDate, indexStoreNotAnalyzed));
            document.Add(new DocumentField("lastmodifieddate", item.ModifiedDate ?? DateTime.MaxValue, indexStoreNotAnalyzed));
            document.Add(new DocumentField("priority", item.Priority, indexStoreNotAnalyzed));
            document.Add(new DocumentField("lastindexdate", DateTime.UtcNow, indexStoreNotAnalyzed));

            // Add priority in virtual categories to search index
            foreach (var link in item.Links)
            {
                document.Add(new DocumentField(string.Format(CultureInfo.InvariantCulture, "priority_{0}_{1}", link.CatalogId, link.CategoryId), link.Priority, indexStoreNotAnalyzed));
            }

            // Add catalogs to search index
            var catalogs = item.Outlines
                           .Select(o => o.Items.First().Id)
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToArray();

            foreach (var catalogId in catalogs)
            {
                document.Add(new DocumentField("catalog", catalogId.ToLowerInvariant(), indexStoreNotAnalyzedStringCollection));
            }

            // Add outlines to search index
            var outlineStrings = GetOutlineStrings(item.Outlines);

            foreach (var outline in outlineStrings)
            {
                document.Add(new DocumentField("__outline", outline.ToLowerInvariant(), indexStoreNotAnalyzedStringCollection));
            }

            // Index custom properties
            IndexItemCustomProperties(document, item);

            // add to content
            document.Add(new DocumentField("__content", item.Name, indexStoreAnalyzedStringCollection));
            document.Add(new DocumentField("__content", item.Code, indexStoreAnalyzedStringCollection));

            if (_settingsManager.GetValue("VirtoCommerce.SearchApi.UseFullObjectIndexStoring", true))
            {
                var itemDto = item.ToWebModel(_blobUrlResolver);
                document.AddObjectFieldValue(itemDto);
            }

            return(true);
        }
Esempio n. 7
0
 public static void AddObjectFieldValue <T>(this IDocument document, T value)
 {
     document.Add(new DocumentField(ObjectFieldName, SerializeObject(value), new[] { IndexStore.Yes, IndexType.No }));
 }
Esempio n. 8
0
 /// <summary>
 /// is:hidden, property can be used to provide user friendly way of searching products
 /// </summary>
 /// <param name="document"></param>
 /// <param name="value"></param>
 protected virtual void IndexIsProperty(IDocument document, string value)
 {
     document.Add(new DocumentField("is", value, new[] { IndexStore.No, IndexType.NotAnalyzed, IndexDataType.StringCollection }));
 }