예제 #1
0
        public List <SearchEntry> Search(IBaseWindow baseWin, string searchText)
        {
            if (baseWin == null)
            {
                throw new ArgumentNullException("baseWin");
            }

            const uint flags = (uint)(QueryParser.feature_flag.FLAG_PARTIAL | QueryParser.feature_flag.FLAG_WILDCARD |
                                      QueryParser.feature_flag.FLAG_PHRASE | QueryParser.feature_flag.FLAG_BOOLEAN |
                                      QueryParser.feature_flag.FLAG_LOVEHATE);

            List <SearchEntry> res = new List <SearchEntry>();

            try {
                lock (fLock) {
                    using (Database database = new Database(GetXDBFolder()))
                        using (Enquire enquire = new Enquire(database))
                            using (Stem stemmer = new Stem("russian"))
                                using (QueryParser qp = new QueryParser()) {
                                    qp.SetStemmer(stemmer);
                                    qp.SetDatabase(database);
                                    qp.SetDefaultOp(Query.op.OP_AND);
                                    qp.SetStemmingStrategy(QueryParser.stem_strategy.STEM_SOME);

                                    string qs = searchText + " ged:" + GetSign(baseWin);
                                    qp.AddBooleanPrefix("ged", "GDB");

                                    using (Query query = qp.ParseQuery(qs, flags)) {
                                        enquire.SetQuery(query);

                                        using (MSet matches = enquire.GetMSet(0, 100)) {
                                            MSetIterator m = matches.Begin();
                                            while (m != matches.End())
                                            {
                                                try {
                                                    using (Document mDoc = m.GetDocument()) {
                                                        SearchEntry entry = new SearchEntry();
                                                        entry.XRef    = mDoc.GetData();
                                                        entry.Rank    = m.GetRank() + 1;
                                                        entry.Percent = m.GetPercent();
                                                        res.Add(entry);
                                                    }
                                                } catch (Exception ex) {
                                                    Logger.WriteError("SearchManager.Search()", ex);
                                                }

                                                m = m.Next();
                                            }
                                        }
                                    }
                                }
                }
            } catch (Exception ex) {
                Logger.WriteError("SearchManager.Search()", ex);
            }

            return(res);
        }