Beispiel #1
0
        //public bool UpdateLucene()
        //{
        //      //商品信息
        //    IList<ProductLuceneEntity> list = SearchDA.Instance.GetLuceneList();
        //    if (list.Count == 0)
        //    {
        //        return true;
        //    }
        //    Directory d = CreateDir(Table);
        //    //IndexWriter modifier = new IndexWriter(d, new PanGuAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
        //    IndexWriter modifier = new IndexWriter(d, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), false, IndexWriter.MaxFieldLength.LIMITED);

        //    foreach (ProductLuceneEntity m in list)
        //    {
        //        try
        //        {
        //            modifier.DeleteDocuments(new Term("StyleCode", m.StyleCode));
        //        }
        //        catch (Exception ex)
        //        {
        //            Core.LogUtil.Log("更新索引失败", m.StyleCode + " - " + ex.Message);
        //        }
        //    }

        //    foreach (GY_StyleLuceneEntity m in list)
        //    {
        //        try
        //        {
        //            //IsKit为ISWEBSALE的值
        //            if (m.IsWebSale == 1)
        //            {
        //                Document doc = GetDocumentObj(m);
        //                //写入索引文档
        //                modifier.AddDocument(doc);
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            Core.LogUtil.Log("更新索引失败", m.StyleCode + " + " + ex.Message);
        //        }
        //    }
        //    modifier.Optimize();
        //    modifier.Commit();
        //    modifier.Close();
        //    d.Close();

        //    data.DeleteLuceneStyle(list.Max(c => c.MaxId));
        //    return true;
        //}
        #endregion
        #region  创建文件夹
        Document GetDocumentObj(ProductLuceneEntity productinfo)
        {
            Document doc = new Document();

            doc.Add(new Field("ProductId", productinfo.ProductId.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("ProductDetailId", productinfo.ProductDetailId.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Code", productinfo.Code.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Title", productinfo.Title.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("AdTitle", productinfo.AdTitle.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Name", productinfo.Name.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("OECode", productinfo.OECode.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("StyleId", productinfo.StyleId.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("BrandId", productinfo.BrandId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("ClassId", productinfo.ClassId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("CGMemId", productinfo.CGMemId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("IsAhmTake", productinfo.IsAhmTake.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("JiShiSong", productinfo.JiShiSong.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            //doc.Add(new NumericField("Cost", Field.Store.YES, true).SetFloatValue(float.Parse(productinfo.Cost.ToString())));
            doc.Add(new Field("Num", productinfo.Num.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Spec1", productinfo.Spec1.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Spec2", productinfo.Spec2.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Spec3", productinfo.Spec3.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("PicSuffix", productinfo.PicSuffix.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("CarTypeRelated", productinfo.CarTypeRelated.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Status", productinfo.Status.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Retail", productinfo.Retail.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Wholesale", productinfo.Wholesale.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Sort", productinfo.Sort.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("PlaceOrigin", productinfo.PlaceOrigin.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Unit", productinfo.Unit.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("PackUnit", productinfo.PackUnit.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("IsOEM", productinfo.IsOEM.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("PackNum", productinfo.PackNum.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("PicUrl", productinfo.PicUrl.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("ListShowMethod", productinfo.ListShowMethod.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("SiteId", productinfo.SiteId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Price", productinfo.Price.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("TradePrice", productinfo.TradePrice.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("DealerPrice", productinfo.DealerPrice.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("IsBP", productinfo.IsBP.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("ProductType", productinfo.ProductType.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("SaleNum", productinfo.SaleNum.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("SpecModel", productinfo.SpecModel.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("Manufacturer", productinfo.Manufacturer.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("OEMPartNos", productinfo.OEMPartNos.ToString(), Field.Store.YES, Field.Index.NO));
            doc.Add(new Field("SpecPacking", productinfo.SpecPacking.ToString(), Field.Store.YES, Field.Index.NO));

            doc.Add(new Field("SearchFor", productinfo.SearchFor, Field.Store.NO, Field.Index.ANALYZED));

            return(doc);
        }
Beispiel #2
0
        void AppendList(IList <ProductLuceneEntity> list, Document doc, int startPost, string keywords)
        {
            ProductLuceneEntity model = new ProductLuceneEntity();

            model.PicUrl          = StringUtils.SafeStr(doc.GetField("PicUrl").StringValue);
            model.PicSuffix       = StringUtils.SafeStr(doc.GetField("PicSuffix").StringValue);
            model.Code            = StringUtils.SafeStr(doc.GetField("Code").StringValue);
            model.ProductId       = StringUtils.GetDbInt(doc.GetField("ProductId").StringValue);
            model.ProductDetailId = StringUtils.GetDbInt(doc.GetField("ProductDetailId").StringValue);
            model.ClassId         = StringUtils.GetDbInt(doc.GetField("ClassId").StringValue);
            model.BrandId         = StringUtils.GetDbInt(doc.GetField("BrandId").StringValue);
            model.AdTitle         = doc.GetField("AdTitle").StringValue;
            model.Spec1           = doc.GetField("Spec1").StringValue;
            model.Spec2           = doc.GetField("Spec2").StringValue;
            model.Price           = StringUtils.GetDbDecimal(doc.GetField("Price").StringValue);
            model.TradePrice      = StringUtils.GetDbDecimal(doc.GetField("TradePrice").StringValue);
            model.DealerPrice     = StringUtils.GetDbDecimal(doc.GetField("DealerPrice").StringValue);
            model.IsBP            = StringUtils.GetDbInt(doc.GetField("IsBP").StringValue);
            model.IsOEM           = StringUtils.GetDbInt(doc.GetField("IsOEM").StringValue);
            model.Manufacturer    = doc.GetField("Manufacturer").StringValue;
            if (keywords != "")
            {
                Lucene.Net.Analysis.Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
                QueryParser qp     = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "SearchFor", analyzer);
                Query       query1 = qp.Parse(keywords);



                //PanGu.HighLight.SimpleHTMLFormatter simpleHTMLFormatter = new PanGu.HighLight.SimpleHTMLFormatter("<font class=detailprice>", "</font>");
                //PanGu.HighLight.Highlighter highlighter = new PanGu.HighLight.Highlighter(simpleHTMLFormatter, new Segment());
                //highlighter.FragmentSize = 50;
                //model.HLStyleName = highlighter.GetBestFragment(keywords, Mola.Core.StringUtils.SafeStr(doc.GetField("StyleName").StringValue()));
            }
            //model.Cost =  StringUtils.SafeDecimal(doc.GetField("Cost").StringValue(), 0);
            //model.MarketPrice = StringUtils.SafeDecimal(doc.GetField("MarketPrice").StringValue(), 0);

            list.Add(model);
        }