Developer forum

Forum » CMS - Standard features » New Index first letter analyzer

New Index first letter analyzer

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Guys,

I am trying to build a facet that contains the fisrt letters of company names. An Alphabetic index.

Is there any way I can use one of the existing Lucene analyzers to create a field of this type. Just the first letter of the Company name (Company is actual an Item)?

Thanks,

Adrian


Replies

 
Nicolai Pedersen
Reply

Not that I can think of.

You can either create an analyzer your self - it should be pretty simple:

using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Store;
 
public class FirstLetterAnalyzer : Analyzer
        {

            public override TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
            {
                TokenStream tokenStream = new KeywordTokenizer(reader);
                //find the first letter of the first token and return that in a new token stream
                return tokenStream;
            }
        }

 

An alternative would be to create a IIndexBuilderExtender<ContentIndexBuilder> that extends the document with a field of your choice - and add just the first letter of another field to it. That is a more custom implementation, whereas the analyzer is more reusable.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Thanks a lot Nicolai,

I believe an Analyzer would be nicer and more reusable.

Thanks,

Adrian

 

You must be logged in to post in the forum