Esempio n. 1
0
        public List<TextSearched> GetHistoryBetweenDates(DateTime fromDate, DateTime toDate)
        {
            IndexSearcher searcher = new IndexSearcher(m_HistoryPath);
            List<TextSearched> list = null;
            try
            {
                list = new List<TextSearched>();

                string from = fromDate.ToString("yyyyMMddHHmmss");
                string to = toDate.ToString("yyyyMMddHHmmss");

                //QueryParser parserUser = new QueryParser(Constants.VisitUser, new WhitespaceAnalyzer());
                QueryParser parserDate = new QueryParser(Constants.DateTicks, new WhitespaceAnalyzer());

                //Query queryUser = parserUser.Parse(System.Threading.Thread.CurrentPrincipal.Identity.Name);
                Query queryDate = parserDate.Parse("[" + from + " TO " + to + "]");

                BooleanQuery query = new BooleanQuery();

                //query.Add(queryUser, BooleanClause.Occur.MUST);
                query.Add(queryDate, BooleanClause.Occur.MUST);

                Hits hits = searcher.Search(query);
                for (int i = 0; i < hits.Length(); i++)
                {
                    TextSearched st = new TextSearched();

                    Document doc = hits.Doc(i);
                    st.DateTicks = doc.Get(Constants.DateTicks);
                    st.VisitUser = doc.Get(Constants.VisitUser);
                    st.SearchedText = doc.Get(Constants.SearchedText);

                    list.Add(st);
                }
                return list;
            }
            finally
            {
                searcher.Close();
            }
        }
Esempio n. 2
0
        public List<TextSearched> SearchHistoryByUserPattern(string pattern)
        {
            IndexSearcher searcher = new IndexSearcher(m_HistoryPath);
            List<TextSearched> list = null;
            try
            {
                list = new List<TextSearched>();

                QueryParser parserUser = new QueryParser(Constants.VisitUser, new WhitespaceAnalyzer());
                parserUser.SetDefaultOperator(QueryParser.AND_OPERATOR);
                QueryParser parserPattern = new QueryParser(Constants.SearchedText, new WhitespaceAnalyzer());
                parserPattern.SetDefaultOperator(QueryParser.AND_OPERATOR);

                Query queryUser = parserUser.Parse(System.Threading.Thread.CurrentPrincipal.Identity.Name);
                Query queryPattern = parserPattern.Parse(pattern);

                BooleanQuery query = new BooleanQuery();
                query.Add(queryUser, BooleanClause.Occur.MUST);
                query.Add(queryPattern, BooleanClause.Occur.MUST);

                Hits hits = searcher.Search(query);
                for (int i = 0; i < hits.Length(); i++)
                {
                    TextSearched st = new TextSearched();

                    Document doc = hits.Doc(i);
                    st.DateTicks = doc.Get(Constants.DateTicks);
                    st.VisitUser = doc.Get(Constants.VisitUser);
                    st.SearchedText = doc.Get(Constants.SearchedText);

                    list.Add(st);
                }
                list.Sort();
                return list;
            }
            finally
            {
                searcher.Close();
            }
        }