%% -------------------------------------------------------------------
%%
%% Copyright (c) 2007-2010 Basho Technologies, Inc.  All Rights Reserved.
%%
%% -------------------------------------------------------------------

-module(lucene_parser).
-export([parse/3]).
-include("lucene_parser.hrl").

%% @doc Parse a given query string into a query graph. The query graph
%% consists of a nested set of Erlang records found in lucene_parser.hrl.
parse(DefaultIndex, DefaultField, QueryString) when is_list(DefaultIndex) andalso is_list(DefaultField) andalso is_list(QueryString) ->
    case lucene_scan:string(QueryString) of
        {ok, Tokens, 1} -> 
            case lucene_parse:parse(Tokens) of
                {ok, QueryGraph} -> 
                    %% Success case.
                    QueryGraph1 = #scope { index=DefaultIndex, field=DefaultField, ops=QueryGraph },
                    {ok, QueryGraph1};
                {error, {_, lucene_parse, String}} ->
                    %% Syntax error.
                    {error, {lucene_parse, lists:flatten(String)}};
                {error, Error} -> 
                    %% Other parsing error.
                    {error, Error}
            end;
        {error, Error} ->
            %% Scanning error.
            {error, Error}
    end.



%% -------------------------------------------------------------------
%%
%% Copyright (c) 2007-2010 Basho Technologies, Inc.  All Rights Reserved.
%%
%% -------------------------------------------------------------------

-module(lucene_parser).
-export([parse/3]).
-include("lucene_parser.hrl").

%% @doc Parse a given query string into a query graph. The query graph
%% consists of a nested set of Erlang records found in lucene_parser.hrl.
parse(DefaultIndex, DefaultField, QueryString) when is_list(DefaultIndex) andalso is_list(DefaultField) andalso is_list(QueryString) ->
    case lucene_scan:string(QueryString) of
        {ok, Tokens, 1} -> 
            case lucene_parse:parse(Tokens) of
                {ok, QueryGraph} -> 
                    %% Success case.
                    QueryGraph1 = #scope { index=DefaultIndex, field=DefaultField, ops=QueryGraph },
                    {ok, QueryGraph1};
                {error, {_, lucene_parse, String}} ->
                    %% Syntax error.
                    {error, {lucene_parse, lists:flatten(String)}};
                {error, Error} -> 
                    %% Other parsing error.
                    {error, Error}
            end;
        {error, Error} ->
            %% Scanning error.
            {error, Error};
        {error, Error, _} ->
            %% Scanning error.
            {error, Error}
    end.



Add error handling clause to catch error triplets returned from lucene_scan.
Add error handling clause to catch error triplets returned from lucene_scan.

Fixes: az775

The lucene_parser module only expects errors of the form {error, Reason}
from calling lucene_scan:string, but it can return errors of the form
{error, Reason, Line} and the lack of handling of errors of this form
is causing test failures of the basho_expect cluster membership test.
This change adds a case clause to handle those errors.
