Esempio n. 1
0
        public override Query Rewrite(IndexReader reader)
        {
            Query orig = new RegexQuery(term).Rewrite(reader);

            // RegexQuery (via MultiTermQuery).rewrite always returns a BooleanQuery
            BooleanQuery bq = (BooleanQuery)orig;

            BooleanClause[] clauses = bq.GetClauses();
            SpanQuery[]     sqs     = new SpanQuery[clauses.Length];
            for (int i = 0; i < clauses.Length; i++)
            {
                BooleanClause clause = clauses[i];

                // Clauses from RegexQuery.rewrite are always TermQuery's
                TermQuery tq = (TermQuery)clause.GetQuery();

                sqs[i] = new SpanTermQuery(tq.GetTerm());
                sqs[i].SetBoost(tq.GetBoost());
            }

            SpanOrQuery query = new SpanOrQuery(sqs);

            query.SetBoost(orig.GetBoost());

            return(query);
        }
Esempio n. 2
0
		public override Query Rewrite(IndexReader reader)
		{
			Query orig = new RegexQuery(term).Rewrite(reader);
			
			// RegexQuery (via MultiTermQuery).rewrite always returns a BooleanQuery
			BooleanQuery bq = (BooleanQuery) orig;
			
			BooleanClause[] clauses = bq.GetClauses();
			SpanQuery[] sqs = new SpanQuery[clauses.Length];
			for (int i = 0; i < clauses.Length; i++)
			{
				BooleanClause clause = clauses[i];
				
				// Clauses from RegexQuery.rewrite are always TermQuery's
				TermQuery tq = (TermQuery) clause.GetQuery();
				
				sqs[i] = new SpanTermQuery(tq.GetTerm());
				sqs[i].SetBoost(tq.GetBoost());
			}
			
			SpanOrQuery query = new SpanOrQuery(sqs);
			query.SetBoost(orig.GetBoost());
			
			return query;
		}
Esempio n. 3
0
        private int RegexQueryNrHits(String regex, IRegexCapabilities capability)
        {
            RegexQuery query = new RegexQuery(NewTerm(regex));

            if (capability != null)
                query.RegexImplementation = capability;

            return searcher.Search(query, null, 1000).TotalHits;
        }
Esempio n. 4
0
        public void TestEquals()
        {
            RegexQuery query1 = new RegexQuery(NewTerm("foo.*"));
            //query1.SetRegexImplementation(new JakartaRegexpCapabilities());

            RegexQuery query2 = new RegexQuery(NewTerm("foo.*"));
            Assert.True(query1.Equals(query2));
        }
 private int GetRegexQueryHitsCount(string sRegex)
 {
     RegexQuery query = new RegexQuery(NewTerm(sRegex));
     return _searcher.Search(query, 5).TotalHits;
 }