示例#1
0
		/// <summary> Returns version-dependent default for enablePositionIncrements. Analyzers
		/// that embed StopFilter use this method when creating the StopFilter. Prior
		/// to 2.9, this returns {@link #getEnablePositionIncrementsDefault}. On 2.9
		/// or later, it returns true.
		/// </summary>
		public static bool GetEnablePositionIncrementsVersionDefault(Version matchVersion)
		{
			if (matchVersion.OnOrAfter(Version.LUCENE_29))
			{
				return true;
			}
			else
			{
				return ENABLE_POSITION_INCREMENTS_DEFAULT;
			}
		}
示例#2
0
 private void  Init(System.IO.TextReader input, Version matchVersion)
 {
     if (matchVersion.OnOrAfter(Version.LUCENE_24))
     {
         Init(input, true);
     }
     else
     {
         Init(input, false);
     }
 }
示例#3
0
        /// <summary> Parses a query, searching on the fields specified. Use this if you need
        /// to specify certain fields as required, and others as prohibited.
        /// <p/>
        ///
        /// <pre>
        /// Usage:
        /// &lt;code&gt;
        /// String[] query = {&quot;query1&quot;, &quot;query2&quot;, &quot;query3&quot;};
        /// String[] fields = {&quot;filename&quot;, &quot;contents&quot;, &quot;description&quot;};
        /// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
        /// BooleanClause.Occur.MUST,
        /// BooleanClause.Occur.MUST_NOT};
        /// MultiFieldQueryParser.parse(query, fields, flags, analyzer);
        /// &lt;/code&gt;
        /// </pre>
        /// <p/>
        /// The code above would construct a query:
        ///
        /// <pre>
        /// &lt;code&gt;
        /// (filename:query1) +(contents:query2) -(description:query3)
        /// &lt;/code&gt;
        /// </pre>
        ///
        /// </summary>
        /// <param name="matchVersion">Lucene version to match; this is passed through to
        /// QueryParser.
        /// </param>
        /// <param name="queries">Queries string to parse
        /// </param>
        /// <param name="fields">Fields to search on
        /// </param>
        /// <param name="flags">Flags describing the fields
        /// </param>
        /// <param name="analyzer">Analyzer to use
        /// </param>
        /// <throws>  ParseException </throws>
        /// <summary>             if query parsing fails
        /// </summary>
        /// <throws>  IllegalArgumentException </throws>
        /// <summary>             if the length of the queries, fields, and flags array differ
        /// </summary>
        public static Query Parse(Version matchVersion, System.String[] queries, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
        {
            if (!(queries.Length == fields.Length && queries.Length == flags.Length))
            {
                throw new System.ArgumentException("queries, fields, and flags array have have different length");
            }
            BooleanQuery bQuery = new BooleanQuery();

            for (int i = 0; i < fields.Length; i++)
            {
                QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
                Query       q  = qp.Parse(queries[i]);
                if (q != null && (!(q is BooleanQuery) || ((BooleanQuery)q).GetClauses().Length > 0))
                {
                    bQuery.Add(q, flags[i]);
                }
            }
            return(bQuery);
        }
示例#4
0
 private void  Init(Version matchVersion)
 {
     SetOverridesTokenStreamMethod(typeof(StandardAnalyzer));
     if (matchVersion.OnOrAfter(Version.LUCENE_29))
     {
         enableStopPositionIncrements = true;
     }
     else
     {
         useDefaultStopPositionIncrements = true;
     }
     if (matchVersion.OnOrAfter(Version.LUCENE_24))
     {
         replaceInvalidAcronym = defaultReplaceInvalidAcronym;
     }
     else
     {
         replaceInvalidAcronym = false;
     }
 }
示例#5
0
 /// <summary> Creates a MultiFieldQueryParser. Allows passing of a map with term to
 /// Boost, and the boost to apply to each term.
 ///
 /// <p/>
 /// It will, when parse(String query) is called, construct a query like this
 /// (assuming the query consists of two terms and you specify the two fields
 /// <code>title</code> and <code>body</code>):
 /// <p/>
 ///
 /// <code>
 /// (title:term1 body:term1) (title:term2 body:term2)
 /// </code>
 ///
 /// <p/>
 /// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
 /// <p/>
 ///
 /// <code>
 /// +(title:term1 body:term1) +(title:term2 body:term2)
 /// </code>
 ///
 /// <p/>
 /// When you pass a boost (title=>5 body=>10) you can get
 /// <p/>
 ///
 /// <code>
 /// +(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)
 /// </code>
 ///
 /// <p/>
 /// In other words, all the query's terms must appear, but it doesn't matter
 /// in what fields they appear.
 /// <p/>
 /// </summary>
 public MultiFieldQueryParser(Version matchVersion, System.String[] fields, Analyzer analyzer, System.Collections.IDictionary boosts) : this(matchVersion, fields, analyzer)
 {
     this.boosts = boosts;
 }
示例#6
0
		/// <summary> Creates a new StandardTokenizer with a given
		/// {@link org.apache.lucene.util.AttributeSource.AttributeFactory}
		/// </summary>
		public StandardTokenizer(Version matchVersion, AttributeFactory factory, System.IO.TextReader input):base(factory)
		{
			InitBlock();
			this.scanner = new StandardTokenizerImpl(input);
			Init(input, matchVersion);
		}
示例#7
0
		private void  Init(System.IO.TextReader input, Version matchVersion)
		{
			if (matchVersion.OnOrAfter(Version.LUCENE_24))
			{
				Init(input, true);
			}
			else
			{
				Init(input, false);
			}
		}
示例#8
0
		/// <summary> Builds an analyzer which removes words in ENGLISH_STOP_WORDS.</summary>
		public StopAnalyzer(Version matchVersion)
		{
			stopWords = ENGLISH_STOP_WORDS_SET;
			useDefaultStopPositionIncrement = false;
			enablePositionIncrements = StopFilter.GetEnablePositionIncrementsVersionDefault(matchVersion);
		}
示例#9
0
		/// <summary> Constructs a query parser.
		/// 
		/// </summary>
		/// <param name="matchVersion">Lucene version to match. See <a href="#version">above</a>)
		/// </param>
		/// <param name="f">the default field for query terms.
		/// </param>
		/// <param name="a">used to find terms in the query text.
		/// </param>
		public QueryParser(Version matchVersion, System.String f, Analyzer a):this(new FastCharStream(new System.IO.StringReader("")))
		{
			analyzer = a;
			field = f;
			if (matchVersion.OnOrAfter(Version.LUCENE_29))
			{
				enablePositionIncrements = true;
			}
			else
			{
				enablePositionIncrements = false;
			}
		}
示例#10
0
		/// <summary>Builds an analyzer with the given stop words.</summary>
		/// <param name="matchVersion">Lucene version to match See {@link
		/// <a href="#version">above</a>}
		/// </param>
		/// <param name="stopWords">stop words 
		/// </param>
		public StandardAnalyzer(Version matchVersion, System.Collections.Hashtable stopWords)
		{
			stopSet = stopWords;
			Init(matchVersion);
		}
示例#11
0
 /// <summary> Creates a new StandardTokenizer with a given
 /// {@link org.apache.lucene.util.AttributeSource.AttributeFactory}
 /// </summary>
 public StandardTokenizer(Version matchVersion, AttributeFactory factory, System.IO.TextReader input) : base(factory)
 {
     InitBlock();
     this.scanner = new StandardTokenizerImpl(input);
     Init(input, matchVersion);
 }
示例#12
0
 /// <summary>Builds an analyzer with the default stop words ({@link
 /// #STOP_WORDS}).
 /// </summary>
 /// <param name="matchVersion">Lucene version to match See {@link
 /// <a href="#version">above</a>}
 /// </param>
 public StandardAnalyzer(Version matchVersion) : this(matchVersion, STOP_WORDS_SET)
 {
 }
示例#13
0
 /// <summary>Builds an analyzer with the stop words from the given reader.</summary>
 /// <seealso cref="WordlistLoader.GetWordSet(Reader)">
 /// </seealso>
 /// <param name="matchVersion">Lucene version to match See {@link
 /// <a href="#version">above</a>}
 /// </param>
 /// <param name="stopwords">Reader to read stop words from
 /// </param>
 public StandardAnalyzer(Version matchVersion, System.IO.TextReader stopwords)
 {
     stopSet = WordlistLoader.GetWordSet(stopwords);
     Init(matchVersion);
 }
示例#14
0
 /// <summary>Builds an analyzer with the stop words from the given reader. </summary>
 /// <seealso cref="WordlistLoader.GetWordSet(Reader)">
 /// </seealso>
 /// <param name="matchVersion">See <a href="#Version">above</a>
 /// </param>
 /// <param name="stopwords">Reader to load stop words from
 /// </param>
 public StopAnalyzer(Version matchVersion, System.IO.TextReader stopwords)
 {
     stopWords = WordlistLoader.GetWordSet(stopwords);
     this.enablePositionIncrements   = StopFilter.GetEnablePositionIncrementsVersionDefault(matchVersion);
     useDefaultStopPositionIncrement = false;
 }
示例#15
0
 /// <summary> Builds an analyzer which removes words in ENGLISH_STOP_WORDS.</summary>
 public StopAnalyzer(Version matchVersion)
 {
     stopWords = ENGLISH_STOP_WORDS_SET;
     useDefaultStopPositionIncrement = false;
     enablePositionIncrements        = StopFilter.GetEnablePositionIncrementsVersionDefault(matchVersion);
 }
示例#16
0
 /// <summary>Builds an analyzer with the stop words from the given set.</summary>
 public StopAnalyzer(Version matchVersion, System.Collections.Hashtable stopWords)
 {
     this.stopWords = stopWords;
     useDefaultStopPositionIncrement = false;
     enablePositionIncrements        = StopFilter.GetEnablePositionIncrementsVersionDefault(matchVersion);
 }
示例#17
0
		private void  Init(Version matchVersion)
		{
			SetOverridesTokenStreamMethod(typeof(StandardAnalyzer));
			if (matchVersion.OnOrAfter(Version.LUCENE_29))
			{
				enableStopPositionIncrements = true;
			}
			else
			{
				useDefaultStopPositionIncrements = true;
			}
			if (matchVersion.OnOrAfter(Version.LUCENE_24))
			{
				replaceInvalidAcronym = defaultReplaceInvalidAcronym;
			}
			else
			{
				replaceInvalidAcronym = false;
			}
		}
示例#18
0
		/// <summary>Builds an analyzer with the stop words from the given reader.</summary>
		/// <seealso cref="WordlistLoader.GetWordSet(Reader)">
		/// </seealso>
		/// <param name="matchVersion">Lucene version to match See {@link
		/// <a href="#version">above</a>}
		/// </param>
		/// <param name="stopwords">Reader to read stop words from 
		/// </param>
		public StandardAnalyzer(Version matchVersion, System.IO.TextReader stopwords)
		{
			stopSet = WordlistLoader.GetWordSet(stopwords);
			Init(matchVersion);
		}
示例#19
0
 /// <summary> Creates a MultiFieldQueryParser.
 ///
 /// <p/>
 /// It will, when parse(String query) is called, construct a query like this
 /// (assuming the query consists of two terms and you specify the two fields
 /// <code>title</code> and <code>body</code>):
 /// <p/>
 ///
 /// <code>
 /// (title:term1 body:term1) (title:term2 body:term2)
 /// </code>
 ///
 /// <p/>
 /// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
 /// <p/>
 ///
 /// <code>
 /// +(title:term1 body:term1) +(title:term2 body:term2)
 /// </code>
 ///
 /// <p/>
 /// In other words, all the query's terms must appear, but it doesn't matter
 /// in what fields they appear.
 /// <p/>
 /// </summary>
 public MultiFieldQueryParser(Version matchVersion, System.String[] fields, Analyzer analyzer) : base(matchVersion, null, analyzer)
 {
     this.fields = fields;
 }
示例#20
0
 /// <summary>Builds an analyzer with the stop words from the given reader. </summary>
 /// <seealso cref="WordlistLoader.GetWordSet(Reader)">
 /// </seealso>
 /// <param name="matchVersion">See <a href="#Version">above</a>
 /// </param>
 /// <param name="stopwords">Reader to load stop words from
 /// </param>
 public StopAnalyzer(Version matchVersion, System.IO.TextReader stopwords)
 {
     stopWords = WordlistLoader.GetWordSet(stopwords);
     this.enablePositionIncrements = StopFilter.GetEnablePositionIncrementsVersionDefault(matchVersion);
     useDefaultStopPositionIncrement = false;
 }
示例#21
0
		/// <summary> Creates a MultiFieldQueryParser. Allows passing of a map with term to
		/// Boost, and the boost to apply to each term.
		/// 
		/// <p/>
		/// It will, when parse(String query) is called, construct a query like this
		/// (assuming the query consists of two terms and you specify the two fields
		/// <code>title</code> and <code>body</code>):
		/// <p/>
		/// 
		/// <code>
		/// (title:term1 body:term1) (title:term2 body:term2)
		/// </code>
		/// 
		/// <p/>
		/// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
		/// <p/>
		/// 
		/// <code>
		/// +(title:term1 body:term1) +(title:term2 body:term2)
		/// </code>
		/// 
		/// <p/>
		/// When you pass a boost (title=>5 body=>10) you can get
		/// <p/>
		/// 
		/// <code>
		/// +(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)
		/// </code>
		/// 
		/// <p/>
		/// In other words, all the query's terms must appear, but it doesn't matter
		/// in what fields they appear.
		/// <p/>
		/// </summary>
		public MultiFieldQueryParser(Version matchVersion, System.String[] fields, Analyzer analyzer, System.Collections.IDictionary boosts):this(matchVersion, fields, analyzer)
		{
			this.boosts = boosts;
		}
示例#22
0
		/// <summary>Builds an analyzer with the default stop words ({@link
		/// #STOP_WORDS}).
		/// </summary>
		/// <param name="matchVersion">Lucene version to match See {@link
		/// <a href="#version">above</a>}
		/// </param>
		public StandardAnalyzer(Version matchVersion):this(matchVersion, STOP_WORDS_SET)
		{
		}
示例#23
0
 /// <summary>Builds an analyzer with the given stop words.</summary>
 /// <param name="matchVersion">Lucene version to match See {@link
 /// <a href="#version">above</a>}
 /// </param>
 /// <param name="stopWords">stop words
 /// </param>
 public StandardAnalyzer(Version matchVersion, System.Collections.Hashtable stopWords)
 {
     stopSet = stopWords;
     Init(matchVersion);
 }
示例#24
0
		/// <summary> Creates a MultiFieldQueryParser.
		/// 
		/// <p/>
		/// It will, when parse(String query) is called, construct a query like this
		/// (assuming the query consists of two terms and you specify the two fields
		/// <code>title</code> and <code>body</code>):
		/// <p/>
		/// 
		/// <code>
		/// (title:term1 body:term1) (title:term2 body:term2)
		/// </code>
		/// 
		/// <p/>
		/// When setDefaultOperator(AND_OPERATOR) is set, the result will be:
		/// <p/>
		/// 
		/// <code>
		/// +(title:term1 body:term1) +(title:term2 body:term2)
		/// </code>
		/// 
		/// <p/>
		/// In other words, all the query's terms must appear, but it doesn't matter
		/// in what fields they appear.
		/// <p/>
		/// </summary>
		public MultiFieldQueryParser(Version matchVersion, System.String[] fields, Analyzer analyzer):base(matchVersion, null, analyzer)
		{
			this.fields = fields;
		}
示例#25
0
		/// <summary> Parses a query, searching on the fields specified. Use this if you need
		/// to specify certain fields as required, and others as prohibited.
		/// <p/>
		/// 
		/// <pre>
		/// Usage:
		/// &lt;code&gt;
		/// String[] query = {&quot;query1&quot;, &quot;query2&quot;, &quot;query3&quot;};
		/// String[] fields = {&quot;filename&quot;, &quot;contents&quot;, &quot;description&quot;};
		/// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
		/// BooleanClause.Occur.MUST,
		/// BooleanClause.Occur.MUST_NOT};
		/// MultiFieldQueryParser.parse(query, fields, flags, analyzer);
		/// &lt;/code&gt;
		/// </pre>
		/// <p/>
		/// The code above would construct a query:
		/// 
		/// <pre>
		/// &lt;code&gt;
		/// (filename:query1) +(contents:query2) -(description:query3)
		/// &lt;/code&gt;
		/// </pre>
		/// 
		/// </summary>
		/// <param name="matchVersion">Lucene version to match; this is passed through to
		/// QueryParser.
		/// </param>
		/// <param name="queries">Queries string to parse
		/// </param>
		/// <param name="fields">Fields to search on
		/// </param>
		/// <param name="flags">Flags describing the fields
		/// </param>
		/// <param name="analyzer">Analyzer to use
		/// </param>
		/// <throws>  ParseException </throws>
		/// <summary>             if query parsing fails
		/// </summary>
		/// <throws>  IllegalArgumentException </throws>
		/// <summary>             if the length of the queries, fields, and flags array differ
		/// </summary>
		public static Query Parse(Version matchVersion, System.String[] queries, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
		{
			if (!(queries.Length == fields.Length && queries.Length == flags.Length))
				throw new System.ArgumentException("queries, fields, and flags array have have different length");
			BooleanQuery bQuery = new BooleanQuery();
			for (int i = 0; i < fields.Length; i++)
			{
				QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
				Query q = qp.Parse(queries[i]);
				if (q != null && (!(q is BooleanQuery) || ((BooleanQuery) q).GetClauses().Length > 0))
				{
					bQuery.Add(q, flags[i]);
				}
			}
			return bQuery;
		}
示例#26
0
		/// <summary>Builds an analyzer with the stop words from the given set.</summary>
		public StopAnalyzer(Version matchVersion, System.Collections.Hashtable stopWords)
		{
			this.stopWords = stopWords;
			useDefaultStopPositionIncrement = false;
			enablePositionIncrements = StopFilter.GetEnablePositionIncrementsVersionDefault(matchVersion);
		}