private SearchMapping createSearchMapping() {
    SearchMapping mapping = new SearchMapping();

    mapping
        .entity(ProgrammaticConfiguredValue.class)
        .indexed()
        .property("id", ElementType.FIELD)
        .documentId()
        .name("id")
        .property("value", ElementType.FIELD)
        .field()
        .store(Store.YES)
        .indexNullAs("@null@");
    return mapping;
  }
  public SearchableCacheConfiguration(
      Class<?>[] classArray,
      Properties properties,
      EmbeddedCacheManager uninitializedCacheManager,
      ComponentRegistry cr) {
    this.providedServices = initializeProvidedServices(uninitializedCacheManager, cr);
    if (properties == null) {
      this.properties = new Properties();
    } else {
      this.properties = rescopeProperties(properties);
    }

    classes = new HashMap<String, Class<?>>();

    for (Class<?> c : classArray) {
      String classname = c.getName();
      classes.put(classname, c);
    }

    // deal with programmatic mapping:
    searchMapping = SearchMappingBuilder.getSearchMapping(this);

    // if we have a SearchMapping then we can predict at least those entities specified in the
    // mapping
    // and avoid further SearchFactory rebuilds triggered by new entity discovery during cache
    // events
    if (searchMapping != null) {
      Set<Class<?>> mappedEntities = searchMapping.getMappedEntities();
      for (Class<?> entity : mappedEntities) {
        classes.put(entity.getName(), entity);
      }
    }
  }
 @Test
 public void documentIdNotOverriden() {
   SearchMapping mapping = new SearchMapping();
   mapping
       .entity(Book.class)
       .indexed()
       .property("title", ElementType.FIELD)
       .documentId()
       .property("text", ElementType.FIELD)
       .field();
   ManualConfiguration cfg =
       new ManualConfiguration()
           .addProperty("hibernate.search.default.directory_provider", "ram")
           .setProgrammaticMapping(mapping)
           // .setIdProvidedImplicit( false ) //Test it's the default
           .addClass(Book.class);
   storeBooksViaProvidedId(cfg, "title", true);
 }
Esempio n. 4
0
  @Produces
  @ApplicationScoped
  @Default
  public EmbeddedCacheManager defaultEmbeddedCacheConfiguration() {
    if (manager == null) {
      GlobalConfiguration glob =
          new GlobalConfigurationBuilder()
              .globalJmxStatistics()
              .allowDuplicateDomains(true)
              .enable() // This
              // method enables the jmx statistics of the global
              // configuration and allows for duplicate JMX domains
              .build();

      SearchMapping mapping = new SearchMapping();
      mapping
          .entity(Task.class)
          .indexed()
          .providedId()
          .property("title", ElementType.METHOD)
          .field();

      Properties properties = new Properties();
      properties.put(org.hibernate.search.Environment.MODEL_MAPPING, mapping);
      properties.put("default.directory_provider", "ram");

      Configuration loc =
          new ConfigurationBuilder()
              .jmxStatistics()
              .enable() // Enable JMX statistics
              .eviction()
              .strategy(EvictionStrategy.NONE) // Do not evic objects
              .transaction()
              .transactionMode(TransactionMode.TRANSACTIONAL)
              .lockingMode(LockingMode.OPTIMISTIC)
              .indexing()
              .enable()
              .indexLocalOnly(false)
              .withProperties(properties)
              .build();
      manager = new DefaultCacheManager(glob, loc, true);
    }
    return manager;
  }
Esempio n. 5
0
 @Factory
 public SearchMapping build() {
   SearchMapping mapping = new SearchMapping();
   mapping
       .analyzerDef("stemmer", StandardTokenizerFactory.class)
       .filter(StandardFilterFactory.class)
       .filter(LowerCaseFilterFactory.class)
       .filter(StopFilterFactory.class)
       .filter(SnowballPorterFilterFactory.class)
       .param("language", "English")
       .analyzerDef("ngram", StandardTokenizerFactory.class)
       .filter(StandardFilterFactory.class)
       .filter(LowerCaseFilterFactory.class)
       .filter(StopFilterFactory.class)
       .filter(NGramFilterFactory.class)
       .param("minGramSize", "3")
       .param("maxGramSize", "3");
   return mapping;
 }
 @Test
 public void usingConfigurationTypeOverride() {
   SearchMapping mapping = new SearchMapping();
   mapping
       .entity(Book.class)
       .indexed()
       // Entity missing both @DocumentId and @ProvidedId:
       .property("title", ElementType.FIELD)
       .field()
       .property("text", ElementType.FIELD)
       .field();
   ManualConfiguration cfg =
       new ManualConfiguration()
           .addProperty("hibernate.search.default.directory_provider", "ram")
           .setProgrammaticMapping(mapping)
           .setIdProvidedImplicit(true)
           .addClass(Book.class);
   storeBooksViaProvidedId(cfg, ProvidedId.defaultFieldName, false);
 }
 @Test
 public void exceptionThrownWhenNotEnabled() {
   SearchMapping mapping = new SearchMapping();
   mapping
       .entity(Book.class)
       .indexed()
       // Entity missing both @DocumentId and @ProvidedId:
       .property("title", ElementType.FIELD)
       .field()
       .property("text", ElementType.FIELD)
       .field();
   ManualConfiguration cfg =
       new ManualConfiguration()
           .addProperty("hibernate.search.default.directory_provider", "ram")
           .setProgrammaticMapping(mapping)
           .addClass(Book.class);
   exceptions.expect(SearchException.class);
   exceptions.expectMessage("No document id in: " + Book.class.getName());
   storeBooksViaProvidedId(cfg, ProvidedId.defaultFieldName, false);
 }
 @Test
 public void usingDefaultSettings() {
   SearchMapping mapping = new SearchMapping();
   mapping
       .entity(Book.class)
       .indexed()
       .providedId()
       .name("myID")
       // Entity missing both @DocumentId and @ProvidedId:
       .property("title", ElementType.FIELD)
       .field()
       .property("text", ElementType.FIELD)
       .field();
   ManualConfiguration cfg =
       new ManualConfiguration()
           .addProperty("hibernate.search.default.directory_provider", "ram")
           .setProgrammaticMapping(mapping)
           // .setIdProvidedImplicit( false ) //Test it's the default
           .addClass(Book.class);
   storeBooksViaProvidedId(cfg, "myID", false);
 }
  /**
   * Returns class bridge instances configured via the programmatic API, if any. The returned map's
   * values are {@code @ClassBridge} annotations representing the corresponding analyzer etc.
   * configuration.
   *
   * @param type the type for which to return the configured class bridge instances
   * @return a map with class bridge instances and their configuration; May be empty but never
   *     {@code null}
   */
  public Map<FieldBridge, ClassBridge> getClassBridgeInstances(Class<?> type) {
    Map<FieldBridge, ClassBridge> classBridgeInstances = null;

    if (searchMapping != null) {
      EntityDescriptor entityDescriptor = searchMapping.getEntityDescriptor(type);
      if (entityDescriptor != null) {
        classBridgeInstances = entityDescriptor.getClassBridgeConfigurations();
      }
    }

    return classBridgeInstances != null
        ? classBridgeInstances
        : Collections.<FieldBridge, ClassBridge>emptyMap();
  }
  @Factory
  public SearchMapping build() {
    SearchMapping mapping = new SearchMapping();

    mapping
        .fullTextFilterDef("security", SecurityFilterFactory.class)
        .cache(FilterCacheModeType.INSTANCE_ONLY)
        .analyzerDef("ngram", StandardTokenizerFactory.class)
        .filter(LowerCaseFilterFactory.class)
        .filter(NGramFilterFactory.class)
        .param("minGramSize", "3")
        .param("maxGramSize", "3")
        .analyzerDef("english", StandardTokenizerFactory.class)
        .filter(LowerCaseFilterFactory.class)
        .filter(SnowballPorterFilterFactory.class)
        .analyzerDef("deutsch", StandardTokenizerFactory.class)
        .filter(LowerCaseFilterFactory.class)
        .filter(GermanStemFilterFactory.class)
        .entity(Address.class)
        .indexed()
        .similarity(DefaultSimilarity.class)
        .boost(2)
        .classBridge(AddressClassBridge.class)
        .analyzer("english")
        .property("addressId", ElementType.FIELD)
        .documentId()
        .name("id")
        .property("lastUpdated", ElementType.FIELD)
        .field()
        .name("last-updated")
        .analyzer("en")
        .store(Store.YES)
        .calendarBridge(Resolution.DAY)
        .property("dateCreated", ElementType.FIELD)
        .field()
        .name("date-created")
        .index(Index.YES)
        .analyzer("en")
        .store(Store.YES)
        .dateBridge(Resolution.DAY)
        .property("owner", ElementType.FIELD)
        .field()
        .property("street1", ElementType.FIELD)
        .field()
        .field()
        .name("street1_ngram")
        .analyzer("ngram")
        .field()
        .name("street1_abridged")
        .bridge(ConcatStringBridge.class)
        .param(ConcatStringBridge.SIZE, "4")
        .property("street2", ElementType.METHOD)
        .field()
        .name("idx_street2")
        .store(Store.YES)
        .boost(2)
        .entity(ProvidedIdEntry.class)
        .indexed()
        .providedId()
        .name("providedidentry")
        .bridge(LongBridge.class)
        .property("name", ElementType.FIELD)
        .field()
        .name("providedidentry.name")
        .analyzer("en")
        .index(Index.YES)
        .store(Store.YES)
        .property("blurb", ElementType.FIELD)
        .field()
        .name("providedidentry.blurb")
        .analyzer("en")
        .index(Index.YES)
        .store(Store.YES)
        .property("age", ElementType.FIELD)
        .field()
        .name("providedidentry.age")
        .analyzer("en")
        .index(Index.YES)
        .store(Store.YES)
        .entity(ProductCatalog.class)
        .indexed()
        .similarity(DefaultSimilarity.class)
        .boost(2)
        .property("id", ElementType.FIELD)
        .documentId()
        .name("id")
        .property("name", ElementType.FIELD)
        .field()
        .name("productCatalogName")
        .index(Index.YES)
        .analyzer("en")
        .store(Store.YES)
        .property("items", ElementType.FIELD)
        .indexEmbedded()
        .entity(Item.class)
        .indexed()
        .property("description", ElementType.FIELD)
        .field()
        .name("description")
        .analyzer("en")
        .index(Index.YES)
        .store(Store.YES)
        .property("productCatalog", ElementType.FIELD)
        .containedIn()
        .property("price", ElementType.FIELD)
        .field()
        .numericField()
        .precisionStep(10)
        .entity(DynamicBoostedDescLibrary.class)
        .dynamicBoost(CustomBoostStrategy.class)
        .indexed()
        .property("libraryId", ElementType.FIELD)
        .documentId()
        .name("id")
        .property("name", ElementType.FIELD)
        .dynamicBoost(CustomFieldBoostStrategy.class)
        .field()
        .store(Store.YES)
        .entity(Departments.class)
        .classBridge(CatDeptsFieldsClassBridge.class)
        .name("branchnetwork")
        .index(Index.YES)
        .store(Store.YES)
        .param("sepChar", " ")
        .classBridge(EquipmentType.class)
        .name("equiptype")
        .index(Index.YES)
        .store(Store.YES)
        .param("C", "Cisco")
        .param("D", "D-Link")
        .param("K", "Kingston")
        .param("3", "3Com")
        .indexed()
        .property("deptsId", ElementType.FIELD)
        .documentId()
        .name("id")
        .property("branchHead", ElementType.FIELD)
        .field()
        .store(Store.YES)
        .property("network", ElementType.FIELD)
        .field()
        .store(Store.YES)
        .property("branch", ElementType.FIELD)
        .field()
        .store(Store.YES)
        .property("maxEmployees", ElementType.FIELD)
        .field()
        .index(Index.YES)
        .analyze(Analyze.YES)
        .store(Store.YES)
        .entity(BlogEntry.class)
        .indexed()
        .property("title", ElementType.METHOD)
        .field()
        .property("description", ElementType.METHOD)
        .field()
        .property("language", ElementType.METHOD)
        .analyzerDiscriminator(BlogEntry.BlogLangDiscriminator.class)
        .property("dateCreated", ElementType.METHOD)
        .field()
        .name("blog-entry-created")
        .analyzer("en")
        .store(Store.YES)
        .dateBridge(Resolution.DAY);
    return mapping;
  }