anchor.diff:  
   -spec query_product(Cont, Id, Name, Offer, SDT, EDT, Service) -> Result
   	when
  -		Cont :: start | eof | any(),
  -		Id :: string() | undefined | '_',
  -		Name :: string() | undefined | '_',
  -		Offer :: string() | undefined | '_',
  -		SDT :: pos_integer() | undefined | '_',
  -		EDT :: pos_integer() | undefined | '_',
  -		Service :: binary() | string() | undefined | '_',
  -		Result :: {Cont, [#product{}]} | {error, Reason},
  +		Cont :: start | any(),
  +		Id ::  Match,
  +		Name ::  Match,
  +		Offer ::  Match,
  +		SDT ::  Match,
  +		EDT ::  Match,
  +		Service ::  Match,
  +		Match :: {exact, string()} | {notexact, string()} | {like, string()} | '_',
  +		Result :: {Cont, [#product{}]} | eof | {error, Reason},
   		Reason :: term().
   %% @doc Query product
  -query_product(Cont, Id, Name, Offer, SDT, EDT, undefined) ->
  -	query_product(Cont, Id, Name, Offer, SDT, EDT, '_');
  -query_product(Cont, Id, Name, Offer, SDT, undefined, Service) ->
  -	query_product(Cont, Id, Name, Offer, SDT, '_', Service);
  -query_product(Cont, Id, Name, Offer, undefined, EDT, Service) ->
  -	query_product(Cont, Id, Name, Offer, '_', EDT, Service);
  -query_product(Cont, Id, Name, undefined, SDT, EDT, Service) ->
  -	query_product(Cont, Id, Name, '_', SDT, EDT, Service);
  -query_product(Cont, Id, undefined, Offer, SDT, EDT, Service) ->
  -	query_product(Cont, Id, '_', Offer, SDT, EDT, Service);
  -query_product(Cont, undefined, Name, Offer, SDT, EDT, Service) ->
  -	query_product(Cont, '_', Name, Offer, SDT, EDT, Service);
  -query_product(Cont, Id, Name, Offer, SDT, EDT, Service) when is_binary(Service)->
  -	query_product(Cont, Id, Name, Offer, SDT, EDT, binary_to_list(Service));
  -query_product(start, Id, Name, Offer, SDT, EDT, Service) ->
  -	MatchSpec = [{'_', [], ['$_']}],
  -	F = fun F(start, Acc) ->
  -				F(mnesia:select(product, MatchSpec,
  -						?CHUNKSIZE, read), Acc);
  -			F('$end_of_table', Acc) ->
  -				lists:flatten(lists:reverse(Acc));
  -			F({error, Reason}, _Acc) ->
  -				{error, Reason};
  -			F({Products, Cont}, Acc) ->
  -				F(mnesia:select(Cont), [Products | Acc])
  -	end,
  -	case mnesia:transaction(F, [start, []]) of
  -		{aborted, Reason} ->
  +query_product(Cont, '_', '_', '_', '_', '_', Service) ->
  +	query_product7(Cont, Service, #product{_ = '_'}, []);
  +query_product(Cont, Id, Name, Offer, SDT, EDT, Service) ->
  +	MatchHead = #product{_ = '_'},
  +	query_product2(Cont, Id, Name, Offer, SDT,
  +			EDT, Service, MatchHead, []).
  +%% @hidden
  +query_product1(String) ->
  +	case lists:last(String) of
  +		$% ->
  +			lists:droplast(String) ++ '_';
  +		_ ->
  +			String
  +	end.
  +%% @hidden
  +query_product2(Cont, '_', Name, Offer, SDT, EDT, Service, MatchHead, MatchCondition) ->
  +	query_product3(Cont, Name, Offer, SDT, EDT, Service, MatchHead, MatchCondition);
  +query_product2(Cont, {like, Id}, Name, Offer, SDT, EDT, Service, MatchHead, MatchCondition) ->
  +	Id1 = query_product1(Id),
  +	MatchHead1 = MatchHead#product{id = Id1},
  +	query_product3(Cont, Name, Offer, SDT, EDT, Service,
  +			MatchHead1, MatchCondition);
  +query_product2(Cont, MatchId, Name, Offer, SDT, EDT, Service, MatchHead, MatchCondition) ->
  +	MatchCondition1 = [match_condition('$1', MatchId) | MatchCondition],
  +	MatchHead1 = MatchHead#product{id = '$1'},
  +	query_product3(Cont, Name, Offer, SDT, EDT, Service, MatchHead1, MatchCondition1).
  +%% @hidden
  +query_product3(Cont, '_', Offer, SDT, EDT, Service, MatchHead, MatchCondition) ->
  +	query_product4(Cont, Offer, SDT, EDT, Service, MatchHead, MatchCondition);
  +query_product3(Cont, {like, Name}, Offer, SDT, EDT, Service, MatchHead, MatchCondition) ->
  +	Name1 = query_product1(Name),
  +	MatchHead1 = MatchHead#product{name = Name1},
  +	query_product4(Cont, Offer, SDT, EDT, Service, MatchHead1, MatchCondition);
  +query_product3(Cont, MatchName, Offer, SDT, EDT, Service, MatchHead, MatchCondition) ->
  +	MatchCondition1 = [match_condition('$2', MatchName) | MatchCondition],
  +	MatchHead1 = MatchHead#product{name = '$2'},
  +	query_product4(Cont, Offer, SDT, EDT, Service, MatchHead1, MatchCondition1).
  +%% @hidden
  +query_product4(Cont, '_', SDT, EDT, Service, MatchHead, MatchCondition) ->
  +	query_product5(Cont, SDT, EDT, Service, MatchHead, MatchCondition);
  +query_product4(Cont, {like, Offer}, SDT, EDT, Service, MatchHead, MatchCondition) ->
  +	Offer1 = query_product1(Offer),
  +	MatchHead1 = MatchHead#product{product = Offer1},
  +	query_product5(Cont, SDT, EDT, Service, MatchHead1, MatchCondition);
  +query_product4(Cont, MatchOffer, SDT, EDT, Service, MatchHead, MatchCondition) ->
  +	MatchCondition1 = [match_condition('$3', MatchOffer) | MatchCondition],
  +	MatchHead1 = MatchHead#product{product = '$3'},
  +	query_product5(Cont, SDT, EDT, Service, MatchHead1, MatchCondition1).
  +%% @hidden
  +query_product5(Cont, '_', EDT, Service, MatchHead, MatchCondition) ->
  +	query_product6(Cont, EDT, Service, MatchHead, MatchCondition);
  +query_product5(Cont, {like, SDT}, EDT, Service, MatchHead, MatchCondition) ->
  +	SDT1 = query_product1(SDT),
  +	MatchHead1 = MatchHead#product{start_date = SDT1},
  +	query_product6(Cont, EDT, Service, MatchHead1, MatchCondition);
  +query_product5(Cont, MatchSDT, EDT, Service, MatchHead, MatchCondition) ->
  +	MatchCondition1 = [match_condition('$4', MatchSDT) | MatchCondition],
  +	MatchHead1 = MatchHead#product{start_date = '$4'},
  +	query_product6(Cont, EDT, Service, MatchHead1, MatchCondition1).
  +%% @hidden
  +query_product6(Cont, '_', Service, MatchHead, MatchCondition) ->
  +	query_product7(Cont, Service, MatchHead, MatchCondition);
  +query_product6(Cont, {like, EDT}, Service, MatchHead, MatchCondition) ->
  +	EDT1 = query_product1(EDT),
  +	MatchHead1 = MatchHead#product{end_date = EDT1},
  +	query_product7(Cont, Service, MatchHead1, MatchCondition);
  +query_product6(Cont, MatchEDT, Service, MatchHead, MatchCondition) ->
  +	MatchCondition1 = [match_condition('$5', MatchEDT) | MatchCondition],
  +	MatchHead1 = MatchHead#product{end_date = '$5'},
  +	query_product7(Cont, Service, MatchHead1, MatchCondition1).
  +%% @hidden
  +query_product7(start, Service, MatchHead, MatchCondition) ->
  +	MatchSpec = [{MatchHead, MatchCondition, ['$_']}],
  +erlang:display({?MODULE, ?LINE, MatchSpec}),
  +	F = fun() -> mnesia:select(product, MatchSpec, ?CHUNKSIZE, read) end,
  +	case mnesia:ets(F) of
  +		{'EXIT', Reason} ->
   			{error, Reason};
  -		{atomic, Products1} ->
  -			Products2 = query_product1(Products1, Id, Name,
  -					Offer, SDT, EDT, Service),
  -			{eof, Products2}
  -	end.
  -%% @hidden
  -query_product1(Products, '_', Name, Offer, SDT, EDT, Service) ->
  -	query_product2(Products, Name, Offer, SDT, EDT, Service);
  -query_product1(Products, Id, Name, Offer, SDT, EDT, Service) ->
  -	F = fun(#product{id = Id1}) when is_list(Id1)->
  -				lists:prefix(Id, Id1);
  -		(_) ->
  -			false
  -	end,
  -	NewProducts = lists:filter(F, Products),
  -	query_product2(NewProducts, Name, Offer, SDT, EDT, Service).
  -%% @hidden
  -query_product2(Products, '_', Offer, SDT, EDT, Service) ->
  -	query_product3(Products, Offer, SDT, EDT, Service);
  -query_product2(Products, Name, Offer, SDT, EDT, Service) ->
  -	F = fun(#product{name = Name1}) when is_list(Name1)->
  -				lists:prefix(Name, Name1);
  -			(_) ->
  -				false
  -	end,
  -	NewProducts = lists:filter(F, Products),
  -	query_product3(NewProducts, Offer, SDT, EDT, Service).
  -%% @hidden
  -query_product3(Products, '_', SDT, EDT, Service) ->
  -	query_product4(Products, SDT, EDT, Service);
  -query_product3(Products, Offer, SDT, EDT, Service) ->
  -	F = fun(#product{product = Offer1}) when is_list(Offer1)->
  -				lists:prefix(Offer, Offer1);
  -		(_) ->
  -			false
  -	end,
  -	NewProducts = lists:filter(F, Products),
  -	query_product4(NewProducts, SDT, EDT, Service).
  -%% @hidden
  -query_product4(Products, '_', '_', Service) ->
  -	query_product5(Products, Service);
  -query_product4(Products, SDT, '_', Service) when is_integer(SDT) ->
  -	F = fun(#product{start_date = SDT1}) when SDT1 >= SDT -> true; (_) -> false end,
  -	NewProducts = lists:filter(F, Products),
  -	query_product5(NewProducts, Service);
  -query_product4(Products, '_', EDT, Service) when is_integer(EDT) ->
  -	F = fun(#product{end_date = EDT1}) when EDT1 =< EDT -> true; (_) -> false end,
  -	NewProducts = lists:filter(F, Products),
  -	query_product5(NewProducts, Service).
  -%% @hidden
  -query_product5(Products, '_') ->
  -	Products;
  -query_product5(Products, Service) ->
  -	F = fun(#product{service = Services} = P, AccIn) ->
  -			F2 = fun(S) when is_binary(S) ->
  -						lists:prefix(Service, binary_to_list(S));
  -					(S) when is_list(S) ->
  -						lists:prefix(Service, S)
  -			end,
  -			case lists:any(F2, Services) of
  -				true ->
  -					[P | AccIn];
  -				false ->
  -					AccIn
  -			end
  -	end,
  -	lists:foldl(F, [], Products).
  +		{Products, Cont} ->
  +			query_product8(Service, Cont, Products);
  +		'$end_of_table' ->
  +			eof
  +	end;
  +query_product7(Cont, Service, MatchHead, MatchCondition) ->
  +	MatchSpec = [{MatchHead, MatchCondition, ['$_']}],
  +	F = fun() -> mnesia:select(Cont, MatchSpec) end,
  +	case mnesia:ets(F) of
  +		{Cont, Products} ->
  +			query_product8(Service, Cont, Products);
  +		eof ->
  +			eof;
  +		{'EXIT', Reason} ->
  +			{error, Reason}
  +	end.
  +%% @hidden
  +query_product8('_', Cont, Products) ->
  +	{Cont, Products};
  +query_product8({Operator, Service}, Cont, Products) ->
  +	F = fun(#product{service = Services}) ->
  +				Services1 = [binary_to_list(S1) || S1 <- Services],
  +
  +				lists:any(fun(S2) -> match(Operator, Service, S2) end, Services1)
  +	end,
  +	{Cont, lists:filter(F, Products)}.
   
   -spec add_product(Offer, ServiceRefs) -> Result
   	when
  
positive.code: 
  -spec query_bucket(Cont, Id, Product) -> Result
  	when
  		Cont :: start | eof | any(),
  		Id :: string() | undefined | '_',
  		Product :: string() | undefined | '_',
  		Result :: {Cont, [#bucket{}]} | {error, Reason},
  		Reason :: term().
  %% @doc Query bucket
  query_bucket(Cont, Id, undefined) ->
  	query_bucket(Cont, Id, '_');
  query_bucket(Cont, undefined, Product) ->
  	query_bucket(Cont, '_', Product);
  query_bucket(start, Id, Product) ->
  	MatchSpec = [{'_', [], ['$_']}],
  	F = fun F(start, Acc) ->
  				F(mnesia:select(bucket, MatchSpec,
  						?CHUNKSIZE, read), Acc);
  			F('$end_of_table', Acc) ->
  				lists:flatten(lists:reverse(Acc));
  			F({error, Reason}, _Acc) ->
  				{error, Reason};
  			F({Services, Cont}, Acc) ->
  				F(mnesia:select(Cont), [Services | Acc])
  	end,
  	case mnesia:transaction(F, [start, []]) of
  		{aborted, Reason} ->
  			{error, Reason};
  		{atomic, Buckets} ->
  			{eof, query_bucket1(Id, Product, Buckets)}
  	end.
  %% @hidden
  query_bucket1('_', Product, Buckets) ->
  	query_bucket2(Product, Buckets);
  query_bucket1(Id, Product, Buckets) ->
  	F = fun(#bucket{id = Id1}) -> lists:prefix(Id, Id1) end,
  	NewBuckets = lists:filter(F, Buckets),
  	query_bucket2(Product, NewBuckets).
  %% @hidden
  query_bucket2('_', Buckets) ->
  	Buckets;
  query_bucket2(Product, Buckets) ->
  	F1 = fun(#bucket{product = Products}) ->
  		F2 = fun(Product1) -> lists:prefix(Product, Product1) end,
  		lists:any(F2, Products)
  	end,
  	lists:filter(F1, Buckets).
  
  -spec delete_bucket(BucketId) -> ok
  	when
  
negative.code: 
  -spec query_offer(Cont, Name, Description, Status, SDT, EDT, Price) -> Result
  	when
  		Cont :: start | any(),
  		Name :: Match,
  		Description :: Match,
  		Status :: Match,
  		SDT :: Match,
  		EDT:: Match,
  		Price :: Match,
  		Match :: {exact, string()} | {notexact, string()} | {like, string()} | '_',
  		Result :: {Cont, [#offer{}]} | eof | {error, Reason},
  		Reason :: term().
  %% @doc Query offer entires
  query_offer(Con, '_', '_', Status, STD, EDT, Price) ->
  	query_offer4(Con, Status, STD, EDT, Price, #offer{_ = '_'}, []);
  query_offer(Con, Name, Description, Status, STD, EDT, Price) ->
  	query_offer2(Con, Name, Description, Status, STD, EDT, Price, #offer{_ = '_'}, []).
  %% @hidden
  query_offer1(String) ->
  	case lists:last(String) of
  		$% ->
  			lists:droplast(String) ++ '_';
  		_ ->
  			String
  	end.
  query_offer2(Con, '_', Description, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	query_offer3(Con, Description, Status, STD, EDT, Price, MatchHead, MatchConditions);
  query_offer2(Con, {like, Name}, Description, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	Name1 = query_offer1(Name),
  	MatchHead1 = MatchHead#offer{name = Name1},
  	query_offer3(Con, Description, Status, STD, EDT, Price, MatchHead1, MatchConditions);
  query_offer2(Con, MatchName, Description, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	MatchConditions1 = [match_condition('$1', MatchName) | MatchConditions],
  	MatchHead1 = MatchHead#offer{name = '$1'},
  	query_offer3(Con, Description, Status, STD, EDT, Price, MatchHead1, MatchConditions1).
  %% @hidden
  query_offer3(Con, '_', Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	query_offer4(Con, Status, STD, EDT, Price, MatchHead, MatchConditions);
  query_offer3(Con, {like, Description}, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	Des = query_offer1(Description),
  	MatchHead1 = MatchHead#offer{description = Des},
  	query_offer4(Con, Status, STD, EDT, Price, MatchHead1, MatchConditions);
  query_offer3(Con, MatchDescription, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	MatchConditions1 = [match_condition('$2', MatchDescription) | MatchConditions],
  	MatchHead1 = MatchHead#offer{name = '$3'},
  	query_offer4(Con, Status, STD, EDT, Price, MatchHead1, MatchConditions1).
  %% @hidden
  query_offer4(start, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	MatchSpec = [{MatchHead, MatchConditions, ['$_']}],
  	F = fun() -> mnesia:select(offer, MatchSpec, ?CHUNKSIZE, read) end,
  	case mnesia:ets(F) of
  		{'EXIT', Reason} ->
  			{error, Reason};
  		{Offers, Cont} ->
  			query_offer5(Status, STD, EDT, Price, Cont, Offers);
  		'$end_of_table' ->
  			eof
  	end;
  query_offer4(Con, Status, STD, EDT, Price, _MatchHead, _MatchConditions) ->
  	F = fun() -> mnesia:select(Con) end,
  	case mnesia:ets(F) of
  		{'EXIT', Reason} ->
  			{error, Reason};
  		{Offers, Cont} ->
  			query_offer5(Status, STD, EDT, Price, Cont, Offers);
  		'$end_of_table' ->
  			eof
  	end.
  %% @hidden
  query_offer5('_', STD, EDT, Price, Cont, Offers) ->
  	query_offer6(STD, EDT, Price, Cont, Offers);
  query_offer5({Operator, Status}, STD, EDT, Price, Cont, Offers) ->
  	F = fun(#offer{status = Status1}) ->
  			Status2 = atom_to_list(Status1),
  			match(Operator, Status, Status2)
  	end,
  	NewOffers = lists:filter(F, Offers),
  	query_offer6(STD, EDT, Price, Cont, NewOffers).
  %% @hidden
  query_offer6('_', EDT, Price, Cont, Offers) ->
  	query_offer7(EDT, Price, Cont, Offers);
  query_offer6({Operator, STD}, EDT, Price, Cont, Offers) ->
  	F = fun(#offer{start_date = STD1}) when is_integer(STD1) ->
  			SDT2 = integer_to_list(STD1),
  			match(Operator, STD, SDT2);
  		(_) ->
  			false
  	end,
  	NewOffers = lists:filter(F, Offers),
  	query_offer7(EDT, Price, Cont, NewOffers).
  %% @hidden
  query_offer7('_', Price, Cont, Offers) ->
  	query_offer8(Price, Cont, Offers);
  query_offer7({Operator, EDT}, Price, Cont, Offers) ->
  	F = fun(#offer{end_date = ETD1}) when is_integer(ETD1) ->
  			EDT2 = integer_to_list(ETD1),
  			match(Operator, EDT, EDT2);
  		(_) ->
  			false
  	end,
  	NewOffers = lists:filter(F, Offers),
  	query_offer8(Price, Cont, NewOffers).
  %% @hidden
  query_offer8('_', Cont, Offers) ->
  	{Cont, Offers};
  query_offer8({Operator, Price}, Cont, Offers) ->
  	F = fun(#offer{price = Prices}) ->
  			F2 = fun(#price{name = Price1}) ->
  					match(Operator, Price, Price1)
  			end,
  			list:any(F2, Prices)
  	end,
  	{Cont, lists:filter(F, Offers)}.
  
  -spec query_table(Cont, Name, Prefix, Description, Rate, LM) -> Result
  	when
  