mnesia text search ?
ke han
ke.han@REDACTED
Mon Apr 24 16:55:34 CEST 2006
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