protected internal override Query GetFieldQuery(string field, string queryText, int slop) { ComplexPhraseQuery cpq = new ComplexPhraseQuery(field, queryText, slop, InOrder); complexPhrases.Add(cpq); // add to list of phrases to be parsed once // we // are through with this pass return cpq; }
protected internal override Query GetFieldQuery(string field, string queryText, int slop) { ComplexPhraseQuery cpq = new ComplexPhraseQuery(field, queryText, slop, InOrder); complexPhrases.Add(cpq); // add to list of phrases to be parsed once // we // are through with this pass return(cpq); }
public override Query Parse(String query) { if (isPass2ResolvingPhrases) { RewriteMethod oldMethod = MultiTermRewriteMethod; try { // Temporarily force BooleanQuery rewrite so that Parser will // generate visible // collection of terms which we can convert into SpanQueries. // ConstantScoreRewrite mode produces an // opaque ConstantScoreQuery object which cannot be interrogated for // terms in the same way a BooleanQuery can. // QueryParser is not guaranteed threadsafe anyway so this temporary // state change should not // present an issue MultiTermRewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE; return(base.Parse(query)); } finally { MultiTermRewriteMethod = oldMethod; } } // First pass - parse the top-level query recording any PhraseQuerys // which will need to be resolved complexPhrases = new List <ComplexPhraseQuery>(); Query q = base.Parse(query); // Perform second pass, using this QueryParser to parse any nested // PhraseQueries with different // set of syntax restrictions (i.e. all fields must be same) isPass2ResolvingPhrases = true; try { using (IEnumerator <ComplexPhraseQuery> enumerator = complexPhrases.GetEnumerator()) { while (enumerator.MoveNext()) { currentPhraseQuery = enumerator.Current; currentPhraseQuery.ParsePhraseElements(this); } } } finally { isPass2ResolvingPhrases = false; } return(q); }
public override bool Equals(object obj) { if (this == obj) { return(true); } if (obj is null) { return(false); } if (GetType() != obj.GetType()) { return(false); } if (!base.Equals(obj)) { return(false); } ComplexPhraseQuery other = (ComplexPhraseQuery)obj; if (field is null) { if (other.field != null) { return(false); } } else if (!field.Equals(other.field, StringComparison.Ordinal)) { return(false); } if (phrasedQueryStringContents is null) { if (other.phrasedQueryStringContents != null) { return(false); } } else if (!phrasedQueryStringContents .Equals(other.phrasedQueryStringContents, StringComparison.Ordinal)) { return(false); } if (slopFactor != other.slopFactor) { return(false); } return(inOrder == other.inOrder); }
public override Boolean Equals(Object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (GetType() != obj.GetType()) { return(false); } ComplexPhraseQuery other = (ComplexPhraseQuery)obj; if (Field == null) { if (other.Field != null) { return(false); } } else if (!Field.Equals(other.Field)) { return(false); } if (PhrasedQueryStringContents == null) { if (other.PhrasedQueryStringContents != null) { return(false); } } else if (!PhrasedQueryStringContents .Equals(other.PhrasedQueryStringContents)) { return(false); } if (SlopFactor != other.SlopFactor) { return(false); } return(true); }
public override Query Parse(string query) { if (isPass2ResolvingPhrases) { MultiTermQuery.RewriteMethod oldMethod = MultiTermRewriteMethod; try { // Temporarily force BooleanQuery rewrite so that Parser will // generate visible // collection of terms which we can convert into SpanQueries. // ConstantScoreRewrite mode produces an // opaque ConstantScoreQuery object which cannot be interrogated for // terms in the same way a BooleanQuery can. // QueryParser is not guaranteed threadsafe anyway so this temporary // state change should not // present an issue MultiTermRewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE; return base.Parse(query); } finally { MultiTermRewriteMethod = oldMethod; } } // First pass - parse the top-level query recording any PhraseQuerys // which will need to be resolved complexPhrases = new List<ComplexPhraseQuery>(); Query q = base.Parse(query); // Perform second pass, using this QueryParser to parse any nested // PhraseQueries with different // set of syntax restrictions (i.e. all fields must be same) isPass2ResolvingPhrases = true; try { foreach (var currentPhraseQuery in complexPhrases) { this.currentPhraseQuery = currentPhraseQuery; // in each phrase, now parse the contents between quotes as a // separate parse operation currentPhraseQuery.ParsePhraseElements(this); } } finally { isPass2ResolvingPhrases = false; } return q; }