public static List<Post> getPitanjaPretrage(string recenica) { if (recenica != "") { Directory directoryPronadjenaPitanja = Data.Lucene.Indexing.GetDirectoryPitanja(); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30); IndexReader indexReader = IndexReader.Open(directoryPronadjenaPitanja, true); Searcher searcher = new IndexSearcher(indexReader); //var queryParser = new QueryParser(Version.LUCENE_30, "Naslov", analyzer); var queryParser = new MultiFieldQueryParser(Version.LUCENE_30, new[] { "Naslov", "Sadrzaj", "Tagovi" }, analyzer); var query = queryParser.Parse(recenica.Trim()); // Rastavljanje rečenice na rijeci TopDocs pronadjeno = searcher.Search(query, indexReader.MaxDoc); List<Post> pitanja = new List<Post>(); var hits = pronadjeno.ScoreDocs; foreach (var hit in hits) { var documentFromSearcher = searcher.Doc(hit.Doc); using (TriglavBL temp = new TriglavBL()) { pitanja.Add(temp.getPitanjeByID(Convert.ToInt32(documentFromSearcher.Get("id")))); } } searcher.Dispose(); directoryPronadjenaPitanja.Dispose(); return pitanja; } else return null; }
public static List<Post> getPitanjaByTag(int TAGID) { Directory directoryPronadjenaPitanjaTagovi = Data.Lucene.Indexing.GetDirectoryPitanjaTagovi(); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30); IndexReader indexReader = IndexReader.Open(directoryPronadjenaPitanjaTagovi, true); Searcher searcher = new IndexSearcher(indexReader); //var queryParser = new QueryParser(Version.LUCENE_30, "Naslov", analyzer); var queryParser = new MultiFieldQueryParser(Version.LUCENE_30, new[] { "PostID", "TagID", "DatumKreiranja" }, analyzer); var query = queryParser.Parse(Convert.ToString(TAGID)); // Rastavljanje rečenice na rijeci TopDocs pronadjeno = searcher.Search(query, indexReader.MaxDoc); List<Post> PitanjaTagovi = new List<Post>(); if (pronadjeno != null) { var hits = pronadjeno.ScoreDocs; foreach (var hit in hits) { var documentFromSearcher = searcher.Doc(hit.Doc); using (TriglavBL temp = new TriglavBL()) { PitanjaTagovi.Add(temp.getPitanjeByID(Convert.ToInt32(documentFromSearcher.Get("PostID")))); } } searcher.Dispose(); directoryPronadjenaPitanjaTagovi.Dispose(); return PitanjaTagovi; } else { searcher.Dispose(); directoryPronadjenaPitanjaTagovi.Dispose(); return PitanjaTagovi; } }