NightOwl888 commented on issue #964:
URL: https://github.com/apache/lucenenet/issues/964#issuecomment-2544449385

   Note that 
[`KeywordAnalyzer`](https://github.com/apache/lucenenet/blob/7cfc4c340c384bd5af39f42d7591dbe45344fd24/src/Lucene.Net.Analysis.Common/Analysis/Core/KeywordAnalyzer.cs)/[`KeywordTokenizer`](https://github.com/apache/lucenenet/blob/7cfc4c340c384bd5af39f42d7591dbe45344fd24/src/Lucene.Net.Analysis.Common/Analysis/Core/KeywordTokenizer.cs)
 are suitable for the purpose of not splitting apart values like this.
   
   You can use `PerFieldAnalyzerWrapper` in a custom analyzer to specify that 
the `name` field will use `KeywordAnalyzer` while all other fields will use 
`StandardAnalyzer`.
   
   ```c#
   using Lucene.Net.Analysis;
   using Lucene.Net.Analysis.Core;
   using Lucene.Net.Analysis.Standard;
   
   public class CustomAnalyzer : Analyzer
   {
       private readonly Analyzer _defaultAnalyzer;
       private readonly PerFieldAnalyzerWrapper _perFieldAnalyzerWrapper;
   
       public CustomAnalyzer()
       {
           // Default analyzer for most fields
           _defaultAnalyzer = new 
StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48);
   
           // Define the per-field analyzers
           var perFieldAnalyzers = new Dictionary<string, Analyzer>
           {
               { "name", new KeywordAnalyzer() } // Use KeywordAnalyzer for 
"name"
           };
   
           // Combine default and per-field analyzers
           _perFieldAnalyzerWrapper = new 
PerFieldAnalyzerWrapper(_defaultAnalyzer, perFieldAnalyzers);
       }
   
       protected override TokenStreamComponents CreateComponents(string 
fieldName, System.IO.TextReader reader)
       {
           // Delegate to the PerFieldAnalyzerWrapper
           return 
_perFieldAnalyzerWrapper.GetWrappedAnalyzer(fieldName).CreateComponents(fieldName,
 reader);
       }
   
       protected override TextReader InitReader(string fieldName, TextReader 
reader)
       {
           return _perFieldAnalyzerWrapper.InitReader(fieldName, reader);
       }
   }
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to