+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Using "IN" or nested AND meta search

Using "IN" or nested AND meta search

6 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    22 Dec 2010
    Link to this post
    Hi,

    Im trying to filter results, which if I were writing SQL would look like:

    SELECT * FROM table1 WHERE table1.ContactCounty = "London" AND (table1.MemberType = "Full" OR table1.MemberType = "Life")

    The first part of my filter expression is:

    filter = new MetaSearchInfo(MetaValueTypes.ShortText, "ContactCounty", this._county.ToString(), SearchCondition.Equal, JoinType.And);
                    filterBuilder.AddFilter(filter);

    However how can I add the nested filter? The code below doesnt work.

    List<string> olist = new List<string>();
    olist.Add("Full");
    olist.Add("Life");
     
    filter = new MetaSearchInfo(MetaValueTypes.ShortText, "MemberType", olist, SearchCondition.Equal, JoinType.And);
    filterBuilder.AddFilter(filter);

    And I can't do the following:

    protected override ContentFilterBuilder GetFilterBuilder() {
     
        ContentFilterBuilder filterBuilder = base.GetFilterBuilder();
        MetaSearchInfo filter = new MetaSearchInfo();
        filterBuilder.ClearFilter();
     
            filter = new MetaSearchInfo(MetaValueTypes.ShortText, "ContactCounty", this._county.ToString(), SearchCondition.Equal, JoinType.And);
            filterBuilder.AddFilter(filter);
     
        //only Life or Full members can have a profile
        filter = new MetaSearchInfo(MetaValueTypes.ShortText, "MemberType", Member.MemberTypes.Full.ToString(), SearchCondition.Equal, JoinType.And);
        filterBuilder.AddFilter(filter);
     
        filter = new MetaSearchInfo(MetaValueTypes.ShortText, "MemberType", Member.MemberTypes.Life.ToString(), SearchCondition.Like, JoinType.Or);
        filterBuilder.AddFilter(filter);
     
        return filterBuilder;
     
    }

    Because the filterexpression that is generated is:

    ContactCounty = "Essex" AND MemberType = "Full" OR MemberType LIKE "Life"

    Which produces hugely different results from:

    ContactCounty = "Essex" AND (MemberType = "Full" OR MemberType LIKE "Life")

    How do i achieve this?

    Thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Dec 2010
    Link to this post
    Hello higgsy,

    OR is not supported and this is why the filter you have does not work. You can use LINQ-SQL to filter the databasource with "OR"


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    24 Dec 2010
    Link to this post
    Hi Ivan,

    I dont understand your comments, SiteFinity provides an OR provider - JoinType.OR. and I have seen the filter expression sitefinity produces, which is 

    ContactCounty = "London" AND MemberType = "Full" OR MemberType = "Life"

    Are you suggesting I write a LINQ-SQL query to interact with the Sitefinity database directly? Or are you suggesting i use linq to query the IList returned by CreateDataSource?

    If I am to write a Linq-Sql query that queries the DB directly I will need to understand the structure of the sitefinity Database i.e. how does it store information in modules. I dont have any custom tables all the data is entered directly into custom sitefinity modules.

    Thanks
    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Dec 2010
    Link to this post
    Hi higgsy,

    OR cannot be used and we do not use it. There is missing implementation in the datalayer that we using in 3.x editions and OR is not working. You can use the Linq query to the IList of objects that you have. You can cast the List to <IContent> and then  query the items inside it, so you do not need to write the basic queries and creating a datacontext to a given table.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    07 Jan 2011
    Link to this post
    Hi Ivan,

    My module has a MetaKey called MemberType. Do you have a basic example of querying the IList against a metafield?

    And actually even harder:

    I have my IList of results at this point:

    System.Collections.IList oFilteredItems =  this.Manager.GetContent(base.GetContentStartIndex(),
                                                                    base.GetPageSize(),
                                                                    "Name ASC",
                                                                    filterBuilder.ParseTagFilter(),
                                                                    ContentStatus.Published,
                                                                    null,
                                                                    filterBuilder.ParseParentsFilter(),
                                                                    filterBuilder.ParseMetaFieldsFilter());

    But this list needs to be further filtered. You've told me I can't use the "OR" operator, but if I am using Linq to query the list of returned items, how is the pager going to accurately know how many pages there are!?

    Thanks
    higgsy
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jan 2011
    Link to this post
    Hi higgsy,

    The pager for each of our controls is calculated based on what you have in the datasource of the control. Such operations should be performed where you bind the control.

    var ds = base.CreateDataSource().Cast<IContent>().Where(c => c.GetMetaData("Name").ToString()  == "test1" || c.GetMetaData("Name").ToString() == "test2");

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 0 answered