private MultiSpansWrapper(IList<AtomicReaderContext> leaves, SpanQuery query, IDictionary<Term, TermContext> termContexts)
 {
     this.Query = query;
     this.Leaves = leaves;
     this.NumLeaves = leaves.Count;
     this.TermContexts = termContexts;
 }
 private static void VisitQuery(SpanQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     writer.WriteLine("Field: {0}", (object)query.Field);
     if (query is FieldMaskingSpanQuery)
         AzureQueryLogger.VisitQuery((FieldMaskingSpanQuery)query, writer);
     if (query is SpanFirstQuery)
         AzureQueryLogger.VisitQuery((SpanFirstQuery)query, writer);
     if (query is SpanNearQuery)
         AzureQueryLogger.VisitQuery((SpanNearQuery)query, writer);
     if (query is SpanNotQuery)
         AzureQueryLogger.VisitQuery((SpanNotQuery)query, writer);
     if (query is SpanOrQuery)
         AzureQueryLogger.VisitQuery((SpanOrQuery)query, writer);
     if (query is SpanRegexQuery)
         AzureQueryLogger.VisitQuery((SpanRegexQuery)query, writer);
     if (query is SpanTermQuery)
         AzureQueryLogger.VisitQuery((SpanTermQuery)query, writer);
     if (query is PayloadNearQuery)
         AzureQueryLogger.VisitQuery((PayloadNearQuery)query, writer);
     if (query is PayloadTermQuery)
         AzureQueryLogger.VisitQuery((PayloadTermQuery)query, writer);
     if (query is SpanWildcardQuery)
         AzureQueryLogger.VisitQuery((SpanWildcardQuery)query, writer);
     if (query is SpanLastQuery)
         AzureQueryLogger.VisitQuery((SpanLastQuery)query, writer);
     if (!(query is SpanFuzzyQuery))
         return;
     AzureQueryLogger.VisitQuery((SpanFuzzyQuery)query, writer);
 }
Beispiel #3
0
        /// <summary>Construct a SpanNotQuery matching spans from <c>include</c> which
        /// have no overlap with spans from <c>exclude</c>.
        /// </summary>
        public SpanNotQuery(SpanQuery include, SpanQuery exclude)
        {
            this.include = include;
            this.exclude = exclude;

            if (!include.GetField().Equals(exclude.GetField()))
                throw new System.ArgumentException("Clauses must have same field.");
        }
Beispiel #4
0
		public SpanWeight(SpanQuery query, Searcher searcher)
		{
			this.similarity = query.GetSimilarity(searcher);
			this.query = query;
			this.terms = query.GetTerms();
			
			idf = this.query.GetSimilarity(searcher).Idf(terms, searcher);
		}
Beispiel #5
0
		public SpanWeight(SpanQuery query, Searcher searcher)
		{
			this.similarity = query.GetSimilarity(searcher);
			this.query = query;
			terms = new System.Collections.Hashtable();
			query.ExtractTerms(terms);
			idfExp = similarity.idfExplain(new System.Collections.ArrayList(terms.Values), searcher);
			idf = idfExp.GetIdf();
		}
		public SpanWeight(SpanQuery query, Searcher searcher)
		{
			this.similarity = query.GetSimilarity(searcher);
			this.query = query;
            terms = new Support.Set<Lucene.Net.Index.Term>();
			query.ExtractTerms(terms);
			idfExp = similarity.idfExplain(terms.ToArray(), searcher);
			idf = idfExp.GetIdf();
		}
 public virtual void TestSpanNearInOrderVersusOutOfOrder()
 {
     Term t1 = RandomTerm();
     Term t2 = RandomTerm();
     SpanQuery[] subquery = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2) };
     SpanNearQuery q1 = new SpanNearQuery(subquery, 3, true);
     SpanNearQuery q2 = new SpanNearQuery(subquery, 3, false);
     AssertSubsetOf(q1, q2);
 }
 ///
 /// <param name="match"> The underlying <seealso cref="Lucene.Net.Search.Spans.SpanQuery"/> to check </param>
 /// <param name="payloadToMatch"> The <seealso cref="java.util.Collection"/> of payloads to match </param>
 public SpanPayloadCheckQuery(SpanQuery match, ICollection<byte[]> payloadToMatch)
     : base(match)
 {
     if (match is SpanNearQuery)
     {
         throw new System.ArgumentException("SpanNearQuery not allowed");
     }
     this.PayloadToMatch = payloadToMatch;
 }
Beispiel #9
0
        public SpanWeight(SpanQuery query, Searcher searcher)
        {
            this.similarity = query.GetSimilarity(searcher);
            this.internalQuery = query;

            terms = Lucene.Net.Support.Compatibility.SetFactory.CreateHashSet<Term>();
            query.ExtractTerms(terms);

            idfExp = similarity.IdfExplain(terms, searcher);
            idf = idfExp.Idf;
        }
 public virtual void TestSpanNearVersusPhrase()
 {
     Term t1 = RandomTerm();
     Term t2 = RandomTerm();
     SpanQuery[] subquery = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2) };
     SpanNearQuery q1 = new SpanNearQuery(subquery, 0, true);
     PhraseQuery q2 = new PhraseQuery();
     q2.Add(t1);
     q2.Add(t2);
     AssertSameSet(q1, q2);
 }
 public virtual void TestSpanNearVersusBooleanAnd()
 {
     Term t1 = RandomTerm();
     Term t2 = RandomTerm();
     SpanQuery[] subquery = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2) };
     SpanNearQuery q1 = new SpanNearQuery(subquery, int.MaxValue, false);
     BooleanQuery q2 = new BooleanQuery();
     q2.Add(new TermQuery(t1), Occur.MUST);
     q2.Add(new TermQuery(t2), Occur.MUST);
     AssertSameSet(q1, q2);
 }
        public SpanWeight(SpanQuery query, Searcher searcher)
        {
            this.similarity = query.GetSimilarity(searcher);
            this.query = query;
            terms = new System.Collections.Hashtable();
            query.ExtractTerms(terms);

            System.Collections.ArrayList tmp = new System.Collections.ArrayList(terms.Values);

            idf = this.query.GetSimilarity(searcher).Idf(tmp, searcher);
        }
Beispiel #13
0
        /// <summary>
        /// Construct a SpanNotQuery matching spans from <code>include</code> which
        /// have no overlap with spans from <code>exclude</code> within
        /// <code>pre</code> tokens before or <code>post</code> tokens of <code>include</code>.
        /// </summary>
        public SpanNotQuery(SpanQuery include, SpanQuery exclude, int pre, int post)
        {
            this.include = include;
            this.exclude = exclude;
            this.Pre = (pre >= 0) ? pre : 0;
            this.Post = (post >= 0) ? post : 0;

            if (include.Field != null && exclude.Field != null && !include.Field.Equals(exclude.Field))
            {
                throw new System.ArgumentException("Clauses must have same field.");
            }
        }
Beispiel #14
0
        public override System.Object Clone()
        {
            int sz = clauses.Count;
            SpanQuery[] newClauses = new SpanQuery[sz];

            for (int i = 0; i < sz; i++)
            {
                SpanQuery clause = (SpanQuery) clauses[i];
                newClauses[i] = (SpanQuery) clause.Clone();
            }
            SpanOrQuery soq = new SpanOrQuery(newClauses);
            soq.SetBoost(GetBoost());
            return soq;
        }
Beispiel #15
0
 public static Spans Wrap(IndexReaderContext topLevelReaderContext, SpanQuery query)
 {
     IDictionary<Term, TermContext> termContexts = new Dictionary<Term, TermContext>();
     SortedSet<Term> terms = new SortedSet<Term>();
     query.ExtractTerms(terms);
     foreach (Term term in terms)
     {
         termContexts[term] = TermContext.Build(topLevelReaderContext, term);
     }
     IList<AtomicReaderContext> leaves = topLevelReaderContext.Leaves();
     if (leaves.Count == 1)
     {
         AtomicReaderContext ctx = leaves[0];
         return query.GetSpans(ctx, ((AtomicReader)ctx.Reader()).LiveDocs, termContexts);
     }
     return new MultiSpansWrapper(leaves, query, termContexts);
 }
        public virtual Query Build(IQueryNode node)
        {
            // validates node
            BooleanQueryNode booleanNode = (BooleanQueryNode)node;

            IList<IQueryNode> children = booleanNode.GetChildren();
            SpanQuery[]
            spanQueries = new SpanQuery[children.size()];

            int i = 0;
            foreach (IQueryNode child in children)
            {
                spanQueries[i++] = (SpanQuery)child
                    .GetTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
            }

            return new SpanOrQuery(spanQueries);
        }
Beispiel #17
0
 /// <summary>Construct a SpanOrQuery merging the provided clauses. </summary>
 public SpanOrQuery(SpanQuery[] clauses)
 {
     // copy clauses array into an ArrayList
     this.clauses = new System.Collections.ArrayList(clauses.Length);
     for (int i = 0; i < clauses.Length; i++)
     {
         SpanQuery clause = clauses[i];
         if (i == 0)
         {
             // check field
             field = clause.GetField();
         }
         else if (!clause.GetField().Equals(field))
         {
             throw new System.ArgumentException("Clauses must have same field.");
         }
         this.clauses.Add(clause);
     }
 }
Beispiel #18
0
 public SpanNearQuery(SpanQuery[] clauses, int slop, bool inOrder, bool collectPayloads)
 {
     // copy clauses array into an ArrayList
     this.clauses = new List<SpanQuery>(clauses.Length);
     for (int i = 0; i < clauses.Length; i++)
     {
         SpanQuery clause = clauses[i];
         if (field == null) // check field
         {
             field = clause.Field;
         }
         else if (clause.Field != null && !clause.Field.Equals(field))
         {
             throw new System.ArgumentException("Clauses must have same field.");
         }
         this.clauses.Add(clause);
     }
     this.CollectPayloads = collectPayloads;
     this.slop = slop;
     this.inOrder = inOrder;
 }
Beispiel #19
0
        public SpanWeight(SpanQuery query, IndexSearcher searcher)
        {
            this.Similarity = searcher.Similarity;
            this.query = query;

            TermContexts = new Dictionary<Term, TermContext>();
            SortedSet<Term> terms = new SortedSet<Term>();
            query.ExtractTerms(terms);
            IndexReaderContext context = searcher.TopReaderContext;
            TermStatistics[] termStats = new TermStatistics[terms.Count];
            int i = 0;
            foreach (Term term in terms)
            {
                TermContext state = TermContext.Build(context, term);
                termStats[i] = searcher.TermStatistics(term, state);
                TermContexts[term] = state;
                i++;
            }
            string field = query.Field;
            if (field != null)
            {
                Stats = Similarity.ComputeWeight(query.Boost, searcher.CollectionStatistics(query.Field), termStats);
            }
        }
Beispiel #20
0
 /// <summary>
 /// Construct a <see cref="SpanNotQuery"/> matching spans from <paramref name="include"/> which
 /// have no overlap with spans from <paramref name="exclude"/>.
 /// </summary>
 public SpanNotQuery(SpanQuery include, SpanQuery exclude)
     : this(include, exclude, 0, 0)
 {
 }
 public SpanLastQuery(SpanQuery match, Analyzer analyzer)
 {
     this.match = match;
     this.analyzer = analyzer;
 }
 public SpanLastQuery(SpanQuery match, int end)
   : this(match, (Analyzer)new StandardAnalyzer(global::Lucene.Net.Util.Version.LUCENE_30))
 {
 }
Beispiel #23
0
		/// <summary>Construct a SpanFirstQuery matching spans in <code>match</code> whose end
		/// position is less than or equal to <code>end</code>. 
		/// </summary>
		public SpanFirstQuery(SpanQuery match, int end)
		{
			this.match = match;
			this.end = end;
		}
Beispiel #24
0
 private Spans OrSpans(string[] terms)
 {
     SpanQuery[] sqa = new SpanQuery[terms.Length];
     for (int i = 0; i < terms.Length; i++)
     {
         sqa[i] = MakeSpanTermQuery(terms[i]);
     }
     return MultiSpansWrapper.Wrap(Searcher.TopReaderContext, new SpanOrQuery(sqa));
 }
Beispiel #25
0
 private void OrderedSlopTest3SQ(SpanQuery q1, SpanQuery q2, SpanQuery q3, int slop, int[] expectedDocs)
 {
     bool ordered = true;
     SpanNearQuery snq = new SpanNearQuery(new SpanQuery[] { q1, q2, q3 }, slop, ordered);
     CheckHits(snq, expectedDocs);
 }
Beispiel #26
0
 // LUCENE-1404
 private SpanQuery CreateSpan(int slop, bool ordered, SpanQuery[] clauses)
 {
     return new SpanNearQuery(clauses, slop, ordered);
 }
Beispiel #27
0
		private Spans OrSpans(System.String[] terms)
		{
			SpanQuery[] sqa = new SpanQuery[terms.Length];
			for (int i = 0; i < terms.Length; i++)
			{
				sqa[i] = MakeSpanTermQuery(terms[i]);
			}
			return (new SpanOrQuery(sqa)).GetSpans(searcher.GetIndexReader());
		}
 public FieldMaskingSpanQuery(SpanQuery maskedQuery, string maskedField)
 {
     this.maskedQuery = maskedQuery;
     this.field       = maskedField;
 }
		/// <summary>Construct a SpanNearQuery.  Matches spans matching a span from each
		/// clause, with up to <code>slop</code> total unmatched positions between
		/// them.  * When <code>inOrder</code> is true, the spans from each clause
		/// must be * ordered as in <code>clauses</code>. 
		/// </summary>
		public SpanNearQuery(SpanQuery[] clauses, int slop, bool inOrder):this(clauses, slop, inOrder, true)
		{
		}
		public override System.Object Clone()
		{
			int sz = clauses.Count;
			SpanQuery[] newClauses = new SpanQuery[sz];
			
			for (int i = 0; i < sz; i++)
			{
				SpanQuery clause = (SpanQuery) clauses[i];
				newClauses[i] = (SpanQuery) clause.Clone();
			}
			SpanNearQuery spanNearQuery = new SpanNearQuery(newClauses, slop, inOrder);
			spanNearQuery.SetBoost(GetBoost());
			return spanNearQuery;
		}
 protected internal virtual void Check(SpanQuery q, int[] docs)
 {
     CheckHits.CheckHitCollector(Random(), q, null, Searcher, docs);
 }
		/// <summary>MACRO for SpanNearQuery containing three SpanQueries </summary>
		public virtual SpanNearQuery Snear(SpanQuery s, SpanQuery m, SpanQuery e, int slop, bool inOrder)
		{
			return new SpanNearQuery(new SpanQuery[]{s, m, e}, slop, inOrder);
		}
Beispiel #33
0
 /// <summary>
 /// Construct a <see cref="SpanNotQuery"/> matching spans from <paramref name="include"/> which
 /// have no overlap with spans from <paramref name="exclude"/> within
 /// <paramref name="dist"/> tokens of <paramref name="include"/>.
 /// </summary>
 public SpanNotQuery(SpanQuery include, SpanQuery exclude, int dist)
     : this(include, exclude, dist, dist)
 {
 }