Beispiel #1
0
        public List <LuceneResult <T> > Search(String[] fields, String querystring)
        {
            //querystring = "\"" + querystring + "\"";

            log.Debug("start new search for multiple fields " + querystring);

            Searcher searcher = new IndexSearcher(reader);
            Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, fields, analyzer);

            parser.DefaultOperator = QueryParser.Operator.AND;

            Query query = parser.Parse(querystring);

            AnonymousClassCollector streamingHitCollector = new AnonymousClassCollector(searcher);

            searcher.Search(query, streamingHitCollector);

            parser = null;
            query  = null;

            List <LuceneResult <T> > ret = streamingHitCollector.GetSortedResult();

            log.Debug("resultcount: " + ret.Count);
            return(ret);
        }
Beispiel #2
0
        public List <LuceneResult <T> > Search(String[] fields, String querystring,
                                               String datecol, String lowerdate, String uppderdate)
        {
            log.Debug("start new search for multiple fields and range");
            //RangeFilter filter = new RangeFilter(datecol, lowerDate, upperDate, true, true);
            Searcher searcher = new IndexSearcher(reader);
            Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            String low = lowerdate;
            String up  = uppderdate;

            DateTime dt1 = DateTime.MinValue;

            if (DateTime.TryParse(lowerdate, out dt1))
            {
                low = Sharpend.Utils.Utils.getDateTimeForIndex(dt1);
            }

            DateTime dt2 = DateTime.MinValue;

            if (DateTime.TryParse(uppderdate, out dt2))
            {
                up = Sharpend.Utils.Utils.getDateTimeForIndex(dt2);
            }

            Query query;

            if (String.IsNullOrEmpty(querystring))
            {
                query = new TermRangeQuery(datecol, low, up, true, true);
            }
            else
            {
                MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, fields, analyzer);
                parser.DefaultOperator = QueryParser.Operator.AND;
                query = parser.Parse(querystring);
            }

            AnonymousClassCollector streamingHitCollector = new AnonymousClassCollector(searcher);

            if (String.IsNullOrEmpty(querystring))
            {
                searcher.Search(query, streamingHitCollector);
            }
            else
            {
                TermRangeFilter filter = new TermRangeFilter(datecol, low, up, true, true);
                searcher.Search(query, filter, streamingHitCollector);
            }

            query = null;

            List <LuceneResult <T> > ret = streamingHitCollector.GetSortedResult();

            log.Debug("resultcount: " + ret.Count);
            return(ret);
        }
Beispiel #3
0
        ///<inheritdoc />
        public override void  Search(Weight weight, Filter filter, Collector collector, IState state)
        {
            for (int i = 0; i < searchables.Length; i++)
            {
                int start = starts[i];

                Collector hc = new AnonymousClassCollector(collector, start, this);
                searchables[i].Search(weight, filter, hc, state);
            }
        }
Beispiel #4
0
        public static void searchFor(Searcher searcher, string querystr)
        {
            QueryParser parser = new QueryParser("body", new StandardAnalyzer());    // could be outside this function
            Query query = parser.Parse(querystr);

            var hits = new AnonymousClassCollector();

            // more accurate timer
            var timer = new Stopwatch();
            timer.Start();
            searcher.Search(query, hits);
            timer.Stop();

            Console.WriteLine("search for [{0}] returned {1} hits in {2}ms )",
                query, hits.Count, timer.ElapsedMilliseconds);
        }
Beispiel #5
0
        public List <LuceneResult <T> > Search(String field, String querystring)
        {
            log.Debug("start new search for field " + field + " query: " + querystring);

            Searcher searcher = new IndexSearcher(reader);
            Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, field, analyzer);
            Query       query  = parser.Parse(querystring);

            AnonymousClassCollector streamingHitCollector = new AnonymousClassCollector(searcher);

            searcher.Search(query, streamingHitCollector);

            parser = null;
            query  = null;

            List <LuceneResult <T> > ret = streamingHitCollector.GetSortedResult();

            log.Debug("resultcount: " + ret.Count);
            return(ret);
        }
        /// <summary>
        /// This method uses a custom HitCollector implementation which simply prints out
        /// the docId and score of every matching document.
        ///
        /// This simulates the streaming search use case, where all hits are supposed to
        /// be processed, regardless of their relevance.
        /// </summary>
        public static void  DoStreamingSearch(Searcher searcher, Query query)
        {
            Collector streamingHitCollector = new AnonymousClassCollector();

            searcher.Search(query, streamingHitCollector);
        }
Beispiel #7
0
        // inherit javadoc
        public override void Search(Weight weight, Filter filter, Collector collector)
        {
            for (int i = 0; i < searchables.Length; i++)
            {

                int start = starts[i];

                Collector hc = new AnonymousClassCollector(collector, start, this);

                searchables[i].Search(weight, filter, hc);
            }
        }
Beispiel #8
0
        /// <summary> This method uses a custom HitCollector implementation which simply prints out
        /// the docId and score of every matching document. 
        /// 
        /// This simulates the streaming search use case, where all hits are supposed to
        /// be processed, regardless of their relevance.
        /// </summary>
        public static void DoStreamingSearch(Searcher searcher, Query query)
        {
            Collector streamingHitCollector = new AnonymousClassCollector();

            searcher.Search(query, streamingHitCollector);
        }