Factory for creating basic term queries
Exemplo n.º 1
0
 public SpanNearClauseFactory(IndexReader reader, string fieldName, BasicQueryFactory qf)
 {
     this.reader            = reader;
     this.fieldName         = fieldName;
     this.weightBySpanQuery = new JCG.Dictionary <SpanQuery, float>();
     this.qf = qf;
 }
 public SimpleTermRewriteQuery(
     SimpleTerm srndQuery,
     string fieldName,
     BasicQueryFactory qf)
     : base(srndQuery, fieldName, qf)
 {
 }
 public SpanNearClauseFactory(IndexReader reader, string fieldName, BasicQueryFactory qf)
 {
     this.reader = reader;
     this.fieldName = fieldName;
     this.weightBySpanQuery = new HashMap<SpanQuery, float>();
     this.qf = qf;
 }
Exemplo n.º 4
0
        public virtual Search.Query GetSpanNearQuery(
            IndexReader reader,
            string fieldName,
            float boost,
            BasicQueryFactory qf)
        {
            SpanQuery[] spanClauses = new SpanQuery[NrSubQueries];
            var         sqi         = GetSubQueriesEnumerator();
            int         qi          = 0;

            while (sqi.MoveNext())
            {
                SpanNearClauseFactory sncf = new SpanNearClauseFactory(reader, fieldName, qf);

                ((IDistanceSubQuery)sqi.Current).AddSpanQueries(sncf);
                if (sncf.Count == 0)
                {     /* distance operator requires all sub queries */
                    while (sqi.MoveNext())
                    { /* produce evt. error messages but ignore results */
                        ((IDistanceSubQuery)sqi.Current).AddSpanQueries(sncf);
                        sncf.Clear();
                    }
                    return(SrndQuery.TheEmptyLcnQuery);
                }

                spanClauses[qi] = sncf.MakeSpanClause();
                qi++;
            }
            SpanNearQuery r = new SpanNearQuery(spanClauses, OpDistance - 1, QueriesOrdered);

            r.Boost = boost;
            return(r);
        }
Exemplo n.º 5
0
        public virtual Search.Query GetSpanNearQuery(
            IndexReader reader,
            string fieldName,
            float boost,
            BasicQueryFactory qf)
        {
            SpanQuery[] spanClauses = new SpanQuery[NrSubQueries];
            var sqi = GetSubQueriesEnumerator();
            int qi = 0;
            while (sqi.MoveNext())
            {
                SpanNearClauseFactory sncf = new SpanNearClauseFactory(reader, fieldName, qf);

                ((IDistanceSubQuery)sqi.Current).AddSpanQueries(sncf);
                if (sncf.Count == 0)
                { /* distance operator requires all sub queries */
                    while (sqi.MoveNext())
                    { /* produce evt. error messages but ignore results */
                        ((IDistanceSubQuery)sqi.Current).AddSpanQueries(sncf);
                        sncf.Clear();
                    }
                    return SrndQuery.TheEmptyLcnQuery;
                }

                spanClauses[qi] = sncf.MakeSpanClause();
                qi++;
            }
            SpanNearQuery r = new SpanNearQuery(spanClauses, OpDistance - 1, QueriesOrdered);
            r.Boost = boost;
            return r;
        }
Exemplo n.º 6
0
 public virtual Search.Query MakeLuceneQueryField(string fieldName, BasicQueryFactory qf)
 {
     Search.Query q = MakeLuceneQueryFieldNoBoost(fieldName, qf);
     if (IsWeighted)
     {
         q.Boost=(Weight * q.Boost); /* weight may be at any level in a SrndQuery */
     }
     return q;
 }
Exemplo n.º 7
0
 private void CheckEqualParsings(string s1, string s2)
 {
     string fieldName = "foo";
     BasicQueryFactory qf = new BasicQueryFactory(16);
     Search.Query lq1, lq2;
     lq1 = Parser.QueryParser.Parse(s1).MakeLuceneQueryField(fieldName, qf);
     lq2 = Parser.QueryParser.Parse(s2).MakeLuceneQueryField(fieldName, qf);
     QueryUtils.CheckEqual(lq1, lq2);
 }
Exemplo n.º 8
0
 public virtual Search.Query MakeLuceneQueryField(string fieldName, BasicQueryFactory qf)
 {
     Search.Query q = MakeLuceneQueryFieldNoBoost(fieldName, qf);
     if (IsWeighted)
     {
         q.Boost = (Weight * q.Boost); /* weight may be at any level in a SrndQuery */
     }
     return(q);
 }
Exemplo n.º 9
0
 public RewriteQuery(
     SQ srndQuery,
     string fieldName,
     BasicQueryFactory qf)
 {
     this.srndQuery = srndQuery;
     this.fieldName = fieldName;
     this.qf        = qf;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Two BasicQueryFactory's are equal when they generate
        /// the same types of basic queries, or both cannot generate queries anymore.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (!(obj is BasicQueryFactory))
            {
                return(false);
            }
            BasicQueryFactory other = (BasicQueryFactory)obj;

            return(AtMax == other.AtMax);
        }
Exemplo n.º 11
0
        private void CheckEqualParsings(string s1, string s2)
        {
            string            fieldName = "foo";
            BasicQueryFactory qf        = new BasicQueryFactory(16);

            Search.Query lq1, lq2;
            lq1 = Parser.QueryParser.Parse(s1).MakeLuceneQueryField(fieldName, qf);
            lq2 = Parser.QueryParser.Parse(s2).MakeLuceneQueryField(fieldName, qf);
            QueryUtils.CheckEqual(lq1, lq2);
        }
Exemplo n.º 12
0
        public virtual bool IsOperatorInfix { get { return operatorInfix; } } /* else prefix operator */

        public virtual IEnumerable<Search.Query> MakeLuceneSubQueriesField(string fn, BasicQueryFactory qf)
        {
            List<Search.Query> luceneSubQueries = new List<Search.Query>();
            IEnumerator<SrndQuery> sqi = GetSubQueriesEnumerator();
            while (sqi.MoveNext())
            {
                luceneSubQueries.Add((sqi.Current).MakeLuceneQueryField(fn, qf));
            }
            return luceneSubQueries;
        }
Exemplo n.º 13
0
        }                                                                     /* else prefix operator */

        public virtual IList <Search.Query> MakeLuceneSubQueriesField(string fn, BasicQueryFactory qf)
        {
            List <Search.Query>     luceneSubQueries = new List <Search.Query>();
            IEnumerator <SrndQuery> sqi = GetSubQueriesEnumerator();

            while (sqi.MoveNext())
            {
                luceneSubQueries.Add((sqi.Current).MakeLuceneQueryField(fn, qf));
            }
            return(luceneSubQueries);
        }
Exemplo n.º 14
0
 public BooleanQueryTst(
     string queryText,
     int[] expectedDocNrs,
     SingleFieldTestDb dBase,
     string fieldName,
     BasicQueryFactory qf)
 {
     this.queryText      = queryText;
     this.expectedDocNrs = expectedDocNrs;
     this.dBase          = dBase;
     this.fieldName      = fieldName;
     this.qf             = qf;
 }
Exemplo n.º 15
0
 public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
 {
     var luceneSubQueries = MakeLuceneSubQueriesField(fieldName, qf);
     BooleanQuery bq = new BooleanQuery();
     bq.Add(luceneSubQueries.FirstOrDefault(), BooleanClause.Occur.MUST);
     SrndBooleanQuery.AddQueriesToBoolean(bq,
         // FIXME: do not allow weights on prohibited subqueries.
             //luceneSubQueries.subList(1, luceneSubQueries.size()),
             luceneSubQueries.Skip(1).ToList(),
         // later subqueries: not required, prohibited
             BooleanClause.Occur.MUST_NOT);
     return bq;
 }
Exemplo n.º 16
0
        public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
        {
            var          luceneSubQueries = MakeLuceneSubQueriesField(fieldName, qf);
            BooleanQuery bq = new BooleanQuery();

            bq.Add(luceneSubQueries.FirstOrDefault(), BooleanClause.Occur.MUST);
            SrndBooleanQuery.AddQueriesToBoolean(bq,
                                                 // FIXME: do not allow weights on prohibited subqueries.
                                                 //luceneSubQueries.subList(1, luceneSubQueries.size()),
                                                 luceneSubQueries.Skip(1).ToList(),
                                                 // later subqueries: not required, prohibited
                                                 BooleanClause.Occur.MUST_NOT);
            return(bq);
        }
Exemplo n.º 17
0
 public BooleanQueryTst(
     string queryText,
     int[] expectedDocNrs,
     SingleFieldTestDb dBase,
     string fieldName,
     Assert testCase,
     BasicQueryFactory qf)
 {
     this.queryText = queryText;
     this.expectedDocNrs = expectedDocNrs;
     this.dBase = dBase;
     this.fieldName = fieldName;
     this.testCase = testCase;
     this.qf = qf;
 }
Exemplo n.º 18
0
        public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
        {
            var          luceneSubQueries = MakeLuceneSubQueriesField(fieldName, qf);
            BooleanQuery bq = new BooleanQuery
            {
                { luceneSubQueries.Count > 0 ? luceneSubQueries[0] : null, Occur.MUST }
            };

            SrndBooleanQuery.AddQueriesToBoolean(bq,
                                                                                                          // FIXME: do not allow weights on prohibited subqueries.
                                                 luceneSubQueries.GetView(1, luceneSubQueries.Count - 1), // LUCENENET: Converted end index to length
                                                                                                          // later subqueries: not required, prohibited
                                                 Occur.MUST_NOT);
            return(bq);
        }
Exemplo n.º 19
0
 public virtual Search.Query MakeLuceneQueryNoBoost(BasicQueryFactory qf)
 {
     if (fieldNames.Count == 1)
     { /* single field name: no new queries needed */
         return(q.MakeLuceneQueryFieldNoBoost(fieldNames.FirstOrDefault(), qf));
     }
     else
     { /* OR query over the fields */
         List <SrndQuery> queries = new List <SrndQuery>();
         foreach (var fieldName in fieldNames)
         {
             var qc = (SrndQuery)q.Clone();
             queries.Add(new FieldsQuery(qc, fieldName, fieldOp));
         }
         OrQuery oq = new OrQuery(queries,
                                  true /* infix OR for field names */,
                                  orOperatorName);
         // System.out.println(getClass().toString() + ", fields expanded: " + oq.toString()); /* needs testing */
         return(oq.MakeLuceneQueryField(null, qf));
     }
 }
Exemplo n.º 20
0
 public virtual Search.Query MakeLuceneQueryNoBoost(BasicQueryFactory qf)
 {
     if (fieldNames.Count() == 1)
     { /* single field name: no new queries needed */
         return q.MakeLuceneQueryFieldNoBoost(fieldNames.FirstOrDefault(), qf);
     }
     else
     { /* OR query over the fields */
         List<SrndQuery> queries = new List<SrndQuery>();
         foreach (var fieldName in fieldNames)
         {
             var qc = (SrndQuery)q.Clone();
             queries.Add(new FieldsQuery(qc, fieldName, fieldOp));
         }
         OrQuery oq = new OrQuery(queries,
                                 true /* infix OR for field names */,
                                 OrOperatorName);
         // System.out.println(getClass().toString() + ", fields expanded: " + oq.toString()); /* needs testing */
         return oq.MakeLuceneQueryField(null, qf);
     }
 }
Exemplo n.º 21
0
        public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
        {
            var          luceneSubQueries = MakeLuceneSubQueriesField(fieldName, qf);
            BooleanQuery bq = new BooleanQuery
            {
                { luceneSubQueries.Count > 0 ? luceneSubQueries[0] : null, Occur.MUST }
            };

            // LUCENENET: SubList() is slow, so we do an array copy operation instead
            var luceneSubQueriesArray = new Search.Query[luceneSubQueries.Count - 1];

            for (int i = 1, j = 0; i < luceneSubQueries.Count; i++, j++)
            {
                luceneSubQueriesArray[j] = luceneSubQueries[i];
            }

            SrndBooleanQuery.AddQueriesToBoolean(bq,
                                                 // FIXME: do not allow weights on prohibited subqueries.
                                                 luceneSubQueriesArray,
                                                 // later subqueries: not required, prohibited
                                                 Occur.MUST_NOT);
            return(bq);
        }
Exemplo n.º 22
0
 public abstract Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf);
Exemplo n.º 23
0
 public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
 {
     return(MakeLuceneQueryNoBoost(qf)); /* use this.fieldNames instead of fieldName */
 }
Exemplo n.º 24
0
 public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
 {
     return(SrndBooleanQuery.MakeBooleanQuery( /* subqueries can be individually boosted */
                MakeLuceneSubQueriesField(fieldName, qf), BooleanClause.Occur.MUST));
 }
Exemplo n.º 25
0
 public abstract Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf);
Exemplo n.º 26
0
 public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
 {
     return(new SimpleTermRewriteQuery(this, fieldName, qf));
 }
 public SimpleTermRewriteMatchingTermVisitor(IList <Search.Query> luceneSubQueries, BasicQueryFactory qf)
 {
     this.luceneSubQueries = luceneSubQueries;
     this.qf = qf;
 }
Exemplo n.º 28
0
 public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
 {
     return MakeLuceneQueryNoBoost(qf); /* use this.fieldNames instead of fieldName */
 }
Exemplo n.º 29
0
 public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
 {
     return new DistanceRewriteQuery(this, fieldName, qf);
 }
Exemplo n.º 30
0
 public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
 {
     return SrndBooleanQuery.MakeBooleanQuery(
         /* subqueries can be individually boosted */
         MakeLuceneSubQueriesField(fieldName, qf), BooleanClause.Occur.SHOULD);
 }