Reputation: 1554
I'm working on learning how to setup and configure a Lucene search index for Sitecore 6.6. I've pieced together a base config file that indexes all items that are of type "Article" template starting at my desired location in the tree and am able to pull all the items out of that index and display the name from the results.
Now I'm ready to customize that index. I need to specifically index two fields and I am having trouble with the config syntax. Here's the breakdown of the two fields. I'm hoping someone can assist me with tweaking the configuration to account for these fields.
Meta Keywords - This field (single line text) is not part of the Article template but is pulled in from another template called Meta Base which Article inherits from. I do not need to store this, only index it for searching. ex. value "ortho, pain, joint"
Category - This field is a droplink that points to an available list of category items in the tree. I do need to store this as well as index it so that I can use it on the results page that will be searching/displaying these Lucene documents.
I can't seem to find the right documentation for 6.6. Docs for 7+ exist but they won't work in 6.6 because things seem to have changed significantly. Sitecore support directed me to some old docs that contained deprecated code as well as code that didn't compile, and everything else I've read seems to point to using Contrib Search (which I've pulled in via NuGet already). I'd like to get it working without the Contrib, but if I need to, I will.
Here is my config I created without the contrib stuff:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<search>
<configuration>
<indexes>
<index id="my-custom-index" type="Sitecore.Search.Index, Sitecore.Kernel">
<!-- name - not sure if necessary but use id and forget about it -->
<param desc="name">$(id)</param>
<!-- folder - name of directory on the hard drive -->
<param desc="folder">__my-custom-index</param>
<!-- analyzer - reference to analyzer defined in Sitecore.config -->
<Analyzer ref="search/analyzer" />
<!-- list of locations to index - each of the with unique xml tag -->
<locations hint="list:AddCrawler">
<!-- first location (and the only one in this case) - specific folder from you question -->
<!-- type attribute is the crawler type - use default one in this scenario -->
<specificfolder type="Sitecore.Search.Crawlers.DatabaseCrawler,Sitecore.Kernel">
<!-- indexing items from web database -->
<Database>web</Database>
<!-- your folder path -->
<Root>/sitecore/content/Northwestern/in-care</Root>
<!-- Article Template -->
<include hint="list:IncludeTemplate">
<ContentHubArticle>{1E79E463-631A-4FBB-BEEA-3304D25F29CD}</ContentHubArticle>
</include>
<indexAllFields>true</indexAllFields>
</specificfolder>
</locations>
</index>
</indexes>
</configuration>
</search>
Upvotes: 2
Views: 946
Reputation: 1554
talking with Sitecore Support, they definitely said this can't be done with out-of-box functionality. I was able to get it to index my fields by using this series of blog posts:
http://sitecoregadgets.blogspot.com/2009/10/working-with-lucene-search-index-part-i.html http://sitecoregadgets.blogspot.com/2009/11/working-with-lucene-search-index-in.html http://sitecoregadgets.blogspot.com/2009/11/working-with-lucene-search-index-in_25.html http://sitecoregadgets.blogspot.com/2010/08/adding-custom-fields-to-index.html http://sitecoregadgets.blogspot.com/2010/07/sitecore-lucene-index-does-not-remove.html
The only thing left is to make the droplink field store a different field than the guid that points to the item, but I think there is enough here that I can call it answered since the biggest question was how to index custom fields. I might come back and post the entire code when I'm done so you don't have to piece together everything from the blog posts like I did, but it was pretty easy to figure out what's going on.
I also upvode Marek's post above since he's been helpful and his comment was very useful.
Upvotes: 0
Reputation: 27132
The most basic setup of Sitecore 6 lucene index is:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<search>
<configuration>
<indexes>
<index id="custom-index" type="Sitecore.Search.Index, Sitecore.Kernel">
<!-- name of the index displayed in the Sitecore Control Panel -->
<param desc="name">Custom Index</param>
<!-- folder in which index file will be stored -->
<param desc="folder">__$(id)</param>
<!-- reference to the analyzer defined in Sitecore config -->
<Analyzer ref="search/analyzer" />
<!-- list of locations which will be index by our index -->
<locations hint="list:AddCrawler">
<!-- our first and only location crawled by standard Sitecore crawler -->
<custom-loc-1 type="Sitecore.Search.Crawlers.DatabaseCrawler,Sitecore.Kernel">
<!-- location root is Home item in master database -->
<Database>master</Database>
<Root>/sitecore/content/Home</Root>
</custom-loc-1>
</locations>
</index>
</indexes>
</configuration>
</search>
</sitecore>
</configuration>
For custom fields you need to create a custom crawler class, e.g.:
public class MyCrawler : Sitecore.Search.Crawlers.DatabaseCrawler
{
protected override void
AddAllFields(Document document, Item item, bool versionSpecific)
{
base.AddAllFields(document, item, versionSpecific);
document.Add(CreateField("my_title", item["title"], false, 1));
WorkflowState state = item.State.GetWorkflowState();
document.Add(CreateField("my_final_state",
state != null && state.FinalState ? "1" : "", false, 1));
document.Add(CreateDataField("data_title", item["title"]));
}
}
and register this crawler class like that:
<locations hint="list:AddCrawler">
<custom-location-1 type="My.Assembly.Namespace.MyCrawler,My.Assembly">
<Database>master</Database>
<Root>/sitecore/content/Home</Root>
</custom-location-1>
</locations>
Here are blog posts which you can use to learn more about Sitecore 6 search:
Upvotes: 4