Boost logo

Boost Users :

Subject: Re: [Boost-users] How to search multi_index container using composite key with date ranges
From: Jeff (jeffro59_at_[hidden])
Date: 2013-02-12 20:49:45


Hi Joaquín,

That did the trick and helps explain the relationship across the composite
index. Many thanks!

The solution did raise a question concerning the lower/upper iterators being
used in this example. I expected to search getting iterators from
referencing the index, but these iterators are obtained from the container
level. Is this possible because there is only one index defined? If 2 or
more indexes were defined on this container would the iterators used here
work the same?
 
I apologize for asking what seems I should be able to get from docs - I've
read them twice and the concepts are starting to sink in but not yet
solidified. Multi_index is a very impressive creation!

Thanks again,
Jeff

-----Original Message-----
From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf Of
Joaquin M Lopez Munoz
Sent: Monday, February 11, 2013 2:30 AM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users]How to search multi_index container using
composite key with date ranges

Jeff <jeffro59 <at> gmail.com> writes:

> Hi,
>
> I am having syntax issues and wish to
> search a bmi container by the composite index defined
> below.  I have read about boost::lambdas and understand how they work.  I
> simply have gotten stuck in the syntax to perform the get on the index and
> how to create the tuple(s) containing the proper objects.
>
> I want to search such that searchKey1=”key1” and searchKey2=”key2”
> and ValidFrom is <= '2013-03-01' and ValidTo >= '2013-02-08'.  Can anyone
> help me please?

Hi Jeff,

There's no way to retrieve this range with a single lookup operation,
basically because the elements satisfying the four criteria are not
sorted to appear adjacently in the idx_test index. The closest you can
get is

* lookup for elements with searchKey1=”key1”, searchKey2=”key2”,
  ValidFrom <= '2013-03-01'
* filter out from the latter range those elements with ValidTo >=
'2013-02-08'

which would look roughly like this (not tested):

TestCache tc;
...
date valid_to=date(from_string("2013-02-08"));
for(
  auto it= tc.lower_bound(boost:make_tuple("key1","key2")),
       it_end=tc.upper_bound(
         boost:make_tuple("key1","key2",from_string("2013-03-01"))),
  it!=it_end;++it){
  if(it->ValidTo>=valid_to){...}
}

HTH,

Joaquín M López Muñoz
Telefónica Digital

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net