Beispiel #1
0
        public static IndexWriter Create(AbstractConnection connection, Process process, Entity entity)
        {
            using (var dir = LuceneDirectoryFactory.Create(connection, entity)) {
                Analyzer defaultAnalyzer = new KeywordAnalyzer();
                if (process.SearchTypes.ContainsKey("default"))
                {
                    defaultAnalyzer = LuceneAnalyzerFactory.Create(process.SearchTypes["default"].Analyzer, connection.Version);
                }

                var analyzer = new PerFieldAnalyzerWrapper(defaultAnalyzer);
                foreach (var field in GetFields(entity, connection.Version, connection.Logger))
                {
                    analyzer.AddAnalyzer(field.Key, field.Value);
                }
                return(new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED));
            }
        }
Beispiel #2
0
        private static Dictionary <string, Analyzer> GetFields(Entity entity, string version, ILogger logger)
        {
            var fields = new Dictionary <string, Analyzer>();

            foreach (var field in entity.OutputFields())
            {
                foreach (var searchType in field.SearchTypes)
                {
                    if (Analyzers.Contains(searchType.Analyzer))
                    {
                        if (fields.ContainsKey(field.Alias))
                        {
                            fields[field.Alias + searchType.Name] = LuceneAnalyzerFactory.Create(searchType.Analyzer, version);
                        }
                        else
                        {
                            fields[field.Alias] = LuceneAnalyzerFactory.Create(searchType.Analyzer, version);
                        }
                    }
                    else
                    {
                        logger.EntityWarn(entity.Name, "Analyzer '{0}' specified in search type '{1}' is not supported.  Lucene is limited to standard, simple, keyword, or whitespace.", searchType.Analyzer, searchType.Name);
                        if (!fields.ContainsKey(field.Alias))
                        {
                            fields[field.Alias] = LuceneAnalyzerFactory.Create(searchType.Analyzer, version);
                        }
                    }
                }
            }
            if (!fields.ContainsKey("TflBatchId"))
            {
                fields.Add("TflBatchId", new KeywordAnalyzer());
            }
            if (entity.Delete && !fields.ContainsKey("TflDeleted"))
            {
                fields.Add("TflDeleted", new KeywordAnalyzer());
            }
            return(fields);
        }