There are two parts to this answer. Firstly you need to specify which field(s) you wish to search against:
.Or().Field("bodyText", searchTerm)
This makes the assumption that your pages have a bodyText
property. You can append additional fields onto this to search against other properties, e.g. name, introText etc.
Secondly, if you want to search across all fields, you will need to create a field that contains all the text content from the page being indexed. You need to:
- Create an Umbraco event that implements
IApplicationEventHandler
;
Add a handler for gathering node data:
void OnApplicationStarted(UmbracoApplicationBase app, ApplicationContext ctx)
{
ExamineManager.Instance
.IndexProviderCollection["ExternalIndexer"]
.GatheringNodeData += OnGatheringNodeData;
}
Create your combined field:
protected void OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
var builder = new StringBuilder();
foreach (var entry in e.Fields)
{
builder.AppendFormat("{0}, ", entry.Value);
}
e.Fields.Add("combinedText", builder.ToString());
}
- Change your search to be
.Or().Field("combinedText", searchTerm)
;
Now each time a page is published, it will combine all fields into one so that they can be search upon in the way you wish.
However, personally, I would advise you select specific fields to combine as there is rarely any need to combine all. This is usually a sign that there is little consistency in your document types. I always use common aliases throughout all my doc types for reasons like this, e.g. bodyText, introText, summaryText etc. This way if needed I could filter out the fields ending in "Text" or have my aliases as static strings.