Guest User

Untitled

a guest
Apr 20th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. --- C:\Users\xyt\AppData\Local\Temp\AnkhSVN\3179\QueryParser.27919.cs 20.04.2012  08:55:36
  2. +++ C:\_VS.NET\se\Lucene-2_9_4\core\QueryParser\QueryParser.cs 17.04.2012  12:25:02
  3.    
  4.         /// <summary> Factory method for generating a query (similar to
  5.         /// <see cref="GetWildcardQuery" />). Called when parser parses an input term
  6.         /// token that uses prefix notation; that is, contains a single '*' wildcard
  7.         /// character as its last character. Since this is a special case
  8.         /// of generic wildcard term, and such a query can be optimized easily,
  9.         /// this usually results in a different query object.
  10.         /// <p/>
  11.         /// Depending on settings, a prefix term may be lower-cased
  12.         /// automatically. It will not go through the default Analyzer,
  13.         /// however, since normal Analyzers are unlikely to work properly
  14.         /// with wildcard templates.
  15.         /// <p/>
  16.         /// Can be overridden by extending classes, to provide custom handling for
  17.         /// wild card queries, which may be necessary due to missing analyzer calls.
  18.         ///
  19.         /// </summary>
  20.         /// <param name="field">Name of the field query will use.
  21.         /// </param>
  22.         /// <param name="termStr">Term token to use for building term for the query
  23.         /// (<b>without</b> trailing '*' character!)
  24.         ///
  25.         /// </param>
  26.         /// <returns> Resulting <see cref="Query" /> built for the term
  27.         /// </returns>
  28.         /// <exception cref="ParseException">throw in overridden method to disallow
  29.         /// </exception>
  30.         public /*protected internal*/ virtual Query GetPrefixQuery(System.String field, System.String termStr)
  31.         {
  32.             if (!allowLeadingWildcard && termStr.StartsWith("*"))
  33.                 throw new ParseException("'*' not allowed as first character in PrefixQuery");
  34.             if (lowercaseExpandedTerms)
  35.             {
  36.                 termStr = termStr.ToLower();
  37.             }
  38. -           Term t = new Term(field, termStr);
  39. +         Term t = null;
  40. +         TermQuery q = null;
  41. +         try
  42. +         {
  43. +            q = GetFieldQuery(field, termStr) as TermQuery;
  44. +         }
  45. +         catch(Exception ex)
  46. +         {
  47. +         }
  48.  
  49. +         if (q != null)
  50. +         {
  51. +            t = new Term(field, q.GetTerm().text);
  52. +         }
  53. +         else
  54. +         {
  55. +            t = new Term(field, termStr);
  56. +         }
  57.             return NewPrefixQuery(t);
  58.         }
Advertisement
Add Comment
Please, Sign In to add comment