Example usage for org.apache.lucene.queryparser.flexible.core QueryNodeParseException getLocalizedMessage

List of usage examples for org.apache.lucene.queryparser.flexible.core QueryNodeParseException getLocalizedMessage

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.flexible.core QueryNodeParseException getLocalizedMessage.

Prototype

@Override
    public String getLocalizedMessage() 

Source Link

Usage

From source file:de.walware.statet.r.internal.core.rhelp.index.SearchQuery.java

License:Open Source License

public static SearchQuery compile(final RHelpSearchQuery query) throws CoreException {
    try {//from   w w  w.  j av a2  s  .  co m
        final BooleanQuery q = new BooleanQuery();
        q.add(REnvIndexReader.DOCTYPE_PAGE_QUERY, Occur.MUST);
        String[] fieldNames = NO_FIELDS;
        if (query.getSearchString().length() > 0) {
            switch (query.getSearchType()) {
            case RHelpSearchQuery.TOPIC_SEARCH:
                fieldNames = TOPIC_SEARCH_FIELDS;
                q.add(createMainQuery(fieldNames, query.getSearchString()), Occur.MUST);
                break;
            case RHelpSearchQuery.FIELD_SEARCH:
                fieldNames = sortFields(query.getEnabledFields());
                if (fieldNames.length == 0) {
                    break;
                }
                q.add(createMainQuery(fieldNames, query.getSearchString()), Occur.MUST);
                break;
            case RHelpSearchQuery.DOC_SEARCH:
                fieldNames = DOC_SEARCH_FIELDS;
                q.add(createMainQuery(fieldNames, query.getSearchString()), Occur.MUST);
                break;
            default:
                break;
            }
        }

        final List<String> keywords = query.getKeywords();
        if (!keywords.isEmpty()) {
            q.add(createOrQuery(KEYWORD_FIELD_NAME, keywords), Occur.MUST);
        }
        final List<String> packages = query.getPackages();
        if (!packages.isEmpty()) {
            q.add(createOrQuery(PACKAGE_FIELD_NAME, packages), Occur.MUST);
        }

        return new SearchQuery(fieldNames, q);
    } catch (final QueryNodeParseException e) {
        RCorePlugin.log(new Status(IStatus.ERROR, RCore.PLUGIN_ID, -1,
                NLS.bind("An error occurred when creating the Lucene query for: {0}.", //$NON-NLS-1$
                        query.toString()),
                e));
        throw new CoreException(new Status(IStatus.ERROR, RCore.PLUGIN_ID, -1,
                "The search string is invalid: " + e.getLocalizedMessage(), null));
    } catch (final Exception e) {
        RCorePlugin.log(new Status(IStatus.ERROR, RCore.PLUGIN_ID, -1,
                NLS.bind("An error occurred when creating the Lucene query for {0}.", //$NON-NLS-1$
                        query.toString()),
                e));
        throw new CoreException(new Status(IStatus.ERROR, RCore.PLUGIN_ID, -1,
                "An error occurred when preparing the R help query.", null));
    }
}