David
David

Reputation: 181

Search specific folder using sitecore search

I want to be able to search just within a certain directory. E.g. lets say a user has clicked the "different types of trains" link at the top of a web site. This page then has a list of different types of trains with a search box. I want anything the user types in the search box just to search the pages within "types of trains" section -- anything within /sitecore/content/LOTW/Home/trains and no other pages on the site. I'm currently using:

protected void searchIcon_Click(object sender, EventArgs e)
{
    PerformSearch();
}

private void PerformSearch()
{
    /* Changed from Shared Source, to use different path finding, and context database */

    Item pointerItem = Sitecore.Context.Database.SelectSingleItem("/sitecore/content/LOTW/Global/Settings/Config/Pointers/Search Results");

    if (pointerItem != null)
    {
        Item results = Sitecore.Context.Database.GetItem(new ID(pointerItem["Item"]));

        if (results != null)
        {

            string results_url = LinkManager.GetItemUrl(results) + "?search=" + Server.UrlEncode(search.Text);
            Response.Redirect(results_url);
        }
        else
        {
            search.ForeColor = Color.Red;
            search.Text = "Unable to find results item";
        }

    }
}

This instead searches the whole site. I don't really know anything about the search in Sitecore so I'm a little lost!

Upvotes: 0

Views: 516

Answers (1)

Brian Pedersen
Brian Pedersen

Reputation: 11

Sitecore does have the Axis namespace on an item, allowing you to access descendants from a specific item, but if you have more than, say, 25 children, the search becomes very slow.

To search fast, use the Lucene index. Sitecore comes as standard with the Lucene index.

To simplify the access to the index, you should download the Advanced Database Crawler freeware/open source module.

You can read more about how to set it up and how to access the index here:

Using the Sitecore open source AdvancedDatabaseCrawler Lucene indexer

Upvotes: 1

Related Questions