/// <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; } }
private void Init(System.IO.TextReader input, Version matchVersion) { if (matchVersion.OnOrAfter(Version.LUCENE_24)) { Init(input, true); } else { Init(input, false); } }
/// <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: /// <code> /// String[] query = {"query1", "query2", "query3"}; /// String[] fields = {"filename", "contents", "description"}; /// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD, /// BooleanClause.Occur.MUST, /// BooleanClause.Occur.MUST_NOT}; /// MultiFieldQueryParser.parse(query, fields, flags, analyzer); /// </code> /// </pre> /// <p/> /// The code above would construct a query: /// /// <pre> /// <code> /// (filename:query1) +(contents:query2) -(description:query3) /// </code> /// </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); }
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; } }
/// <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; }
/// <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); }
/// <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); }
/// <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; } }
/// <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); }
/// <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); }
/// <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) { }
/// <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); }
/// <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; }
/// <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); }
/// <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; }
/// <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; }
/// <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) { }
/// <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; }
/// <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: /// <code> /// String[] query = {"query1", "query2", "query3"}; /// String[] fields = {"filename", "contents", "description"}; /// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD, /// BooleanClause.Occur.MUST, /// BooleanClause.Occur.MUST_NOT}; /// MultiFieldQueryParser.parse(query, fields, flags, analyzer); /// </code> /// </pre> /// <p/> /// The code above would construct a query: /// /// <pre> /// <code> /// (filename:query1) +(contents:query2) -(description:query3) /// </code> /// </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; }