Try our conversational search powered by Generative AI!

Help explaining SearchDataSource?


Could someone perhaps give a fast explanation of the SearchDataSource? I really don't get it. I'd like to be able to search a certain pagetype in a specific branch of the page. The parameters I'd like to search is free text in all the searchable fields of the page type as well as two in code specified integer properties.

Is it just me or would a FIndPagesWithCriteria work better for this? What is the difference between the two?

Apr 01, 2011 12:06

The search data source uses findpageswithcriteria below the surface. I guess the searchdatasource was createde to give an easy way to search the episerver database and be able to bind it to any presentation control like repater.

You can do all of this "frontside".



Apr 03, 2011 18:29

The SearchDataSource operates differently depending on what parameters you give it. If you give it a search phrase it will use the search index to find pages matching that phrase, and then do an in-memory post-filtering of any other (property) criteria you've added. If you only add property criteria (no search phrase) it will perform a FindPagesWithCriteria.

If you want to search all searchable (indexed) properties, it's probably easiest to use the SearchDataSource. FindPagesWithCriteria won't work because you have to specify what properties to search and their expected content. The page type as well as the two integer properties you have you should add as PropertyCriteria(Controls) and they will be used by the SearchDataSource to filter the initial results returned by the indexed search.

Apr 04, 2011 6:41
Apr 04, 2011 6:41

Hmm, ok. I'll try them out and see which one best fits my needs. Thanks for the info!

Apr 04, 2011 8:04

I've tried both of the ways without any good results. Maybe you can help me out deciding what way to go.

I've got a set of pages representing product categories. These pages vary in numbers throughout the different language branches. I'd like to search for three different strings in these category pages where one is a free text search (of all the properties marked "searchable") and the others are category and location.

If I've understood the SearchDataSource-control correctly I set the free text search as a select-parameter and the other two as a criteria, right? Would it then be a good thing to make a PageDataCollection of the pages that are supposed to be searched and perform the search on these?

Apr 04, 2011 13:20

How does your markup for the SearchDataSource look? What results do you get and what did you expect?

Apr 05, 2011 6:38

Actually, it's not existing at this moment. I have literally no idea how to set it up. Neither how I can set it to search my PageDataCollection. All help is welcome!

Apr 05, 2011 10:01

I don't think you can set it to search a PageDataCollection. The indexed search uses the index in the database. If you want to limit what pages to search you have to use the PageLink of the control which sets the start node and/or add criteria to limit page types etc. If your "categories" are of a special page type you could just add the page type as a criterion?

If you have a PageDataCollection you have to do the filtering yourself which could of course be very difficult if you want to match many properties, some of which might be XHTML, for a seach string.

Or you'd have to do something really ugly like doing a search for your free text for each page, with the page itself set as start node, to see if you get the page itself returned as a match.

Apr 05, 2011 10:11

Setting the PageLink and adding a criteria for the PageType of the pages that are supposed to searched was a great idea. Now I don't need my PageDataCollection. So, I tried with the following markup and got some results. I then tried dynamically adding a category to the search with the following code but got nothing in return from the search. Do I add the category criteria correctly?

<EPiServer:SearchDataSource ID="SearchDataSource1" runat="server" PageLink="306">
        <EPiServer:PropertyCriteriaControl runat="server" Condition="Equal" Name="PageTypeName" Type="PageType" Value="CompanyPage" Required="True" />

string cat = Request.QueryString["cat"] ?? string.Empty;

if (cat.Length > 0)
    PropertyCriteriaControl catCriteria = new PropertyCriteriaControl();
    catCriteria.Condition = CompareCondition.Equal;
    catCriteria.Name = "Category";
    catCriteria.Type = PropertyDataType.String;
    catCriteria.Value = cat;
    catCriteria.Required = true;


Apr 05, 2011 13:01

Some things to check:

Does the page type filter really work when defined that way? I'm used to filtering for PageTypeID.

The category you want to search for, is it the built in categories in EPiServer or some string property you have added to the page type? If you want to search for the built-in categories the property name is PageCategory (the system properties are prefixed with "Page") and the type is PropertyDataType.Category. The value should be the ID of the category.

Apr 05, 2011 13:15

Yes, filter by PageTypeName works great.

The category and location are values from an external SQL table stored as a string after being selected in a dropdown. What's odd is that I tried the some code with the location property and that worked fine. Gonna have to find what's causing that problem.

Apr 05, 2011 13:20

Oh, I just realized what the problem is. I've never stored the category in the page itself, it's checked from it's parent page. Is it possible to do a check like that in a criteria? I suppose it would be by using something like when you in markup use Container.CurrentPage in PageLists if you know what I mean. Sort of like catCriteria.Value = ParentOfPageBeingChecked["Category"];

Looks like I need to store it in the page as well, don't you think?

Apr 05, 2011 13:36

No you can't do any type of nested query. Then you'd either have to first find the parent pages with the correct categories and search/check their children or the other way around - filter the returned pages based on values of properties of their parent page (the latter is probably better).

Apr 05, 2011 13:38

Oh yeah, all I need to do is change the PageLink of the SearchDataSource. The category value is the same as the ID of the parent page.

Apr 05, 2011 13:43

Worked like a charm!

I'm not entirely sure how the select parameters for the text search work. Any quick tips?

Apr 05, 2011 13:53

I'm trying to find out how to bind the search-phrase from the querystring to the SearchDataSource. When I look in the public templates this it what it says in the comments: 

"When page is loaded on a get request (IsPostBack == false), the querystring variable "quicksearchquery" is used to prepopulate the search textbox. This value will automatically be used by the SearchDataSource on its initial binding."

The big question is how this is automatically done cause I can't get it to work.

Edited, Apr 06, 2011 7:22

Aah, now I get it. it gets it from the control you add to the SelectParameters. I didn't use on at first since I don't actually have a searchbox here. Instead I have a separate web user control containing the search parameters. Any idea on how to get around this or do I need to put the search phrase in hidden label?

Apr 06, 2011 8:07

If anyone's still reading this, how do it search for several words? I'd like it to search for word1, word2, word3, etc. where the words not necessarily occur after each other. I'd like a search for "word1 word2" give a hit on a page containing the text "some text word2 some more text word1".

Apr 06, 2011 8:41

You kind of lost me along the way here, but some additional tips:

The keyword search is word-by-word, meaning it will match any of the words (so the order doesn't matter). If OnlyWholeWords (or whatever the property/select parameter is called) is false it will even match partial words. You can also require words by putting "+" in front of them and "-" to exclude pages matching a word. If you have OnlyWholeWords=true you can still search partial words by using asterisks in the beginning/end of the word. If you want to get a collection of hits from the SearchDataSource rather than binding it to a control you should be able to use the Select method somehow.

I'm afraid you'll have to figure out the details yourself.

Apr 06, 2011 10:43

I went for forcing +*word* around every word and it works great. I've got a little problem with a string-property not turning up in the search result, though. The property for City is checked as searchable but it doesn't show up when I enter a city name, only text that I've entered in an XHTML-string.

Thanks for all your help! Really appreciate it!

Apr 06, 2011 10:49
* 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.