示例#1
0
        public virtual Query GetQuery(XmlElement e)
        {
            string field          = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string lowerTerm      = DOMUtils.GetAttributeOrFail(e, "lowerTerm");
            string upperTerm      = DOMUtils.GetAttributeOrFail(e, "upperTerm");
            bool   lowerInclusive = DOMUtils.GetAttribute(e, "includeLower", true);
            bool   upperInclusive = DOMUtils.GetAttribute(e, "includeUpper", true);
            int    precisionStep  = DOMUtils.GetAttribute(e, "precisionStep", NumericUtils.PRECISION_STEP_DEFAULT);

            string type = DOMUtils.GetAttribute(e, "type", "int");

            try
            {
                Query filter;
                if (type.Equals("int", StringComparison.OrdinalIgnoreCase))
                {
                    filter = NumericRangeQuery.NewInt32Range(field, precisionStep,
                                                             J2N.Numerics.Int32.Parse(lowerTerm, NumberFormatInfo.InvariantInfo),
                                                             J2N.Numerics.Int32.Parse(upperTerm, NumberFormatInfo.InvariantInfo),
                                                             lowerInclusive,
                                                             upperInclusive);
                }
                else if (type.Equals("long", StringComparison.OrdinalIgnoreCase))
                {
                    filter = NumericRangeQuery.NewInt64Range(field, precisionStep,
                                                             J2N.Numerics.Int64.Parse(lowerTerm, NumberFormatInfo.InvariantInfo),
                                                             J2N.Numerics.Int64.Parse(upperTerm, NumberFormatInfo.InvariantInfo),
                                                             lowerInclusive,
                                                             upperInclusive);
                }
                else if (type.Equals("double", StringComparison.OrdinalIgnoreCase))
                {
                    filter = NumericRangeQuery.NewDoubleRange(field, precisionStep,
                                                              J2N.Numerics.Double.Parse(lowerTerm, NumberFormatInfo.InvariantInfo),
                                                              J2N.Numerics.Double.Parse(upperTerm, NumberFormatInfo.InvariantInfo),
                                                              lowerInclusive,
                                                              upperInclusive);
                }
                else if (type.Equals("float", StringComparison.OrdinalIgnoreCase))
                {
                    filter = NumericRangeQuery.NewSingleRange(field, precisionStep,
                                                              J2N.Numerics.Single.Parse(lowerTerm, NumberFormatInfo.InvariantInfo),
                                                              J2N.Numerics.Single.Parse(upperTerm, NumberFormatInfo.InvariantInfo),
                                                              lowerInclusive,
                                                              upperInclusive);
                }
                else
                {
                    throw new ParserException("type attribute must be one of: [long, int, double, float]");
                }
                return(filter);
            }
            catch (Exception nfe) when(nfe.IsNumberFormatException())
            {
                throw new ParserException("Could not parse lowerTerm or upperTerm into a number", nfe);
            }
        }
示例#2
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            string        fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string        value     = DOMUtils.GetNonBlankTextOrFail(e);
            SpanTermQuery stq       = new SpanTermQuery(new Term(fieldName, value));

            stq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(stq);
        }
示例#3
0
        public virtual Query GetQuery(XmlElement e)
        {
            string    field = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string    value = DOMUtils.GetNonBlankTextOrFail(e);
            TermQuery tq    = new TermQuery(new Term(field, value));

            tq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(tq);
        }
示例#4
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);
        }
示例#5
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            string fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string value     = DOMUtils.GetNonBlankTextOrFail(e);

            PayloadTermQuery btq = new PayloadTermQuery(new Term(fieldName, value), new AveragePayloadFunction());

            btq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(btq);
        }
示例#6
0
        public override ISheet GetPrimarySheet()
        {
            XElement primarySheet = DOMUtils.GetFirstElementByTagName(GetWorkbookElement(), TAG_SHEET);

            if (primarySheet != null)
            {
                return((ISheet)GetAdaptableRegistry().GetAdaptable(primarySheet));
            }
            return(null);
        }
示例#7
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            int        end   = DOMUtils.GetAttribute(e, "end", 1);
            XmlElement child = DOMUtils.GetFirstChildElement(e);
            SpanQuery  q     = factory.GetSpanQuery(child);

            SpanFirstQuery sfq = new SpanFirstQuery(q, end);

            sfq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(sfq);
        }
示例#8
0
        public virtual Filter GetFilter(XmlElement e)
        {
            string fieldName = DOMUtils.GetAttributeWithInheritance(e, "fieldName");

            string lowerTerm    = e.GetAttribute("lowerTerm");
            string upperTerm    = e.GetAttribute("upperTerm");
            bool   includeLower = DOMUtils.GetAttribute(e, "includeLower", true);
            bool   includeUpper = DOMUtils.GetAttribute(e, "includeUpper", true);

            return(TermRangeFilter.NewStringRange(fieldName, lowerTerm, upperTerm, includeLower, includeUpper));
        }
示例#9
0
        /// <summary>
        /// Gets primary sheet
        /// </summary>
        /// <returns></returns>
        public override ISheet GetPrimarySheet()
        {
            XElement primarySheet = DOMUtils.GetFirstElementByTagName(GetWorkbookElement(), TAG_SHEET);

            if (primarySheet == null)
            {
                const string errorMessage = "Primary sheet was not found";
                Logger.Log.Error(errorMessage);
                throw new InvalidOperationException(errorMessage);
            }
            return((ISheet)GetAdaptableRegistry().GetAdaptable(primarySheet) !);
        }
示例#10
0
        public virtual Filter GetFilter(XmlElement e)
        {
            string field          = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string lowerTerm      = DOMUtils.GetAttributeOrFail(e, "lowerTerm");
            string upperTerm      = DOMUtils.GetAttributeOrFail(e, "upperTerm");
            bool   lowerInclusive = DOMUtils.GetAttribute(e, "includeLower", true);
            bool   upperInclusive = DOMUtils.GetAttribute(e, "includeUpper", true);
            int    precisionStep  = DOMUtils.GetAttribute(e, "precisionStep", NumericUtils.PRECISION_STEP_DEFAULT);

            string type = DOMUtils.GetAttribute(e, "type", "int");

            try
            {
                Filter filter;
                if (type.Equals("int", StringComparison.OrdinalIgnoreCase))
                {
                    filter = NumericRangeFilter.NewInt32Range(field, precisionStep, Convert
                                                              .ToInt32(lowerTerm, CultureInfo.InvariantCulture), Convert.ToInt32(upperTerm, CultureInfo.InvariantCulture), lowerInclusive,
                                                              upperInclusive);
                }
                else if (type.Equals("long", StringComparison.OrdinalIgnoreCase))
                {
                    filter = NumericRangeFilter.NewInt64Range(field, precisionStep, Convert
                                                              .ToInt64(lowerTerm, CultureInfo.InvariantCulture), Convert.ToInt64(upperTerm, CultureInfo.InvariantCulture), lowerInclusive,
                                                              upperInclusive);
                }
                else if (type.Equals("double", StringComparison.OrdinalIgnoreCase))
                {
                    filter = NumericRangeFilter.NewDoubleRange(field, precisionStep, Convert
                                                               .ToDouble(lowerTerm, CultureInfo.InvariantCulture), Convert.ToDouble(upperTerm, CultureInfo.InvariantCulture), lowerInclusive,
                                                               upperInclusive);
                }
                else if (type.Equals("float", StringComparison.OrdinalIgnoreCase))
                {
                    filter = NumericRangeFilter.NewSingleRange(field, precisionStep, Convert
                                                               .ToSingle(lowerTerm, CultureInfo.InvariantCulture), Convert.ToSingle(upperTerm, CultureInfo.InvariantCulture), lowerInclusive,
                                                               upperInclusive);
                }
                else
                {
                    throw new ParserException("type attribute must be one of: [long, int, double, float]");
                }
                return(filter);
            }
            catch (FormatException nfe)
            {
                if (strictMode)
                {
                    throw new ParserException("Could not parse lowerTerm or upperTerm into a number", nfe);
                }
                return(NO_MATCH_FILTER);
            }
        }
示例#11
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);
            }
        }
示例#12
0
        public override string getComponentNumberFromLink(string link)
        {
            String[] part = link.Split('/');
            if (part.Length < 4)
            {
                return(null);
            }
            if (!part[2].Contains("digikey"))
            {
                return(null);
            }

            HtmlAgilityPack.HtmlDocument dom = DOMUtils.getDOMFromLink(link, "text/html");

            HtmlNode someNode = dom.GetElementbyId("reportPartNumber");

            if (someNode == null)
            {
                HtmlNode c1 = dom.GetElementbyId("product-overview");
                if (c1 == null)
                {
                    return(null);
                }
                HtmlNode c2 = DOMUtils.getNextChildNodeType(c1, "tbody", 0);
                if (c2 == null)
                {
                    c2 = c1;
                }
                HtmlNode c3 = DOMUtils.getNextChildNodeType(c2, "tr", 0);
                if (c3 == null)
                {
                    return(null);
                }
                HtmlNode c4 = DOMUtils.getNextChildNodeType(c3, "td", 0);
                if (c4 == null)
                {
                    return(null);
                }
                someNode = DOMUtils.getNextChildNodeType(c4, "meta", 0);
                if (someNode == null)
                {
                    return(null);
                }
            }
            return(someNode.InnerText.Trim(new char[] { '\r', '\t', '\n', ' ' }));
        }
示例#13
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            string slopString = DOMUtils.GetAttributeOrFail(e, "slop");
            int    slop       = int.Parse(slopString, CultureInfo.InvariantCulture);
            bool   inOrder    = DOMUtils.GetAttribute(e, "inOrder", false);

            JCG.List <SpanQuery> spans = new JCG.List <SpanQuery>();
            for (XmlNode kid = e.FirstChild; kid != null; kid = kid.NextSibling)
            {
                if (kid.NodeType == XmlNodeType.Element)
                {
                    spans.Add(factory.GetSpanQuery((XmlElement)kid));
                }
            }
            SpanQuery[] spanQueries = spans.ToArray(/*new SpanQuery[spans.size()]*/);
            return(new SpanNearQuery(spanQueries, slop, inOrder));
        }
示例#14
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            JCG.List <SpanQuery> clausesList = new JCG.List <SpanQuery>();
            for (XmlNode kid = e.FirstChild; kid != null; kid = kid.NextSibling)
            {
                if (kid.NodeType == XmlNodeType.Element)
                {
                    SpanQuery clause = factory.GetSpanQuery((XmlElement)kid);
                    clausesList.Add(clause);
                }
            }
            SpanQuery[] clauses = clausesList.ToArray(/*new SpanQuery[clausesList.size()]*/);
            SpanOrQuery soq     = new SpanOrQuery(clauses);

            soq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(soq);
        }
示例#15
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);
        }
示例#16
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);
        }
示例#17
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);
        }
示例#18
0
        // private string _fileName = null;

        /// <summary>
        /// Creates a new XMind workbook if loadContent is false, otherwise the file content will be loaded.
        /// </summary>
        // /// <param name="loadContent">If true, the current data from the file will be loaded, otherwise an empty workbook will be created.</param>
        internal XMindWorkBook(string name, XMindConfiguration bookConfiguration, IXMindDocumentBuilder builder)
        {
            Name                    = name;
            _xMindSettings          = XMindConfigurationLoader.Configuration.XMindConfigCollection;
            this._bookConfiguration = bookConfiguration;
            _documentBuilder        = builder;

            _documentBuilder.CreateMetaFile();
            _documentBuilder.CreateManifestFile();
            _documentBuilder.CreateContentFile();

            _implementation    = _documentBuilder.ContentFile.Descendants().First();
            _adaptableRegistry = new NodeAdaptableRegistry(_documentBuilder.ContentFile, this);
            //Create default sheet if needed
            //TODO:
            if (DOMUtils.GetFirstElementByTagName(_implementation, TAG_SHEET) == null)
            {
                AddSheet(CreateSheet());
            }
        }
示例#19
0
        /// <summary>
        /// (non-Javadoc)
        /// @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
        /// </summary>
        public virtual Query GetQuery(XmlElement e)
        {
            float tieBreaker       = DOMUtils.GetAttribute(e, "tieBreaker", 0.0f);
            DisjunctionMaxQuery dq = new DisjunctionMaxQuery(tieBreaker);

            dq.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 is XmlElement queryElem)
                { // all elements are disjuncts.
                    Query q = factory.GetQuery(queryElem);
                    dq.Add(q);
                }
            }

            return(dq);
        }
示例#20
0
        public override void RemoveSheet(ISheet sheet)
        {
            XElement elementImplementation = (sheet as XMindSheet)?.Implementation;
            var      bookImplementation    = GetWorkbookElement();

            if (elementImplementation == null)
            {
                // Logger.Warn("XMindWorkbook.RemoveSheet: sheet is not correct");
                return;
            }
            if (elementImplementation.Parent != bookImplementation)
            {
                // Logger.Warn("XMindWorkbook.RemoveSheet: sheet must belong to same document");
            }
            var childElements = DOMUtils
                                .GetChildElementsByTag(bookImplementation, TAG_SHEET).ToList();

            childElements
            .FirstOrDefault(el => el == elementImplementation)?
            .Remove();
        }
示例#21
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);
        }
示例#22
0
        public override void RemoveSheet(ISheet sheet)
        {
            if (!(sheet is XMindSheet xmindSheet) || xmindSheet.Implementation is null)
            {
                const string errorMessage = "Implementation was not found";
                Logger.Log.Error(errorMessage);
                throw new ArgumentException(errorMessage);
            }
            XElement elementImplementation = xmindSheet.Implementation;
            var      bookImplementation    = GetWorkbookElement();

            if (elementImplementation.Parent != bookImplementation)
            {
                // Logger.Warn("XMindWorkbook.RemoveSheet: sheet must belong to same document");
            }
            var childElements = DOMUtils
                                .GetChildElementsByTag(bookImplementation, TAG_SHEET).ToList();

            childElements
            .FirstOrDefault(el => el == elementImplementation)?
            .Remove();
        }
示例#23
0
        public virtual Query GetQuery(XmlElement e)
        {
            XmlNodeList        nl          = e.GetElementsByTagName("Field");
            int                maxNumTerms = DOMUtils.GetAttribute(e, "maxNumTerms", DEFAULT_MAX_NUM_TERMS);
            FuzzyLikeThisQuery fbq         = new FuzzyLikeThisQuery(maxNumTerms, analyzer);

            fbq.IgnoreTF = DOMUtils.GetAttribute(e, "ignoreTF", DEFAULT_IGNORE_TF);

            for (int i = 0; i < nl.Count; i++)
            {
                XmlElement fieldElem     = (XmlElement)nl.Item(i);
                float      minSimilarity = DOMUtils.GetAttribute(fieldElem, "minSimilarity", DEFAULT_MIN_SIMILARITY);
                int        prefixLength  = DOMUtils.GetAttribute(fieldElem, "prefixLength", DEFAULT_PREFIX_LENGTH);
                string     fieldName     = DOMUtils.GetAttributeWithInheritance(fieldElem, "fieldName");

                string value = DOMUtils.GetText(fieldElem);
                fbq.AddTerms(value, fieldName, minSimilarity, prefixLength);
            }

            fbq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(fbq);
        }
示例#24
0
        public override Component getComponentFromNumber(string number)
        {
            Component comp    = Component.getFromVenderNumber(VenderName, number);
            bool      excists = false;

            if (comp != null)
            {
                if (comp.CheckedAt.AddDays(1).CompareTo(DateTime.Now) > 0)
                {
                    return(comp);
                }
                excists = true;
            }
            if (!excists)
            {
                comp = new Component();
            }


            HtmlDocument dom = DOMUtils.getDOMFromLink("https://www.digikey.be/products/nl?keywords=" + number, "text/html");

            addInfoToComp(comp, dom);
            comp.Vendername = VenderName;
            comp.Name       = number;
            comp.Link       = "https://www.digikey.be/products/nl?keywords=" + number;
            comp.CheckedAt  = DateTime.Now;

            if (excists)
            {
                Component.update(comp);
            }
            else
            {
                Component.add(comp);
            }

            return(comp);
        }
示例#25
0
        public override string getComponentNumberFromLink(string link)
        {
            String[] part = link.Split('/');
            if (part.Length < 4)
            {
                return(null);
            }
            if (!part[2].Contains("mouser"))
            {
                return(null);
            }

            HtmlAgilityPack.HtmlDocument dom = DOMUtils.getDOMFromLink(link, null);

            HtmlNode someNode = dom.GetElementbyId("spnMouserPartNumFormattedForProdInfo");

            if (someNode == null)
            {
                return(null);
            }

            return(someNode.InnerText.Trim(new char[] { '\r', '\t', '\n', ' ' }));
        }
        public virtual Filter GetFilter(XmlElement e)
        {
            string          fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            DuplicateFilter df        = new DuplicateFilter(fieldName);

            string keepMode = DOMUtils.GetAttribute(e, "keepMode", "first");

            if (keepMode.Equals("first", StringComparison.OrdinalIgnoreCase))
            {
                df.KeepMode = KeepMode.KM_USE_FIRST_OCCURRENCE;
            }
            else if (keepMode.Equals("last", StringComparison.OrdinalIgnoreCase))
            {
                df.KeepMode = KeepMode.KM_USE_LAST_OCCURRENCE;
            }
            else
            {
                throw new ParserException("Illegal keepMode attribute in DuplicateFilter:" + keepMode);
            }

            string processingMode = DOMUtils.GetAttribute(e, "processingMode", "full");

            if (processingMode.Equals("full", StringComparison.OrdinalIgnoreCase))
            {
                df.ProcessingMode = ProcessingMode.PM_FULL_VALIDATION;
            }
            else if (processingMode.Equals("fast", StringComparison.OrdinalIgnoreCase))
            {
                df.ProcessingMode = ProcessingMode.PM_FAST_INVALIDATION;
            }
            else
            {
                throw new ParserException("Illegal processingMode attribute in DuplicateFilter:" + processingMode);
            }

            return(df);
        }
示例#27
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            string fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string value     = DOMUtils.GetNonBlankTextOrFail(e);

            List <SpanQuery> clausesList = new List <SpanQuery>();

            TokenStream ts = null;

            try
            {
                ts = analyzer.GetTokenStream(fieldName, value);
                ITermToBytesRefAttribute termAtt = ts.AddAttribute <ITermToBytesRefAttribute>();
                BytesRef bytes = termAtt.BytesRef;
                ts.Reset();
                while (ts.IncrementToken())
                {
                    termAtt.FillBytesRef();
                    SpanTermQuery stq = new SpanTermQuery(new Term(fieldName, BytesRef.DeepCopyOf(bytes)));
                    clausesList.Add(stq);
                }
                ts.End();
                SpanOrQuery soq = new SpanOrQuery(clausesList.ToArray(/*new SpanQuery[clausesList.size()]*/));
                soq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
                return(soq);
            }
#pragma warning disable 168
            catch (IOException ioe)
#pragma warning restore 168
            {
                throw new ParserException("IOException parsing value:" + value);
            }
            finally
            {
                IOUtils.DisposeWhileHandlingException(ts);
            }
        }
示例#28
0
        public virtual Query GetQuery(XmlElement e)
        {
            string fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string text      = DOMUtils.GetNonBlankTextOrFail(e);

            BooleanQuery bq = new BooleanQuery(DOMUtils.GetAttribute(e, "disableCoord", false));

            bq.MinimumNumberShouldMatch = DOMUtils.GetAttribute(e, "minimumNumberShouldMatch", 0);
            TokenStream ts = null;

            try
            {
                ts = analyzer.GetTokenStream(fieldName, text);
                ITermToBytesRefAttribute termAtt = ts.AddAttribute <ITermToBytesRefAttribute>();
                Term     term  = null;
                BytesRef bytes = termAtt.BytesRef;
                ts.Reset();
                while (ts.IncrementToken())
                {
                    termAtt.FillBytesRef();
                    term = new Term(fieldName, BytesRef.DeepCopyOf(bytes));
                    bq.Add(new BooleanClause(new TermQuery(term), Occur.SHOULD));
                }
                ts.End();
            }
            catch (Exception ioe) when(ioe.IsIOException())
            {
                throw RuntimeException.Create("Error constructing terms from index:" + ioe, ioe);
            }
            finally
            {
                IOUtils.DisposeWhileHandlingException(ts);
            }

            bq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(bq);
        }
示例#29
0
        /// <summary>
        /// (non-Javadoc)
        /// @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
        /// </summary>
        public virtual Query GetQuery(XmlElement e)
        {
            string fieldsList = e.GetAttribute("fieldNames"); //a comma-delimited list of fields

            string[] fields = defaultFieldNames;
            if ((fieldsList != null) && (fieldsList.Trim().Length > 0))
            {
                fields = fieldsList.Trim().Split(',').TrimEnd();
                //trim the fieldnames
                for (int i = 0; i < fields.Length; i++)
                {
                    fields[i] = fields[i].Trim();
                }
            }

            //Parse any "stopWords" attribute
            //TODO MoreLikeThis needs to ideally have per-field stopWords lists - until then
            //I use all analyzers/fields to generate multi-field compatible stop list
            string        stopWords    = e.GetAttribute("stopWords");
            ISet <string> stopWordsSet = null;

            if ((stopWords != null) && (fields != null))
            {
                stopWordsSet = new JCG.HashSet <string>();
                foreach (string field in fields)
                {
                    TokenStream ts = null;
                    try
                    {
                        ts = analyzer.GetTokenStream(field, stopWords);
                        ICharTermAttribute termAtt = ts.AddAttribute <ICharTermAttribute>();
                        ts.Reset();
                        while (ts.IncrementToken())
                        {
                            stopWordsSet.Add(termAtt.ToString());
                        }
                        ts.End();
                    }
                    catch (IOException ioe)
                    {
                        throw new ParserException("IoException parsing stop words list in "
                                                  + GetType().Name + ":" + ioe.Message);
                    }
                    finally
                    {
                        IOUtils.DisposeWhileHandlingException(ts);
                    }
                }
            }

            MoreLikeThisQuery mlt = new MoreLikeThisQuery(DOMUtils.GetText(e), fields, analyzer, fields[0]);

            mlt.MaxQueryTerms       = DOMUtils.GetAttribute(e, "maxQueryTerms", DEFAULT_MAX_QUERY_TERMS);
            mlt.MinTermFrequency    = DOMUtils.GetAttribute(e, "minTermFrequency", DEFAULT_MIN_TERM_FREQUENCY);
            mlt.PercentTermsToMatch = DOMUtils.GetAttribute(e, "percentTermsToMatch", DEFAULT_PERCENT_TERMS_TO_MATCH) / 100;
            mlt.StopWords           = stopWordsSet;
            int minDocFreq = DOMUtils.GetAttribute(e, "minDocFreq", -1);

            if (minDocFreq >= 0)
            {
                mlt.MinDocFreq = minDocFreq;
            }

            mlt.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);

            return(mlt);
        }
示例#30
0
 public override IEnumerable <ISheet> GetSheets()
 {
     return(DOMUtils.GetChildList <ISheet>(GetWorkbookElement(), TAG_SHEET, GetAdaptableRegistry()));
 }