示例#1
0
        public static List <Post> getClanciPretrage(string recenica)
        {
            if (recenica != "")
            {
                Directory   directoryPronadjeniClanci = Data.Lucene.Indexing.GetDirectoryClanci();
                Analyzer    analyzer    = new StandardAnalyzer(Version.LUCENE_30);
                IndexReader indexReader = IndexReader.Open(directoryPronadjeniClanci, true);
                Searcher    searcher    = new IndexSearcher(indexReader);

                //var queryParser = new QueryParser(Version.LUCENE_30, "Naslov", analyzer);
                var queryParser = new MultiFieldQueryParser(Version.LUCENE_30, new[] { "Naslov", "Sazetak", "Sadrzaj", "Tagovi" }, analyzer);
                var query       = queryParser.Parse(recenica.Trim()); // Rastavljanje rečenice na rijeci


                TopDocs     pronadjeno = searcher.Search(query, indexReader.MaxDoc);
                List <Post> postovi    = new List <Post>();
                var         hits       = pronadjeno.ScoreDocs;
                foreach (var hit in hits)
                {
                    var documentFromSearcher = searcher.Doc(hit.Doc);
                    using (TriglavBL temp = new TriglavBL())
                    {
                        postovi.Add(temp.getClanakByID(Convert.ToInt32(documentFromSearcher.Get("id"))));
                    }
                }


                searcher.Dispose();
                directoryPronadjeniClanci.Dispose();
                return(postovi);
            }
            else
            {
                return(null);
            }
        }