Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.apache.lucene.queryparsers;
import java.util.Map;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.Version;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class HebrewMultiFieldQueryParser extends MultiFieldQueryParser
{
HebrewMultiFieldQueryParser(Version matchVersion, String[] fields, Analyzer analyzer)
{
super(matchVersion, fields, analyzer);
}
HebrewMultiFieldQueryParser(Version matchVersion, String[] fields, Analyzer analyzer, Map boosts)
{
super(matchVersion, fields, analyzer, boosts);
}
/// Parses a query, searching on the fields specified. Use this if you need
/// to specify certain fields as required, and others as prohibited.
///
///
///
///
///
/// Lucene version to match; this is passed through to
/// QueryParser.
///
/// Query string to parse
///
/// Fields to search on
///
/// Flags describing the fields
///
/// Analyzer to use
///
/// ParseException
/// if query parsing fails
///
/// IllegalArgumentException
/// if the length of the fields array differs from the length of
/// the flags array
///
public static Query parse(Version matchVersion, String query, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException
{
if (fields.length > flags.length)
throw new IllegalArgumentException("fields.length != flags.length");
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.length; i++)
{
QueryParser qp = new HebrewQueryParser(matchVersion, fields[i], analyzer);
Query q = qp.parse(query);
if (q != null && (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length > 0))
{
bQuery.add(q, flags[i]);
}
}
return bQuery;
}
/// Parses a query which searches on the fields specified.
///
/// If x fields are specified, this effectively constructs:
///
///
///
///
/// Lucene version to match; this is passed through to
/// QueryParser.
///
/// Queries strings to parse
///
/// Fields to search on
///
/// Analyzer to use
///
/// ParseException
/// if query parsing fails
///
/// IllegalArgumentException
/// if the length of the queries array differs from the length of
/// the fields array
///
public static Query parse(Version matchVersion, String[] queries, String[] fields, Analyzer analyzer) throws ParseException
{
if (queries.length != fields.length)
throw new IllegalArgumentException("queries.length != fields.length");
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.length; i++)
{
QueryParser qp = new HebrewQueryParser(matchVersion, fields[i], analyzer);
Query q = qp.parse(queries[i]);
if (q != null && (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length > 0))
{
bQuery.add(q, BooleanClause.Occur.SHOULD);
}
}
return bQuery;
}
/// Parses a query, searching on the fields specified. Use this if you need
/// to specify certain fields as required, and others as prohibited.
///
///
///
///
///
/// Lucene version to match; this is passed through to
/// QueryParser.
///
/// Queries string to parse
///
/// Fields to search on
///
/// Flags describing the fields
///
/// Analyzer to use
///
/// ParseException
/// if query parsing fails
///
/// IllegalArgumentException
/// if the length of the queries, fields, and flags array differ
///
public static Query parse(Version matchVersion, String[] queries, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException
{
if (!(queries.length == fields.length && queries.length == flags.length))
throw new IllegalArgumentException("queries, fields, and flags array have have different length");
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.length; i++)
{
QueryParser qp = new HebrewQueryParser(matchVersion, fields[i], analyzer);
Query q = qp.parse(queries[i]);
if (q != null && (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length > 0))
{
bQuery.add(q, flags[i]);
}
}
return bQuery;
}
}