コード例 #1
0
  @Test
  public void verifyIndexExclusivity() {
    FullTextSessionBuilder builder = new FullTextSessionBuilder();
    FullTextSession ftSession =
        builder
            .setProperty("hibernate.search.Book.indexmanager", "near-real-time")
            .setProperty(
                "hibernate.search." + Foo.class.getName() + ".indexmanager",
                "org.hibernate.search.testsupport.indexmanager.RamIndexManager")
            .addAnnotatedClass(BlogEntry.class)
            .addAnnotatedClass(Foo.class)
            .addAnnotatedClass(org.hibernate.search.test.query.Book.class)
            .addAnnotatedClass(org.hibernate.search.test.query.Author.class)
            .openFullTextSession();
    SearchFactoryImplementor searchFactory =
        (SearchFactoryImplementor) ftSession.getSearchFactory();
    ftSession.close();
    IndexManagerHolder allIndexesManager = searchFactory.getIndexManagerHolder();

    // checks for the default implementation
    checkIndexManagerType(
        allIndexesManager,
        "org.hibernate.search.test.configuration.BlogEntry",
        org.hibernate.search.indexes.impl.DirectoryBasedIndexManager.class);

    // Uses "NRT" taken from shortcut names
    checkIndexManagerType(
        allIndexesManager, "Book", org.hibernate.search.indexes.impl.NRTIndexManager.class);

    // Uses a fully qualified name to load an implementation
    checkIndexManagerType(allIndexesManager, Foo.class.getName(), RamIndexManager.class);

    builder.close();
  }
コード例 #2
0
ファイル: Helper.java プロジェクト: rhauch/hibernate-search
 static DocumentBuilderIndexedEntity<?> getDocumentBuilder(QueryBuildingContext queryContext) {
   final SearchFactoryImplementor factory = queryContext.getFactory();
   final Class<?> type = queryContext.getEntityType();
   EntityIndexBinder indexBinding = factory.getIndexBindingForEntity(type);
   if (indexBinding == null) {
     throw new AssertionFailure("Class in not indexed: " + type);
   }
   return indexBinding.getDocumentBuilder();
 }
コード例 #3
0
 private Integer getParameter(int shard, IndexWriterSetting setting, Class testEntity) {
   EntityIndexBinder mappingForEntity = searchFactory.getIndexBindingForEntity(testEntity);
   DirectoryBasedIndexManager indexManager =
       (DirectoryBasedIndexManager) mappingForEntity.getIndexManagers()[shard];
   LuceneIndexingParameters luceneIndexingParameters = indexManager.getIndexingParameters();
   return luceneIndexingParameters.getIndexParameters().getCurrentValueFor(setting);
 }
コード例 #4
0
  /**
   * @param cfg The SearchFactory configuration to be tested
   * @param fieldName The expected name of the ID field
   */
  private void storeBooksViaProvidedId(
      ManualConfiguration cfg, String fieldName, boolean matchTitle) {
    SearchFactoryImplementor sf = null;
    try {
      // Should fail right here when @ProvidedId is not enabled:
      sf = new SearchFactoryBuilder().configuration(cfg).buildSearchFactory();

      Book book = new Book();
      book.title = "Less is nice";
      book.text =
          "When using Infinispan Query, users have to always remember to add @ProvidedId on their classes"
              + " or a nasty exception will remind them. Can't we just assume it's always annotated?";
      String isbn = "some entity-external id";
      Work work = new Work(book, isbn, WorkType.ADD, false);
      ManualTransactionContext tc = new ManualTransactionContext();
      sf.getWorker().performWork(work, tc);
      tc.end();

      QueryBuilder queryBuilder = sf.buildQueryBuilder().forEntity(Book.class).get();

      Query query =
          queryBuilder
              .keyword()
              .onField(fieldName)
              .ignoreAnalyzer()
              .matching(matchTitle ? book.title : isbn)
              .createQuery();

      int queryResultSize =
          sf.createHSQuery()
              .luceneQuery(query)
              .targetedEntities(Arrays.asList(new Class<?>[] {Book.class}))
              .queryResultSize();
      Assert.assertEquals(1, queryResultSize);
    } finally {
      if (sf != null) {
        sf.close();
      }
    }
  }
コード例 #5
0
ファイル: AbstractLoader.java プロジェクト: K19/K19-Arquivos
 public void init(Session session, SearchFactoryImplementor searchFactoryImplementor) {
   statisticsImplementor = searchFactoryImplementor.getStatisticsImplementor();
   takeTimings = searchFactoryImplementor.getStatistics().isStatisticsEnabled();
 }