コード例 #1
0
        /// <summary>
        /// (non-Javadoc)
        /// @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
        /// </summary>
        public virtual Filter GetFilter(XmlElement e)
        {
            List <BytesRef> terms     = new List <BytesRef>();
            string          text      = DOMUtils.GetNonBlankTextOrFail(e);
            string          fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");

            TokenStream ts = null;

            try
            {
                ts = analyzer.TokenStream(fieldName, text);
                ITermToBytesRefAttribute termAtt = ts.AddAttribute <ITermToBytesRefAttribute>();
                BytesRef bytes = termAtt.BytesRef;
                ts.Reset();
                while (ts.IncrementToken())
                {
                    termAtt.FillBytesRef();
                    terms.Add(BytesRef.DeepCopyOf(bytes));
                }
                ts.End();
            }
            catch (IOException ioe)
            {
                throw new Exception("Error constructing terms from index:" + ioe);
            }
            finally
            {
                IOUtils.CloseWhileHandlingException(ts);
            }
            return(new TermsFilter(fieldName, terms));
        }
コード例 #2
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            string fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string value     = DOMUtils.GetNonBlankTextOrFail(e);

            JCG.List <SpanQuery> clausesList = new JCG.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);
            }
            catch (Exception ioe) when(ioe.IsIOException())
            {
                throw new ParserException("IOException parsing value:" + value, ioe);
            }
            finally
            {
                IOUtils.DisposeWhileHandlingException(ts);
            }
        }
コード例 #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 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);
        }
コード例 #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 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);
        }