Пример #1
0
        /// <summary>
        /// (non-Javadoc)
        /// @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public virtual Query GetQuery(XmlElement e)
        {
            BooleanQuery bq = new BooleanQuery(DOMUtils.GetAttribute(e, "disableCoord", false));

            bq.MinimumNumberShouldMatch = DOMUtils.GetAttribute(e, "minimumNumberShouldMatch", 0);
            bq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);

            XmlNodeList nl = e.ChildNodes;

            for (int i = 0; i < nl.Count; i++)
            {
                XmlNode node = nl.Item(i);
                if (node.LocalName.Equals("Clause", StringComparison.Ordinal))
                {
                    XmlElement clauseElem = (XmlElement)node;
                    Occur      occurs     = GetOccursValue(clauseElem);

                    XmlElement clauseQuery = DOMUtils.GetFirstChildOrFail(clauseElem);
                    Query      q           = factory.GetQuery(clauseQuery);
                    bq.Add(new BooleanClause(q, occurs));
                }
            }

            return(bq);
        }
Пример #2
0
        public virtual Query GetQuery(XmlElement e)
        {
            XmlElement filterElem = DOMUtils.GetFirstChildOrFail(e);

            Query q = new ConstantScoreQuery(filterFactory.GetFilter(filterElem));

            q.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(q);
        }
Пример #3
0
        public virtual Filter GetFilter(XmlElement e)
        {
            UninterruptableMonitor.Enter(this);
            try
            {
                XmlElement childElement = DOMUtils.GetFirstChildOrFail(e);

                if (filterCache is null)
                {
                    filterCache = new LurchTable <object, Filter>(LurchTableOrder.Access, cacheSize);
                }

                // Test to see if child Element is a query or filter that needs to be
                // cached
                IQueryBuilder qb       = queryFactory.GetQueryBuilder(childElement.Name);
                object        cacheKey = null;
                Query         q        = null;
                Filter        f        = null;
                if (qb != null)
                {
                    q        = qb.GetQuery(childElement);
                    cacheKey = q;
                }
                else
                {
                    f        = filterFactory.GetFilter(childElement);
                    cacheKey = f;
                }
                if (filterCache.TryGetValue(cacheKey, out Filter cachedFilter) && cachedFilter != null)
                {
                    return(cachedFilter); // cache hit
                }

                //cache miss
                if (qb != null)
                {
                    cachedFilter = new QueryWrapperFilter(q);
                }
                else
                {
                    cachedFilter = new CachingWrapperFilter(f);
                }

                filterCache[cacheKey] = cachedFilter;
                return(cachedFilter);
            }
            finally
            {
                UninterruptableMonitor.Exit(this);
            }
        }
Пример #4
0
        /// <summary>
        /// (non-Javadoc)
        /// @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
        /// </summary>
        public virtual Query GetQuery(XmlElement e)
        {
            XmlElement filterElement = DOMUtils.GetChildByTagOrFail(e, "Filter");

            filterElement = DOMUtils.GetFirstChildOrFail(filterElement);
            Filter f = filterFactory.GetFilter(filterElement);

            XmlElement queryElement = DOMUtils.GetChildByTagOrFail(e, "Query");

            queryElement = DOMUtils.GetFirstChildOrFail(queryElement);
            Query q = queryFactory.GetQuery(queryElement);

            FilteredQuery fq = new FilteredQuery(q, f);

            fq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(fq);
        }
Пример #5
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            XmlElement includeElem = DOMUtils.GetChildByTagOrFail(e, "Include");

            includeElem = DOMUtils.GetFirstChildOrFail(includeElem);

            XmlElement excludeElem = DOMUtils.GetChildByTagOrFail(e, "Exclude");

            excludeElem = DOMUtils.GetFirstChildOrFail(excludeElem);

            SpanQuery include = factory.GetSpanQuery(includeElem);
            SpanQuery exclude = factory.GetSpanQuery(excludeElem);

            SpanNotQuery snq = new SpanNotQuery(include, exclude);

            snq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(snq);
        }
Пример #6
0
        public virtual Query GetQuery(XmlElement e)
        {
            XmlElement mainQueryElem = DOMUtils.GetChildByTagOrFail(e, "Query");

            mainQueryElem = DOMUtils.GetFirstChildOrFail(mainQueryElem);
            Query mainQuery = factory.GetQuery(mainQueryElem);

            XmlElement boostQueryElem = DOMUtils.GetChildByTagOrFail(e, "BoostQuery");
            float      boost          = DOMUtils.GetAttribute(boostQueryElem, "boost", DEFAULT_BOOST);

            boostQueryElem = DOMUtils.GetFirstChildOrFail(boostQueryElem);
            Query boostQuery = factory.GetQuery(boostQueryElem);

            BoostingQuery bq = new BoostingQuery(mainQuery, boostQuery, boost);

            bq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(bq);
        }
Пример #7
0
        public virtual Filter GetFilter(XmlElement e)
        {
            BooleanFilter bf = new BooleanFilter();
            XmlNodeList   nl = e.ChildNodes;

            for (int i = 0; i < nl.Count; i++)
            {
                XmlNode node = nl.Item(i);
                if (node.LocalName.Equals("Clause", StringComparison.Ordinal))
                {
                    XmlElement clauseElem = (XmlElement)node;
                    Occur      occurs     = BooleanQueryBuilder.GetOccursValue(clauseElem);

                    XmlElement clauseFilter = DOMUtils.GetFirstChildOrFail(clauseElem);
                    Filter     f            = factory.GetFilter(clauseFilter);
                    bf.Add(new FilterClause(f, occurs));
                }
            }

            return(bf);
        }