Is it possible to use leading wildcard in Examine (V10)
Hi dear Forum,
in older implementations of Examine (V7 sites), we had the option to use leading wildcards when searching. Meaning that you could search for ex. "lorem" and the Examine would find words like ex.
packlorem
lorempack
lorem
I can´t seem to find this option anywhere in the V10 implementation. Anybody got a clue?
It's no longer necessary to configure your index to support this - IIRC we had to do that for V7.
Only requirement now seems to be that your index has a searcher of type BaseLuceneSearcher - which is the case for the default indexes.
So it should be possible doing like in the snippet below. My local test site has an About page, which is matched when searching for *out.
Both leading and trailing wildcards are also possible - eg. *ou* still matches my About page, but now also some other pages.
@using Examine
@using Examine.Lucene.Providers
@using Examine.Lucene.Search
@using Examine.Search
@using Limbo.Umbraco.Search.Constants
@inject IExamineManager ExamineManager
@{
// Get a reference to the index that we wish to use (constant comes from the 'Limbo.Umbraco.Search')
if (!ExamineManager.TryGetIndex(ExamineIndexes.ExternalIndexName, out IIndex? index)) {
<pre>Computer says NO!</pre>
return;
}
// Get a reference to the searcher (must be 'BaseLuceneSearcher' to allow leading wildcard)
if (index.Searcher is not BaseLuceneSearcher searcher) {
<pre>Computer says NO!</pre>
return;
}
// Initialize a new query
IQuery query = searcher.CreateQuery(null, default, searcher.LuceneAnalyzer, new LuceneSearchOptions {
AllowLeadingWildcard = true
});
// Update and execute the query with out leading wildcard query
ISearchResults result = query.NativeQuery("nodeName:*out").Execute();
// Total amount of matched items
<pre>@result.TotalItemCount</pre>
// Iterate through the matched items
foreach (ISearchResult? item in result) {
<pre>@item.Id => @item.Values["nodeName"]</pre>
}
}
Is it possible to use leading wildcard in Examine (V10)
Hi dear Forum,
in older implementations of Examine (V7 sites), we had the option to use leading wildcards when searching. Meaning that you could search for ex. "lorem" and the Examine would find words like ex.
I can´t seem to find this option anywhere in the V10 implementation. Anybody got a clue?
Hi dear René
It's no longer necessary to configure your index to support this - IIRC we had to do that for V7.
Only requirement now seems to be that your index has a searcher of type
BaseLuceneSearcher
- which is the case for the default indexes.So it should be possible doing like in the snippet below. My local test site has an About page, which is matched when searching for
*out
.Both leading and trailing wildcards are also possible - eg.
*ou*
still matches my About page, but now also some other pages.is working on a reply...