@@ -0,0 +1,2992 @@
+/*%0A * Copyright 2017 Red Hat, Inc. and/or its affiliates.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.jboss.perspicuus.storage;%0A%0Aimport org.apache.avro.Schema;%0Aimport org.apache.lucene.analysis.TokenStream;%0Aimport org.apache.lucene.analysis.Tokenizer;%0Aimport org.apache.lucene.analysis.core.LowerCaseFilter;%0Aimport org.apache.lucene.analysis.core.StopFilter;%0Aimport org.apache.lucene.analysis.standard.StandardFilter;%0Aimport org.apache.lucene.analysis.standard.StandardTokenizer;%0Aimport org.apache.lucene.analysis.util.StopwordAnalyzerBase;%0A%0Aimport java.io.IOException;%0Aimport java.io.Reader;%0Aimport java.io.StringReader;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Custom Analyzer to help make Avro's Schema structure indexable by Hibernate Search i.e. lucene.%0A *%0A * Currently unused, but may be a more flexible approach than the exiting AvroSchemaStringBridge.%0A *%0A * @since 2017-03%0A * @author Jonathan Halliday (jonathan.halliday@redhat.com)%0A */%0Apublic class AvroSchemaAnalyzer extends StopwordAnalyzerBase %7B%0A%0A    // should probably be a subclass of StandardAnalyzer, but that's final :-(%0A%0A%0A    @Override%0A    protected TokenStreamComponents createComponents(final String fieldName) %7B%0A%0A        final Tokenizer src = new StandardTokenizer();%0A%0A        TokenStream tok = new StandardFilter(src);%0A        tok = new LowerCaseFilter(tok);%0A        tok = new StopFilter(tok, stopwords);%0A%0A        return new TokenStreamComponents(src, tok) %7B%0A            @Override%0A            protected void setReader(final Reader reader) throws IOException %7B%0A%0A                char%5B%5D array = new char%5B4 * 1024%5D;%0A                StringBuilder buffer = new StringBuilder();%0A                int count;%0A                while ((count = reader.read(array, 0, array.length)) != -1) %7B%0A                    buffer.append(array, 0, count);%0A                %7D%0A%0A                String data = buffer.toString();%0A%0A                if(data.startsWith(%22%7B%22)) %7B%0A%0A                    Schema avroSchema = new Schema.Parser().parse(data);%0A                    List%3CString%3E tokens = new ArrayList%3C%3E();%0A%0A                    tokens.add(avroSchema.getName());%0A%0A                    for (Schema.Field field : avroSchema.getFields()) %7B%0A                        tokens.add(field.name());%0A                    %7D%0A%0A                    String result = String.join(%22 %22, tokens);%0A                    data = result;%0A                %7D%0A%0A                super.setReader( new StringReader(data) );%0A            %7D%0A        %7D;%0A    %7D%0A%7D%0A

Add custom Analyzer for indexing schema objects.