/// <summary> Constructor for enumeration of all terms from specified <code>reader</code> which share a prefix of /// length <code>prefixLength</code> with <code>term</code> and which have a fuzzy similarity > /// <code>minSimilarity</code>. /// <p/> /// After calling the constructor the enumeration is already pointing to the first /// valid term if such a term exists. /// /// </summary> /// <param name="reader">Delivers terms. /// </param> /// <param name="term">Pattern term. /// </param> /// <param name="minSimilarity">Minimum required similarity for terms from the reader. Default value is 0.5f. /// </param> /// <param name="prefixLength">Length of required common prefix. Default value is 0. /// </param> /// <throws> IOException </throws> public FuzzyTermEnum(IndexReader reader, Term term, float minSimilarity, int prefixLength) : base() { if (minSimilarity >= 1.0f) { throw new System.ArgumentException("minimumSimilarity cannot be greater than or equal to 1"); } else if (minSimilarity < 0.0f) { throw new System.ArgumentException("minimumSimilarity cannot be less than 0"); } if (prefixLength < 0) { throw new System.ArgumentException("prefixLength cannot be less than 0"); } this.minimumSimilarity = minSimilarity; this.scale_factor = 1.0f / (1.0f - minimumSimilarity); this.searchTerm = term; this.field = searchTerm.Field(); //The prefix could be longer than the word. //It's kind of silly though. It means we must match the entire word. int fullSearchTermLength = searchTerm.Text().Length; int realPrefixLength = prefixLength > fullSearchTermLength?fullSearchTermLength:prefixLength; this.text = searchTerm.Text().Substring(realPrefixLength); this.prefix = searchTerm.Text().Substring(0, (realPrefixLength) - (0)); InitializeMaxDistances(); this.d = InitDistanceArray(); SetEnum(reader.Terms(new Term(searchTerm.Field(), prefix))); }
public /*protected internal*/ override bool TermCompare(Term term) { if (collator == null) { // Use Unicode code point ordering bool checkLower = false; if (!includeLower) { // make adjustments to set to exclusive checkLower = true; } if (term != null && (System.Object)term.Field() == (System.Object)field) { // interned comparison if (!checkLower || null == lowerTermText || String.CompareOrdinal(term.Text(), lowerTermText) > 0) { checkLower = false; if (upperTermText != null) { int compare = String.CompareOrdinal(upperTermText, term.Text()); /* * if beyond the upper term, or is exclusive and this is equal to * the upper term, break out */ if ((compare < 0) || (!includeUpper && compare == 0)) { endEnum = true; return(false); } } return(true); } } else { // break endEnum = true; return(false); } return(false); } else { if (term != null && (System.Object)term.Field() == (System.Object)field) { // interned comparison if ((lowerTermText == null || (includeLower?collator.Compare(term.Text().ToString(), lowerTermText.ToString()) >= 0:collator.Compare(term.Text().ToString(), lowerTermText.ToString()) > 0)) && (upperTermText == null || (includeUpper?collator.Compare(term.Text().ToString(), upperTermText.ToString()) <= 0:collator.Compare(term.Text().ToString(), upperTermText.ToString()) < 0))) { return(true); } return(false); } endEnum = true; return(false); } }
/// <summary> The termCompare method in FuzzyTermEnum uses Levenshtein distance to /// calculate the distance between the given term and the comparing term. /// </summary> public /*protected internal*/ override bool TermCompare(Term term) { if ((System.Object)field == (System.Object)term.Field() && term.Text().StartsWith(prefix)) { System.String target = term.Text().Substring(prefix.Length); this.similarity = Similarity(target); return(similarity > minimumSimilarity); } endEnum = true; return(false); }
protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey) { Entry entry = (Entry)entryKey; System.String field = entry.field; SortComparator comparator = (SortComparator)entry.custom; System.IComparable[] retArray = new System.IComparable[reader.MaxDoc()]; TermDocs termDocs = reader.TermDocs(); TermEnum termEnum = reader.Terms(new Term(field)); try { do { Term term = termEnum.Term(); if (term == null || (System.Object)term.Field() != (System.Object)field) { break; } System.IComparable termval = comparator.GetComparable(term.Text()); termDocs.Seek(termEnum); while (termDocs.Next()) { retArray[termDocs.Doc()] = termval; } }while (termEnum.Next()); } finally { termDocs.Close(); termEnum.Close(); } return(retArray); }
protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey) { System.String field = StringHelper.Intern((System.String)entryKey.field); System.String[] retArray = new System.String[reader.MaxDoc()]; TermDocs termDocs = reader.TermDocs(); TermEnum termEnum = reader.Terms(new Term(field)); try { do { Term term = termEnum.Term(); if (term == null || (System.Object)term.Field() != (System.Object)field) { break; } System.String termval = term.Text(); termDocs.Seek(termEnum); while (termDocs.Next()) { retArray[termDocs.Doc()] = termval; } }while (termEnum.Next()); } finally { termDocs.Close(); termEnum.Close(); } return(retArray); }
/// <summary> Create a new FuzzyQuery that will match terms with a similarity /// of at least <code>minimumSimilarity</code> to <code>term</code>. /// If a <code>prefixLength</code> > 0 is specified, a common prefix /// of that length is also required. /// /// </summary> /// <param name="term">the term to search for /// </param> /// <param name="minimumSimilarity">a value between 0 and 1 to set the required similarity /// between the query term and the matching terms. For example, for a /// <code>minimumSimilarity</code> of <code>0.5</code> a term of the same length /// as the query term is considered similar to the query term if the edit distance /// between both terms is less than <code>length(term)*0.5</code> /// </param> /// <param name="prefixLength">length of common (non-fuzzy) prefix /// </param> /// <throws> IllegalArgumentException if minimumSimilarity is >= 1 or < 0 </throws> /// <summary> or if prefixLength < 0 /// </summary> public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength) : base(term) { // will be removed in 3.0 this.term = term; if (minimumSimilarity >= 1.0f) { throw new System.ArgumentException("minimumSimilarity >= 1"); } else if (minimumSimilarity < 0.0f) { throw new System.ArgumentException("minimumSimilarity < 0"); } if (prefixLength < 0) { throw new System.ArgumentException("prefixLength < 0"); } if (term.Text().Length > 1.0f / (1.0f - minimumSimilarity)) { this.termLongEnough = true; } this.minimumSimilarity = minimumSimilarity; this.prefixLength = prefixLength; rewriteMethod = SCORING_BOOLEAN_QUERY_REWRITE; }
protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey) { Entry entry = (Entry)entryKey; System.String field = entry.field; FloatParser parser = (FloatParser)entry.custom; if (parser == null) { try { return(wrapper.GetFloats(reader, field, Mono.Lucene.Net.Search.FieldCache_Fields.DEFAULT_FLOAT_PARSER)); } catch (System.FormatException ne) { return(wrapper.GetFloats(reader, field, Mono.Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_FLOAT_PARSER)); } } float[] retArray = null; TermDocs termDocs = reader.TermDocs(); TermEnum termEnum = reader.Terms(new Term(field)); try { do { Term term = termEnum.Term(); if (term == null || (System.Object)term.Field() != (System.Object)field) { break; } float termval = parser.ParseFloat(term.Text()); if (retArray == null) { // late init retArray = new float[reader.MaxDoc()]; } termDocs.Seek(termEnum); while (termDocs.Next()) { retArray[termDocs.Doc()] = termval; } }while (termEnum.Next()); } catch (StopFillCacheException stop) { } finally { termDocs.Close(); termEnum.Close(); } if (retArray == null) { // no values retArray = new float[reader.MaxDoc()]; } return(retArray); }
public /*protected internal*/ override bool TermCompare(Term term) { if ((System.Object)term.Field() == (System.Object)prefix.Field() && term.Text().StartsWith(prefix.Text())) { return(true); } endEnum = true; return(false); }
protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey) { System.String field = StringHelper.Intern((System.String)entryKey.field); TermEnum enumerator = reader.Terms(new Term(field)); try { Term term = enumerator.Term(); if (term == null) { throw new System.SystemException("no terms in field " + field + " - cannot determine type"); } System.Object ret = null; if ((System.Object)term.Field() == (System.Object)field) { System.String termtext = term.Text().Trim(); try { System.Int32.Parse(termtext); ret = wrapper.GetInts(reader, field); } catch (System.FormatException nfe1) { try { System.Int64.Parse(termtext); ret = wrapper.GetLongs(reader, field); } catch (System.FormatException nfe2) { try { SupportClass.Single.Parse(termtext); ret = wrapper.GetFloats(reader, field); } catch (System.FormatException nfe3) { ret = wrapper.GetStringIndex(reader, field); } } } } else { throw new System.SystemException("field \"" + field + "\" does not appear to be indexed"); } return(ret); } finally { enumerator.Close(); } }
/// <summary>Prints a user-readable version of this query. </summary> public override System.String ToString(System.String field) { System.Text.StringBuilder buffer = new System.Text.StringBuilder(); if (!term.Field().Equals(field)) { buffer.Append(term.Field()); buffer.Append(":"); } buffer.Append(term.Text()); buffer.Append(ToStringUtils.Boost(GetBoost())); return(buffer.ToString()); }
public /*protected internal*/ override bool TermCompare(Term term) { if ((System.Object) field == (System.Object) term.Field()) { System.String searchText = term.Text(); if (searchText.StartsWith(pre)) { return WildcardEquals(text, 0, searchText, preLen); } } endEnum = true; return false; }
public /*protected internal*/ override bool TermCompare(Term term) { if ((System.Object)field == (System.Object)term.Field()) { System.String searchText = term.Text(); if (searchText.StartsWith(pre)) { return(WildcardEquals(text, 0, searchText, preLen)); } } endEnum = true; return(false); }
public override int DocFreq(Term term) { int df; try { df = ((System.Int32)dfMap[term]); } catch (System.NullReferenceException e) { throw new System.ArgumentException("df for term " + term.Text() + " not available"); } return(df); }
/// <summary> Creates a new <code>WildcardTermEnum</code>. /// <p/> /// After calling the constructor the enumeration is already pointing to the first /// valid term if such a term exists. /// </summary> public WildcardTermEnum(IndexReader reader, Term term):base() { searchTerm = term; field = searchTerm.Field(); System.String searchTermText = searchTerm.Text(); int sidx = searchTermText.IndexOf((System.Char) WILDCARD_STRING); int cidx = searchTermText.IndexOf((System.Char) WILDCARD_CHAR); int idx = sidx; if (idx == - 1) { idx = cidx; } else if (cidx >= 0) { idx = System.Math.Min(idx, cidx); } pre = idx != - 1?searchTerm.Text().Substring(0, (idx) - (0)):""; preLen = pre.Length; text = searchTermText.Substring(preLen); SetEnum(reader.Terms(new Term(searchTerm.Field(), pre))); }
public override System.String ToString(System.String field) { System.Text.StringBuilder buffer = new System.Text.StringBuilder(); if (!term.Field().Equals(field)) { buffer.Append(term.Field()); buffer.Append(":"); } buffer.Append(term.Text()); buffer.Append('~'); buffer.Append(SupportClass.Single.ToString(minimumSimilarity)); buffer.Append(ToStringUtils.Boost(GetBoost())); return(buffer.ToString()); }
/// <summary> Creates a new <code>WildcardTermEnum</code>. /// <p/> /// After calling the constructor the enumeration is already pointing to the first /// valid term if such a term exists. /// </summary> public WildcardTermEnum(IndexReader reader, Term term) : base() { searchTerm = term; field = searchTerm.Field(); System.String searchTermText = searchTerm.Text(); int sidx = searchTermText.IndexOf((System.Char)WILDCARD_STRING); int cidx = searchTermText.IndexOf((System.Char)WILDCARD_CHAR); int idx = sidx; if (idx == -1) { idx = cidx; } else if (cidx >= 0) { idx = System.Math.Min(idx, cidx); } pre = idx != -1?searchTerm.Text().Substring(0, (idx) - (0)):""; preLen = pre.Length; text = searchTermText.Substring(preLen); SetEnum(reader.Terms(new Term(searchTerm.Field(), pre))); }
internal static int DetectFieldType(IndexReader reader, System.String fieldKey) { System.String field = StringHelper.Intern(fieldKey); TermEnum enumerator = reader.Terms(new Term(field)); try { Term term = enumerator.Term(); if (term == null) { throw new System.SystemException("no terms in field " + field + " - cannot determine sort type"); } int ret = 0; if ((System.Object)term.Field() == (System.Object)field) { System.String termtext = term.Text().Trim(); int tmpI32; long tmpI64; float tmpF; if (System.Int32.TryParse(termtext, out tmpI32)) { ret = SortField.INT; } else if (System.Int64.TryParse(termtext, out tmpI64)) { ret = SortField.LONG; } else if (SupportClass.Single.TryParse(termtext, out tmpF)) { ret = SortField.FLOAT; } else { ret = SortField.STRING; } } else { throw new System.SystemException("field \"" + field + "\" does not appear to be indexed"); } return(ret); } finally { enumerator.Close(); } }
protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey) { Entry entry = (Entry)entryKey; System.String field = entry.field; ShortParser parser = (ShortParser)entry.custom; if (parser == null) { return(wrapper.GetShorts(reader, field, Mono.Lucene.Net.Search.FieldCache_Fields.DEFAULT_SHORT_PARSER)); } short[] retArray = new short[reader.MaxDoc()]; TermDocs termDocs = reader.TermDocs(); TermEnum termEnum = reader.Terms(new Term(field)); try { do { Term term = termEnum.Term(); if (term == null || (System.Object)term.Field() != (System.Object)field) { break; } short termval = parser.ParseShort(term.Text()); termDocs.Seek(termEnum); while (termDocs.Next()) { retArray[termDocs.Doc()] = termval; } }while (termEnum.Next()); } catch (StopFillCacheException stop) { } finally { termDocs.Close(); termEnum.Close(); } return(retArray); }
/// <summary> Create a new FuzzyQuery that will match terms with a similarity /// of at least <code>minimumSimilarity</code> to <code>term</code>. /// If a <code>prefixLength</code> > 0 is specified, a common prefix /// of that length is also required. /// /// </summary> /// <param name="term">the term to search for /// </param> /// <param name="minimumSimilarity">a value between 0 and 1 to set the required similarity /// between the query term and the matching terms. For example, for a /// <code>minimumSimilarity</code> of <code>0.5</code> a term of the same length /// as the query term is considered similar to the query term if the edit distance /// between both terms is less than <code>length(term)*0.5</code> /// </param> /// <param name="prefixLength">length of common (non-fuzzy) prefix /// </param> /// <throws> IllegalArgumentException if minimumSimilarity is >= 1 or < 0 </throws> /// <summary> or if prefixLength < 0 /// </summary> public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength):base(term) { // will be removed in 3.0 this.term = term; if (minimumSimilarity >= 1.0f) throw new System.ArgumentException("minimumSimilarity >= 1"); else if (minimumSimilarity < 0.0f) throw new System.ArgumentException("minimumSimilarity < 0"); if (prefixLength < 0) throw new System.ArgumentException("prefixLength < 0"); if (term.Text().Length > 1.0f / (1.0f - minimumSimilarity)) { this.termLongEnough = true; } this.minimumSimilarity = minimumSimilarity; this.prefixLength = prefixLength; rewriteMethod = SCORING_BOOLEAN_QUERY_REWRITE; }
public override Explanation Explain(IndexReader reader, int doc) { Explanation result = new Explanation(); result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:"); System.Text.StringBuilder docFreqs = new System.Text.StringBuilder(); System.Text.StringBuilder query = new System.Text.StringBuilder(); query.Append('\"'); docFreqs.Append(idfExp.Explain()); for (int i = 0; i < Enclosing_Instance.terms.Count; i++) { if (i != 0) { query.Append(" "); } Term term = (Term)Enclosing_Instance.terms[i]; query.Append(term.Text()); } query.Append('\"'); Explanation idfExpl = new Explanation(idf, "idf(" + Enclosing_Instance.field + ":" + docFreqs + ")"); // explain query weight Explanation queryExpl = new Explanation(); queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:"); Explanation boostExpl = new Explanation(Enclosing_Instance.GetBoost(), "boost"); if (Enclosing_Instance.GetBoost() != 1.0f) { queryExpl.AddDetail(boostExpl); } queryExpl.AddDetail(idfExpl); Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm"); queryExpl.AddDetail(queryNormExpl); queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue()); result.AddDetail(queryExpl); // explain field weight Explanation fieldExpl = new Explanation(); fieldExpl.SetDescription("fieldWeight(" + Enclosing_Instance.field + ":" + query + " in " + doc + "), product of:"); Scorer scorer = Scorer(reader, true, false); if (scorer == null) { return(new Explanation(0.0f, "no matching docs")); } Explanation tfExpl = scorer.Explain(doc); fieldExpl.AddDetail(tfExpl); fieldExpl.AddDetail(idfExpl); Explanation fieldNormExpl = new Explanation(); byte[] fieldNorms = reader.Norms(Enclosing_Instance.field); float fieldNorm = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]) : 1.0f; fieldNormExpl.SetValue(fieldNorm); fieldNormExpl.SetDescription("fieldNorm(field=" + Enclosing_Instance.field + ", doc=" + doc + ")"); fieldExpl.AddDetail(fieldNormExpl); fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue()); result.AddDetail(fieldExpl); // combine them result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue()); if (queryExpl.GetValue() == 1.0f) { return(fieldExpl); } return(result); }
public override int DocFreq(Term term) { int df; try { df = ((System.Int32) dfMap[term]); } catch (System.NullReferenceException e) { throw new System.ArgumentException("df for term " + term.Text() + " not available"); } return df; }
/// <summary> Compares if current upper bound is reached, /// this also updates the term count for statistics. /// In contrast to {@link FilteredTermEnum}, a return value /// of <code>false</code> ends iterating the current enum /// and forwards to the next sub-range. /// </summary> //@Override public /*protected internal*/ override bool TermCompare(Term term) { return((System.Object)term.Field() == (System.Object)Enclosing_Instance.field && String.CompareOrdinal(term.Text(), currentUpperBound) <= 0); }
/// <summary>Constructs a query selecting all terms greater than /// <code>lowerTerm</code> but less than <code>upperTerm</code>. /// There must be at least one term and either term may be null, /// in which case there is no bound on that side, but if there are /// two terms, both terms <b>must</b> be for the same field. /// <p/> /// If <code>collator</code> is not null, it will be used to decide whether /// index terms are within the given range, rather than using the Unicode code /// point order in which index terms are stored. /// <p/> /// <strong>WARNING:</strong> Using this constructor and supplying a non-null /// value in the <code>collator</code> parameter will cause every single /// index Term in the Field referenced by lowerTerm and/or upperTerm to be /// examined. Depending on the number of index Terms in this Field, the /// operation could be very slow. /// /// </summary> /// <param name="lowerTerm">The Term at the lower end of the range /// </param> /// <param name="upperTerm">The Term at the upper end of the range /// </param> /// <param name="inclusive">If true, both <code>lowerTerm</code> and /// <code>upperTerm</code> will themselves be included in the range. /// </param> /// <param name="collator">The collator to use to collate index Terms, to determine /// their membership in the range bounded by <code>lowerTerm</code> and /// <code>upperTerm</code>. /// </param> public RangeQuery(Term lowerTerm, Term upperTerm, bool inclusive, System.Globalization.CompareInfo collator) { if (lowerTerm == null && upperTerm == null) throw new System.ArgumentException("At least one term must be non-null"); if (lowerTerm != null && upperTerm != null && (System.Object) lowerTerm.Field() != (System.Object) upperTerm.Field()) throw new System.ArgumentException("Both terms must have the same field"); delegate_Renamed = new TermRangeQuery((lowerTerm == null)?upperTerm.Field():lowerTerm.Field(), (lowerTerm == null)?null:lowerTerm.Text(), (upperTerm == null)?null:upperTerm.Text(), inclusive, inclusive, collator); delegate_Renamed.SetRewriteMethod(TermRangeQuery.SCORING_BOOLEAN_QUERY_REWRITE); }
protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey) { System.String field = StringHelper.Intern((System.String)entryKey.field); int[] retArray = new int[reader.MaxDoc()]; System.String[] mterms = new System.String[reader.MaxDoc() + 1]; TermDocs termDocs = reader.TermDocs(); TermEnum termEnum = reader.Terms(new Term(field)); int t = 0; // current term number // an entry for documents that have no terms in this field // should a document with no terms be at top or bottom? // this puts them at the top - if it is changed, FieldDocSortedHitQueue // needs to change as well. mterms[t++] = null; try { do { Term term = termEnum.Term(); if (term == null || term.Field() != field || t >= mterms.Length) { break; } // store term text mterms[t] = term.Text(); termDocs.Seek(termEnum); while (termDocs.Next()) { retArray[termDocs.Doc()] = t; } t++; }while (termEnum.Next()); } finally { termDocs.Close(); termEnum.Close(); } if (t == 0) { // if there are no terms, make the term array // have a single null entry mterms = new System.String[1]; } else if (t < mterms.Length) { // if there are less terms than documents, // trim off the dead array space System.String[] terms = new System.String[t]; Array.Copy(mterms, 0, terms, 0, t); mterms = terms; } StringIndex value_Renamed = new StringIndex(retArray, mterms); return(value_Renamed); }
public /*protected internal*/ override bool TermCompare(Term term) { if (collator == null) { // Use Unicode code point ordering bool checkLower = false; if (!includeLower) // make adjustments to set to exclusive checkLower = true; if (term != null && (System.Object) term.Field() == (System.Object) field) { // interned comparison if (!checkLower || null == lowerTermText || String.CompareOrdinal(term.Text(), lowerTermText) > 0) { checkLower = false; if (upperTermText != null) { int compare = String.CompareOrdinal(upperTermText, term.Text()); /* * if beyond the upper term, or is exclusive and this is equal to * the upper term, break out */ if ((compare < 0) || (!includeUpper && compare == 0)) { endEnum = true; return false; } } return true; } } else { // break endEnum = true; return false; } return false; } else { if (term != null && (System.Object) term.Field() == (System.Object) field) { // interned comparison if ((lowerTermText == null || (includeLower?collator.Compare(term.Text().ToString(), lowerTermText.ToString()) >= 0:collator.Compare(term.Text().ToString(), lowerTermText.ToString()) > 0)) && (upperTermText == null || (includeUpper?collator.Compare(term.Text().ToString(), upperTermText.ToString()) <= 0:collator.Compare(term.Text().ToString(), upperTermText.ToString()) < 0))) { return true; } return false; } endEnum = true; return false; } }
public PrefixTermEnum(IndexReader reader, Term prefix) { this.prefix = prefix; SetEnum(reader.Terms(new Term(prefix.Field(), prefix.Text()))); }
/// <summary>Constructs a query selecting all terms greater than /// <code>lowerTerm</code> but less than <code>upperTerm</code>. /// There must be at least one term and either term may be null, /// in which case there is no bound on that side, but if there are /// two terms, both terms <b>must</b> be for the same field. /// <p/> /// If <code>collator</code> is not null, it will be used to decide whether /// index terms are within the given range, rather than using the Unicode code /// point order in which index terms are stored. /// <p/> /// <strong>WARNING:</strong> Using this constructor and supplying a non-null /// value in the <code>collator</code> parameter will cause every single /// index Term in the Field referenced by lowerTerm and/or upperTerm to be /// examined. Depending on the number of index Terms in this Field, the /// operation could be very slow. /// /// </summary> /// <param name="lowerTerm">The Term at the lower end of the range /// </param> /// <param name="upperTerm">The Term at the upper end of the range /// </param> /// <param name="inclusive">If true, both <code>lowerTerm</code> and /// <code>upperTerm</code> will themselves be included in the range. /// </param> /// <param name="collator">The collator to use to collate index Terms, to determine /// their membership in the range bounded by <code>lowerTerm</code> and /// <code>upperTerm</code>. /// </param> public RangeQuery(Term lowerTerm, Term upperTerm, bool inclusive, System.Globalization.CompareInfo collator) { if (lowerTerm == null && upperTerm == null) { throw new System.ArgumentException("At least one term must be non-null"); } if (lowerTerm != null && upperTerm != null && (System.Object)lowerTerm.Field() != (System.Object)upperTerm.Field()) { throw new System.ArgumentException("Both terms must have the same field"); } delegate_Renamed = new TermRangeQuery((lowerTerm == null)?upperTerm.Field():lowerTerm.Field(), (lowerTerm == null)?null:lowerTerm.Text(), (upperTerm == null)?null:upperTerm.Text(), inclusive, inclusive, collator); delegate_Renamed.SetRewriteMethod(TermRangeQuery.SCORING_BOOLEAN_QUERY_REWRITE); }
public WildcardQuery(Term term) : base(term) { //will be removed in 3.0 this.term = term; this.termContainsWildcard = (term.Text().IndexOf('*') != -1) || (term.Text().IndexOf('?') != -1); }
/// <summary> The termCompare method in FuzzyTermEnum uses Levenshtein distance to /// calculate the distance between the given term and the comparing term. /// </summary> public /*protected internal*/ override bool TermCompare(Term term) { if ((System.Object) field == (System.Object) term.Field() && term.Text().StartsWith(prefix)) { System.String target = term.Text().Substring(prefix.Length); this.similarity = Similarity(target); return (similarity > minimumSimilarity); } endEnum = true; return false; }
/// <summary> Constructor for enumeration of all terms from specified <code>reader</code> which share a prefix of /// length <code>prefixLength</code> with <code>term</code> and which have a fuzzy similarity > /// <code>minSimilarity</code>. /// <p/> /// After calling the constructor the enumeration is already pointing to the first /// valid term if such a term exists. /// /// </summary> /// <param name="reader">Delivers terms. /// </param> /// <param name="term">Pattern term. /// </param> /// <param name="minSimilarity">Minimum required similarity for terms from the reader. Default value is 0.5f. /// </param> /// <param name="prefixLength">Length of required common prefix. Default value is 0. /// </param> /// <throws> IOException </throws> public FuzzyTermEnum(IndexReader reader, Term term, float minSimilarity, int prefixLength):base() { if (minSimilarity >= 1.0f) throw new System.ArgumentException("minimumSimilarity cannot be greater than or equal to 1"); else if (minSimilarity < 0.0f) throw new System.ArgumentException("minimumSimilarity cannot be less than 0"); if (prefixLength < 0) throw new System.ArgumentException("prefixLength cannot be less than 0"); this.minimumSimilarity = minSimilarity; this.scale_factor = 1.0f / (1.0f - minimumSimilarity); this.searchTerm = term; this.field = searchTerm.Field(); //The prefix could be longer than the word. //It's kind of silly though. It means we must match the entire word. int fullSearchTermLength = searchTerm.Text().Length; int realPrefixLength = prefixLength > fullSearchTermLength?fullSearchTermLength:prefixLength; this.text = searchTerm.Text().Substring(realPrefixLength); this.prefix = searchTerm.Text().Substring(0, (realPrefixLength) - (0)); InitializeMaxDistances(); this.d = InitDistanceArray(); SetEnum(reader.Terms(new Term(searchTerm.Field(), prefix))); }
public WildcardQuery(Term term):base(term) { //will be removed in 3.0 this.term = term; this.termContainsWildcard = (term.Text().IndexOf('*') != - 1) || (term.Text().IndexOf('?') != - 1); }