コード例 #1
0
ファイル: QueryParser.cs プロジェクト: carrie901/mono
		public static void  Main(System.String[] args)
		{
			if (args.Length == 0)
			{
				System.Console.Out.WriteLine("Usage: java Mono.Lucene.Net.QueryParsers.QueryParser <input>");
				System.Environment.Exit(0);
			}
			QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, "field", new Mono.Lucene.Net.Analysis.SimpleAnalyzer());
			Query q = qp.Parse(args[0]);
			System.Console.Out.WriteLine(q.ToString("field"));
		}
コード例 #2
0
ファイル: SearchableIndex.cs プロジェクト: shaias/mono
	Query Parse (string term, string field, bool fuzzy)
	{
		QueryParser parser = new QueryParser (Mono.Lucene.Net.Util.Version.LUCENE_CURRENT,
		                                      field,
		                                      new StandardAnalyzer (Mono.Lucene.Net.Util.Version.LUCENE_CURRENT));
		return parser.Parse (term);
	}
コード例 #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;
		}