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); } }
/// <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) { string text = DOMUtils.GetText(e); try { Query q = null; if (unSafeParser != null) { //synchronize on unsafe parser lock (unSafeParser) { q = unSafeParser.Parse(text); } } else { string fieldName = DOMUtils.GetAttribute(e, "fieldName", defaultField); //Create new parser QueryParser parser = CreateQueryParser(fieldName, analyzer); q = parser.Parse(text); } q.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f); return(q); } catch (ParseException e1) { throw new ParserException(e1.Message); } }
/// <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); }
/// <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) { string text = DOMUtils.GetText(e); try { Query q = null; if (unSafeParser != null) { //synchronize on unsafe parser UninterruptableMonitor.Enter(unSafeParser); try { q = unSafeParser.Parse(text); } finally { UninterruptableMonitor.Exit(unSafeParser); } } else { string fieldName = DOMUtils.GetAttribute(e, "fieldName", defaultField); //Create new parser QueryParser parser = CreateQueryParser(fieldName, analyzer); q = parser.Parse(text); } q.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f); return(q); } catch (Lucene.Net.QueryParsers.Classic.ParseException e1) // LUCENENET: Classic QueryParser has its own ParseException that is different than the one in Support { throw new ParserException(e1.Message, e1); } }
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); }
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); }
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); }
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); } }
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); }
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)); }
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); }
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); } }
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)); }
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); }
/// <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); }
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); }
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); }
/// <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); }
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); }
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); }
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); }
/// <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); }