mnesia text search ?
Ulf Wiger (AL/EAB)
ulf.wiger@REDACTED
Mon Apr 24 17:24:02 CEST 2006
Aren't you missing an 'end' to close the
SearchString = case ... construct?
BR,
Ulf W
> -----Original Message-----
> From: ke han [mailto:ke.han@REDACTED]
> Sent: den 24 april 2006 16:56
> To: Ulf Wiger (AL/EAB)
> Cc: erlang-questions@REDACTED
> Subject: Re: mnesia text search ?
>
> I have coded the following, which has a compile error (I
> can't seem to find it). erlc reports the error as being
> syntax error before:
> '.' on the last line.
> Any ideas on the error as well as if this code is an
> acceptable way to solve my search problem?
> thanks, ke han
>
> findProduct(SearchString, Industry, Client) ->
> RecordPattern = case {Industry, Client} of
> {undefined, undefined}
> ->
> Product#product{};
> {Industry, undefined} when list(Industry)
> ->
> Product#product{industry = Industry};
> {undefined, Client} when list(Client)
> ->
> Product#product{client = Client};
> {Industry, Client} when list(Industry),
> list(Client) ->
> Product#product{industry = Industry,
> client = Client}
> end,
>
> SearchStringFun = case SearchString of
> undefined
> ->
> fun(Product) ->
> true end;
> SearchString when list(SearchString) ->
> {ok, RegExp} = regexp:parse(SearchString),
> fun(Product#product{clientProductId =
> ClientProductId, name = Name, description = Description}) ->
> case
> regexp:first_match(ClientProductId, RegExp) of
> {match, _} -> true;
> _ ->
> case
> regexp:first_match(Name, RegExp) of
> {match, _} -> true;
> _ ->
> case
> regexp:first_match(Description, RegExp) of
> {match, _} -> true;
> _
> -> false
> end
> end
> end
> end,
>
> Fun =
> fun(Record, NewAcc) when Record = RecordPattern ->
> case SearchStringFun(Record) of
> true -> [Record | NewAcc];
> _ -> NewAcc
> end;
> (_, NewAcc) -> NewAcc
> end,
> mnesia:foldl(Fun, [], product).
>
>
>
>
More information about the erlang-questions
mailing list