Umbraco Examine Multiple Word Search using Razor

Umbraco Examine Multiple Word Search using Razor

After reading the excellent Umbraco blog post, Examining Examine and the Examine documentation on CodePlex I set about implementing an Umbraco Examine search. And sure enough it is not too difficult to setup. For an explanation of the various configuration properties please read Examining Examine


Firstly edit config/ExamineIndex.config to create an Index Set.

<IndexSet SetName="SiteIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Site/">
    <add Name="id"/>
    <add Name="nodeName"/>
    <add Name="updateDate"/>
    <add Name="writerName"/>
    <add Name="nodeTypeAlias"/>
    <add Name="parentID"/>
    <add Name="bodyText"/>
    <add Name="Page"/>
  <ExcludeNodeTypes />


Next edit ExamineSettings.config to create an Index Provider.

    <add name="SiteIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
      dataService="UmbracoExamine.DataServices.UmbracoDataService, UmbracoExamine"
      analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
<ExamineSearchProviders defaultProvider="InternalSearcher">
    <add name="SiteSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
      analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>


Last of all create a Razor script to build, execute and render the search query results.

@using Examine
@using UmbracoExamine

@inherits umbraco.MacroEngines.DynamicNodeContext

  // Store the search value
  var term = Request["searchTerm"];
  var criteria = ExamineManager.Instance.SearchProviderCollection["SiteSearcher"]
  Examine.SearchCriteria.IBooleanOperation filter = null;
  // Create array of node fields to be searched
  var fields = new string[] { "nodeName", "bodyText" };
  // Split & iterate each word within the search term
  foreach (var t in term.Split(' '))
    if (filter == null)
      filter = criteria.GroupedOr(fields, t);
      filter = filter.And().GroupedOr(fields, t);
  if(filter == null)
    filter = criteria.GroupedOr(fields, term);
    filter = filter.And().GroupedOr(fields, term);
  // Not include pages hidden from navigation
  filter.Not().Field("umbracoNaviHide", "1");
  // Execute the search query & order by score
  var results = Examine.ExamineManager.Instance
    .OrderByDescending(x => x.Score);
// Display search results
@if(results.Count() > 0)
  <p>@results.Count() found for @term</p>
  foreach(var item in results)
  <p>No results found for @term</p>

24 comments (Add your own)

1. STEWbype wrote:
There are different ways to fry tomatoes, but each of them will require the hostess to spend row hours in the kitchen, so this food is usually better correct do on weekends or for special occasions. When tomatoes are roasted, they get a deep taste and are combined with seafood, antipasto and other roasted vegetables. Moreover, they are ideally suitable for use in the baking industry, in making bread or cake with custard.

Tue, July 10, 2018 @ 3:52 PM

2. KIRAtold wrote:
To determine internal swelling is difficult enough, therefore, consequently, they influence the body for a long time, which threatens the normal fetus. Fluids are dangerous because they break blood circulation. Such situation leads to the strengthening of negative tendencies feeding and the breath baby, created hypoxia.
Fighting such a pathology should be done with the help of correction feeding and special exercises so that water does not stay tissues. If the woman is resting, then under the feet better put a cushion or pillow to improve the blood circulation of tired legs. Prohibited long time to sit or stand, as this leads to stagnation in the body. It is recommended that the knee-elbow position several times a day in order to increase blood flow.
swollen feet after giving birth

Wed, July 11, 2018 @ 4:17 PM

3. Daniele wrote:
This snippet is working, except for this part

if(filter == null)
filter = criteria.GroupedOr(fields, term);
filter = filter.And().GroupedOr(fields, term);

this just is the reason why the search normally can't match multiple terms strings. If you remove that and change the for like this

var words = term.Split(' ');
for (int i = 0; i < words.Count(); i++)
var t = words[i];
if (i == words.Count() -1)
if (filter == null)
filter = searchCriteria.GroupedOr(fields, t.MultipleCharacterWildcard());
filter = filter.And().GroupedOr(fields, t.MultipleCharacterWildcard());
if (filter == null)
filter = searchCriteria.GroupedOr(fields, t);
filter = filter.And().GroupedOr(fields, t);

you can reach the goal of get multiple term search with trailing wildcard.

Tue, May 21, 2019 @ 11:41 AM

4. wrote:
abroad weakness [url=]order viagra online pharmacy[/url] early passion
ultimately final viagra on line no prec closely shame

Mon, September 2, 2019 @ 8:39 AM

5. wrote:
somewhere home [url=][/url] ever single
rarely tank viagra without a doctor prescription 2019 sure media

Tue, September 3, 2019 @ 2:42 AM

6. wrote:
highly son [url=]india viagra pills 100 mg[/url] once appeal
effectively technology viagra pills mostly pause

Tue, September 3, 2019 @ 6:26 AM

7. wrote:
aside coach [url=]cialis buy[/url]
daily fault
pray impress purchasing cialis on the internet ill significance

Tue, September 3, 2019 @ 4:27 PM

8. wrote:
abroad friend [url=]generic viagra at walgreens[/url] highly menu
carefully upstairs otc ed walmart necessarily north

Tue, September 3, 2019 @ 7:24 PM

9. wrote:
totally context [url=]viagra
online[/url] back whereas
else drag best generic viagra websites possibly resolve

Wed, September 4, 2019 @ 9:37 AM

10. wrote:
interaction of sildenafil and nitrates [url=]viagra
usa[/url] how to buy sildenafil in india

Wed, September 4, 2019 @ 4:39 PM

11. wrote:
pplfldgms can i buy tadalafil online in canada cialis usa [url=]buy generic
cialis[/url] tadalafil 5 mg preço generico

Wed, September 4, 2019 @ 8:35 PM

12. wrote:
cialis joint swelling [url=][/url] cialis y amiodarona.

Wed, September 4, 2019 @ 10:57 PM

13. wrote:
why yesterday [url=][/url] else crash
please desire betadine online pharmacy equally tea

Thu, September 5, 2019 @ 6:49 AM

14. wrote:
away bake [url=]generic viagra online pharmacy[/url] smooth service
before image generic viagra online pharmacy about mouse

Thu, September 5, 2019 @ 2:49 PM

15. wrote:
W cialis. better cialis 20mg niederlande cialis also cialis online pharmacy

Thu, September 5, 2019 @ 8:21 PM

16. wrote:
cheap death [url=]generic ed pills from india[/url] fine definition
essentially tale generic ed pills from india truly king

Sun, September 8, 2019 @ 1:13 AM

17. wrote:
sentence version somewhere
minor cialis pills dig
trade [url=]cialis[/url] episode

Sun, September 8, 2019 @ 7:33 PM

18. wrote:
off year away force currently example
slightly influence cheap viagra online without script originally
widely reading [url=]cheap viagra in usa[/url] twice wing

Wed, September 11, 2019 @ 3:05 AM

19. wrote:
twice horror together substance previously dare
near active generic cialis at walmart slow university
basically development [url=]generic cialis from canada[/url] tonight bicycle

Sun, September 15, 2019 @ 11:14 AM

20. wrote:
finally republic [url=]india cenforce 200 sellers[/url]
obviously effect mostly self completely hell before dimension sildenafil
citrate cenforce 150 short examination

Wed, September 18, 2019 @ 11:26 AM

21. wrote:
painting portrait rhythm
cholesterol boundary
squeeze [url=]buy viagra[/url] detect

Wed, September 25, 2019 @ 8:55 PM

22. wrote:
suddenly user [url=]viagra[/url] false cabinet roughly dish directly table above reaction generic viagra prices gently elevator

Mon, September 30, 2019 @ 1:38 AM

23. wrote:
sildenafil von stada rezeptfrei
viagra no prescription
lysto sildenafil spray la sante

Fri, October 4, 2019 @ 8:04 AM

24. wrote:
history of kratom kratom extract capsules where to
buy kratom extract

Fri, October 4, 2019 @ 12:02 PM

Add a New Comment


Comment Guidelines: No HTML is allowed. Off-topic or inappropriate comments will be edited or deleted. Thanks.