mnesia text search ?
Ulf Wiger
ulf@REDACTED
Mon Apr 24 22:34:21 CEST 2006
Den 2006-04-24 17:55:01 skrev ke han <ke.han@REDACTED>:
> yes, thanks...after fixing that syntax error,, I realized my other
> syntax errors ;-). Now that I have a clean compile, I still can't get
> the function to work as expected. Any ideas? I am testing the simple
> case of product:findProduct("name", undefined, undefined). I get back
> an empty list when I know that name matches the regexp of one of the
> fields.
> I am suspicious that the cluase in Fun:
> RecordPattern = Record ->
> is not a valid way to match.
It's valid, but your RecordPattern is an instantiation
of a #product{} record with default values for e.g.
the clientProductId and name attributes. So it will
almost certainly never match what you want.
Beware that the record syntax performs different
functions at instantiation and during pattern match.
When creating a record, omitted attributes get assigned
default values. When using a record pattern in a match,
omitted attributes are ignored. But in your case, you're
testing equality between the Record variable (which is
probably bound to one record) and the RecordPattern
variable, which is bound to another record.
One way to match the Industry and Client values
would be
findProduct(SearchString, Industry, Client) ->
MatchIndustry =
fun(#product{industry = I}) when is_list(Industry) ->
I == Industry;
(_) ->
true
end,
MatchClient =
fun(#product{client = C}) when is_list(Client) ->
C == Client;
(_) ->
true
end,
...,
Fun =
fun(Record, Acc) ->
case (MatchIndustry(Record) orelse
MatchClient(Record)) andalso
SearchStringFun(Record) of
true -> [Record|Acc]
false -> Acc
end
end,
BR,
Ulf W
--
Ulf Wiger
More information about the erlang-questions
mailing list