Try our conversational search powered by Generative AI!

Search text and property criteria together



I want to search on a free text field within a certain filtered criteria.

I already have code which filters content using FindPagesWithCriteria() and a PropertyCriteriaCollection for filtering by date and category against a parent PageReference. I also have code which uses SearchDataSource() to perform a free text search against a parent PageReference.

Essentially I want to combine the functionality of these two searches. e.g. I want to search for the word 'green' in category = A.

I see it is possible to manually filter a List<PageData> if listPages and remove the ones you don't want i.e.

                PageData pageData = (PageData)listingItems[pageIndex];

                var categories = new List();
                foreach (var c in CurrentPage.Category)

                bool keep = false;
                foreach (var c in categories)
                    if (c.Name == "G")
                        keep = true;
                if (!keep)

But is there a more elegant way where I can reuse the PropertyCriteriaCollection I have already created and apply it to my SearchDataSource() results?



Jan 14, 2010 18:23

If you do a combined freetext (indexed) search and property search using a SearchDataSource, the property criteria will be used as a post-filter (i.e. the query will not run in the DBMS as with FindPagesWithCriteria, the first step (free text index search) will however of course be handled by the DBMS). If you already have a PropertyCriteriaCollection I'm sure there's a way to add it to the SearchDataSource from codebehind. I know you should be able to loop through your PropertyCriteriaCollection and create a PropertyCriteriaControl for each PropertyCriteria, I think there's a constructor accepting the PropertyCriteria. Not super-elegant, but working.

Jan 14, 2010 23:34

Thanks for your reply I could extract each PropertyCriteria from the Collection and add them to the Control and it works fine


                var search = new SearchDataSource { SearchFiles = false };
                search.PageTypeID = SearchPageTypeID;
                search.LanguageBranches = GetSearchLocales();
                search.IncludeRootPage = false;
                search.PageLink = rootPage;
                search.SearchQuery = searchPhrase;

                PropertyCriteriaControl prpCriteriaControl;
                foreach (PropertyCriteria prpCriteria in prpCriteriaCollection)
                    prpCriteriaControl = new PropertyCriteriaControl(prpCriteria);

Jan 15, 2010 17:51
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.