/** Built-in default programatic mapping for hibernate-search **/ private static SearchMapping getBuiltinMapping() { SearchMapping mapping = new SearchMapping(); // Map the getExternalId() method as a documentId for all domain classes // Note that hibernate-search currently requires this method to really exist in the // AbstractDomainObject class mapping.entity(AbstractDomainObject.class).property("externalId", ElementType.METHOD).documentId().name("id"); return mapping; }
@Factory public SearchMapping getSearchMapping() { SearchMapping mapping = new SearchMapping(); mapping.analyzerDef("autocompleteEdgeAnalyzer", PatternTokenizerFactory.class) .tokenizerParam("pattern", "(.*)") .tokenizerParam("group", "1")
AnalyzerDefMapping(String name, String tokenizerName, Class<? extends TokenizerFactory> tokenizerFactory, SearchMapping mapping) { this.mapping = mapping; this.analyzerDef = new HashMap<String, Object>(); mapping.addAnalyzerDef( analyzerDef ); analyzerDef.put( "name", name ); tokenizer = new HashMap<String, Object>(); tokenizer.put( "name", tokenizerName ); tokenizer.put( "factory", tokenizerFactory ); analyzerDef.put( "tokenizer", tokenizer ); }
SearchMapping mapping = ...; mapping.entity( SpecialArticle.class ) .indexed() .property( "uid", ElementType.FIELD ).documentId() .property( "someSpecialAttribute", ElementType.FIELD ).field(); //Map the super class directly, but don't call "indexed()" mapping.entity( Article.class ) .property( "articleNumber", ElementType.FIELD ).field() .property( "texts", ElementType.FIELD ) .indexEmbedded().targetElement( ArticleText.class ).entity( ArticleText.class ) .property( "article", ElementType.FIELD ).containedIn() .property( "someText", ElementType.FIELD ).field();
if (programmaticSearchMappingProviders != null && !programmaticSearchMappingProviders.isEmpty()) { if (searchMapping == null) { searchMapping = new SearchMapping(); for (Class<?> c : this.searchMapping.getMappedEntities()) { if (log.isDebugEnabled()) { log.debugf("Found programmatically configured class mapping for Hibernate Search: %s", c.getName());
public AnalyzerDefMapping analyzerDef(String name, Class<? extends TokenizerFactory> tokenizerFactory) { return analyzerDef( name, "", tokenizerFactory ); }
/** * Defines a programmatic configuration to be used by Search * * @return the enabled SearchMapping. change it to define the mapping programmatically. */ public SearchMapping fluentMapping() { SearchMapping mapping = (SearchMapping) cfg.get( org.hibernate.search.cfg.Environment.MODEL_MAPPING ); if ( mapping == null ) { mapping = new SearchMapping(); cfg.put( org.hibernate.search.cfg.Environment.MODEL_MAPPING, mapping ); } return mapping; }
@Factory public SearchMapping build() { SearchMapping mapping = new SearchMapping(); mapping.fullTextFilterDef( "security", SecurityFilterFactory.class ).cache( FilterCacheModeType.INSTANCE_ONLY ) .analyzerDef( NGRAM_ANALYZER_NAME, StandardTokenizerFactory.class ) .filter( LowerCaseFilterFactory.class )
TokenFilterDefMapping(Class<? extends TokenFilterFactory> factory, Map<String, Object> analyzerDef, SearchMapping mapping) { this.mapping = mapping; this.analyzerDef = analyzerDef; this.filter = SearchMapping.addElementToAnnotationArray( analyzerDef, "filters" ); filter.put( "factory", factory ); }
public FullTextFilterDefMapping(SearchMapping mapping, String name, Class<?> impl) { this.mapping = mapping; this.fullTextFilterDef = new HashMap<String, Object>(); this.fullTextFilterDef.put( "name", name ); this.fullTextFilterDef.put( "impl", impl ); mapping.addFulltextFilterDef( fullTextFilterDef ); }
@Override public void defineMappings(Cache cache, SearchMapping searchMapping) { searchMapping.entity(GenericData.Record.class) .indexed() .classBridgeInstance(new ValueWrapperFieldBridge()) .norms(Norms.NO) .analyze(Analyze.NO) .store(Store.NO); } }
public AnalyzerDefMapping analyzerDef(String name, Class<? extends TokenizerFactory> tokenizerFactory) { return analyzerDef( name, "", tokenizerFactory ); }
private Properties addProgrammaticMappings(Properties indexingProperties, ComponentRegistry cr) { Iterator<ProgrammaticSearchMappingProvider> providers = ServiceFinder.load(ProgrammaticSearchMappingProvider.class).iterator(); if (providers.hasNext()) { SearchMapping mapping = (SearchMapping) indexingProperties.get(Environment.MODEL_MAPPING); if (mapping == null) { mapping = new SearchMapping(); Properties amendedProperties = new Properties(); amendedProperties.putAll(indexingProperties); amendedProperties.put(Environment.MODEL_MAPPING, mapping); indexingProperties = amendedProperties; } Cache cache = cr.getComponent(Cache.class); while (providers.hasNext()) { ProgrammaticSearchMappingProvider provider = providers.next(); if (log.isDebugEnabled()) { log.debugf("Loading programmatic search mappings for cache %s from provider : %s", cache.getName(), provider.getClass().getName()); } provider.defineMappings(cache, mapping); } } return indexingProperties; }
TokenFilterDefMapping(Class<? extends TokenFilterFactory> factory, Map<String, Object> analyzerDef, SearchMapping mapping) { this.mapping = mapping; this.analyzerDef = analyzerDef; this.filter = SearchMapping.addElementToAnnotationArray( analyzerDef, "filters" ); filter.put( "factory", factory ); }
public FullTextFilterDefMapping(SearchMapping mapping, String name, Class<?> impl) { this.mapping = mapping; this.fullTextFilterDef = new HashMap<String, Object>(); this.fullTextFilterDef.put( "name", name ); this.fullTextFilterDef.put( "impl", impl ); mapping.addFulltextFilterDef( fullTextFilterDef ); }
@SuppressWarnings("unused") @Factory public SearchMapping buildSearchMapping() { SearchMapping searchMapping = new SearchMapping(); searchMapping.entity(MySearchableEntity.class); return searchMapping; }
@Factory public SearchMapping getSearchMapping() { SearchMapping mapping = new SearchMapping(); mapping.analyzerDef("custom", NGramTokenizerFactory.class).tokenizerParam("maxGramSize", "40") // .filter(ASCIIFoldingFilterFactory.class) // .filter(LowerCaseFilterFactory.class); return mapping; } }
private FullTextSessionBuilder configure(boolean withClassBridgeOnItem, int depth, boolean withClassBridgeOnCatalog) { FullTextSessionBuilder builder = new FullTextSessionBuilder() .addAnnotatedClass( Catalog.class ) .addAnnotatedClass( CatalogItem.class ) .addAnnotatedClass( Consumer.class ) .addAnnotatedClass( Item.class ); SearchMapping fluentMapping = builder.fluentMapping(); // mapping for Catalog EntityMapping catalogMapping = fluentMapping .entity( Catalog.class ); if ( withClassBridgeOnCatalog ) { catalogMapping.classBridge( NoopClassBridge.class ); } catalogMapping .property( "catalogItems", ElementType.FIELD ).containedIn(); // mapping for CatalogItem fluentMapping.entity( CatalogItem.class ) .property( "item", ElementType.FIELD ).containedIn() .property( "catalog", ElementType.FIELD ).indexEmbedded(); // mapping for Item IndexedMapping itemMapping = fluentMapping .entity( Item.class ) .indexed(); if ( withClassBridgeOnItem ) { itemMapping.classBridge( NoopClassBridge.class ); } itemMapping.property( "catalogItems", ElementType.FIELD ).indexEmbedded().depth( depth ); return builder.build(); }
@Override public void defineMappings(Cache cache, SearchMapping searchMapping) { searchMapping .analyzerDef("standard-with-stop", StandardTokenizerFactory.class) .filter(StandardFilterFactory.class) .filter(LowerCaseFilterFactory.class) .filter(StopFilterFactory.class); } }
/** * {@code @TokenFilterDef(, ... params={@Parameter(name="name", value="value"), ...} } * @param name the name of the parameter * @param value the value of the parameter * @return {@code this} for method chaining */ public TokenFilterDefMapping param(String name, String value) { Map<String, Object> param = SearchMapping.addElementToAnnotationArray( filter, "params" ); param.put( "name", name ); param.put( "value", value ); return this; }