示例#1
0
        /// <summary>
        /// Directory Članci
        /// </summary>
        /// <param name="postVrstaId"></param>
        /// <returns></returns>            
        public static Directory GetDirectoryClanci()
        {
            using (TriglavBL temp = new TriglavBL())
            {

                Directory directoryClanci = FSDirectory.Open(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory +"Clanci"));
                Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);

                var writer = new IndexWriter(directoryClanci, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);

                List<Post> sviPostovi = temp.getAllClanci();
                foreach (var post in sviPostovi)
                {
                    //Add & boost
                    var clanak = new Document();
                    clanak.Add(new Field("id", Convert.ToString(post.id), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
                    clanak.Add(new Field("PostVrsta", Convert.ToString(post.PostVrsta), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("Naslov", post.Naslov, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                    clanak.GetField("Naslov").Boost = (2.0F);
                    clanak.Add(new Field("Sadrzaj", post.Sadrzaj, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                    clanak.GetField("Sadrzaj").Boost = (1.2F);
                    if (post.Sazetak != null)
                    {
                        clanak.Add(new Field("Sazetak", post.Sazetak, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                        clanak.GetField("Sazetak").Boost = (1.5F);
                    }
                    clanak.Add(new Field("Tagovi", post.Tagovi, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                    clanak.GetField("Tagovi").Boost = (2.5F);
                    clanak.Add(new Field("VlasnikId", Convert.ToString(post.VlasnikID), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("VlasnikNadimak", Convert.ToString(post.VlasnikNadimak), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                    clanak.Add(new Field("DatumKreiranja", Convert.ToString(post.DatumKreiranja), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("DatumZadnjeIzmjene", Convert.ToString(post.DatumZadnjeIzmjene), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("DatumZadnjeAktivnosti", Convert.ToString(post.DatumZadnjeAktivnosti), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("PrihvaceniOdgovori", Convert.ToString(post.PrihvaceniOdgovori), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("BrojOdgovora", Convert.ToString(post.BrojOdgovora), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("BrojKomentara", Convert.ToString(post.BrojKomentara), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("BrojOmiljenih", Convert.ToString(post.BrojOmiljenih), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("BrojPregleda", Convert.ToString(post.BrojPregleda), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("BrojPoena", Convert.ToString(post.BrojPoena), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("Likes", Convert.ToString(post.Likes), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("Unlikes", Convert.ToString(post.Unlikes), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("PromijenioID", Convert.ToString(post.PromijenioID), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("RoditeljskiPostID", Convert.ToString(post.RoditeljskiPostID), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("BrojRangiranja", Convert.ToString(post.BrojRangiranja), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("PrihvacenaIzmjena", Convert.ToString(post.PrihvacenaIzmjena), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
                    clanak.Add(new Field("Broj_Razgovora", Convert.ToString(post.Broj_Razgovora), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));

                    writer.AddDocument(clanak);
                }

                writer.Optimize();
                writer.Dispose();
                return directoryClanci;
            }
        }