/// <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) { 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) { 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); }
/// <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); }