QueryBuilder.java revision 986
* See LICENSE.txt included in this distribution for the specific * language governing permissions and limitations under the License. * When distributing Covered Code, include this CDDL HEADER in each * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * Copyright 2010 Sun Micosystems. All rights reserved. * Use is subject to license terms. * Helper class that builds a Lucene query based on provided search terms * for the different fields. * A map containing the query text for each field. (We use a sorted map * here only because we have tests that check the generated query string. * If we had used a hash map, the order of the terms could have varied * between platforms and it would be harder to test.) /** Set search string for the "full" field. */ /** Set search string for the "defs" field. */ /** Set search string for the "refs" field. */ /** Set search string for the "path" field. */ /** Set search string for the "hist" field. */ * Get a map containing the query text for each of the fields that have * Build a query based on the query text that has been passed in to this * @return a query, or {@code null} if no query text has been set * @throws ParseException if the query text cannot be parsed // We don't have any text to parse // Parse each of the query texts separately // If we only have one sub-query, return it directly // We have multiple subqueries, so let's combine them into a // If the subquery is a BooleanQuery, we pull out each clause and // add it to the outer BooleanQuery so that any negations work on // the query as a whole. One exception to this rule: If the query // contains one or more Occur.SHOULD clauses and no Occur.MUST // clauses, we keep it in a subquery so that the requirement that // at least one of the Occur.SHOULD clauses must match (pulling them // out would make all of them optional). // All other types of subqueries are added directly to the outer // query with Occur.MUST. * Add query text for the specified field. * @param field the field to add query text for * @param query the query text * Escape special characters in a query string. * @param field the field for which the query string is provided * @param query the query string * @return the escaped query string // The free text field may contain terms qualified with other // field names, so we don't escape single colons. // Other fields shouldn't use qualified terms, so escape colons // so that we can search for them. * Build a subquery against one of the fields. * @param field the field to build the query against * @param queryText the query text * @throws ParseException if the query text cannot be parsed * Check if a BooleanQuery contains a clause of a given occur type. * @param query the query to check * @param occur the occur type to check for * @return whether or not the query contains a clause of the specified type