Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate搜索与Junit一起工作,而不是与Pivotal Server(Spring)一起工作?_Java_Spring_Hibernate_Lucene_Hibernate Search - Fatal编程技术网

Java Hibernate搜索与Junit一起工作,而不是与Pivotal Server(Spring)一起工作?

Java Hibernate搜索与Junit一起工作,而不是与Pivotal Server(Spring)一起工作?,java,spring,hibernate,lucene,hibernate-search,Java,Spring,Hibernate,Lucene,Hibernate Search,今天我有一个非常奇怪的案例(对我来说:-),经过几个小时的搜索,我没有找到任何答案 我用Spring和Hibernate构建了一个网站。我试图使用Hibernate搜索(Lucene),但没有成功,或者说部分成功 我的实体(inspectionMaster)配置了一些索引字段: @Entity @Indexed @Table(name="LGIMAS") public class InspectionMaster implements Serializable { private st

今天我有一个非常奇怪的案例(对我来说:-),经过几个小时的搜索,我没有找到任何答案

我用Spring和Hibernate构建了一个网站。我试图使用Hibernate搜索(Lucene),但没有成功,或者说部分成功

我的实体(inspectionMaster)配置了一些索引字段:

@Entity
@Indexed
@Table(name="LGIMAS")
public class InspectionMaster implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="LMISID", insertable=false, updatable=false)
    private Long id;

    @Column(name="LMRANK", nullable=false)
    private Integer rank;

    @Column(name="LMPIID", nullable=false)
    private Long parentInspection;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="SITID")
    @IndexedEmbedded
    private Site site;

    @Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
    @Column(name="LMVNDN", nullable=false, length=6)
    private String vendorNr;

    @Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
    @Column(name="LMVNNM", nullable=false, length=25)
    private String vendorDesc;

    @Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
    @Column(name="LMITEM", nullable=false, length=15)
    private String itemNr;

    @Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
    @Column(name="LMITDS", nullable=false, length=40)
    private String itemDesc;

    @Column(name="LMSTAT", nullable=false, length=2)
    @Convert(converter = StatusConverter.class)
    private StatusType status;

    @Transient
    private String statusDesc;

    @Column(name="LMRMCT", nullable=false)
    private Long remoteID;

    @Column(name="LMPRTU", nullable=false, precision=1, scale=0)
    private BigDecimal priorityUrg;

    @Column(name="LMPRTC", nullable=false, precision=5, scale=0)
    private BigDecimal priorityCust;

    @Column(name="LMPRTD", nullable=false, precision=2, scale=0)
    private BigDecimal priorityDate;

    @Column(name="LMPRTE", nullable=false, precision=2, scale=0)
    private BigDecimal priorityExt;

    @Column(name="LMSTRL", nullable=false, length=1)
    private String stockRelease;

    @Column(name="LMUPDI", nullable=false, length=1)
    private String updItem;

    @Column(name="LMRCHK", nullable=false, length=1)
    private String recheck;

    @Column(name="LMRCHD")
    private Timestamp recheckDate;

    @Column(name="LMRFCP", nullable=false, length=1)
    private String fullPackIDcontrol;

    @Column(name="LMSPAC", nullable=false, length=2)
    @Convert(converter = ActionsConverter.class)
    private ActionsType specificAction;

    @Column(name="LMTYPE", nullable=false, length=1)
    private String requestType;

    @Column(name="LMRCDT")
    private Timestamp receptDate;

    @Column(name="LMRCUS", length=25)
    private String receptUser;

    @Column(name="LMCTDT")
    private Timestamp controlDate;

    @Column(name="LMCTUS", length=25)
    private String controlUser;

    @Column(name="LMAPDT")
    private Timestamp approvalDate;

    @Column(name="LMAPUS", length=25)
    private String approvalUser;

    @Column(name="LMUNIT", nullable=false, precision=5, scale=0)
    private BigDecimal unitByOuter;

    @Column(name="LMOPCK", nullable=false, precision=5, scale=0)
    private BigDecimal packID;

    @Column(name="LMCFDD")
    private Timestamp coFirstMDD;

    @Column(name="LMCAMT", nullable=false, precision=13, scale=2)
    private BigDecimal coAmount;

    @Column(name="LMCADT")
    private Timestamp customerAnalyseDate;

    @Embedded
    @Transient 
    private List<Whinv> whinv = new ArrayList<Whinv>();

    @Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
    @Column(name="LMWPLC", nullable=false, length=10)
    private String whmPickLocation;

    @Transient 
    private boolean WHINVExist;
结果工作除外:

*** LOG [Sat Apr 23 17:25:08 CEST 2016] TEST : Test search on site.siteId = *lpb* return 16 documents
*** LOG [Sat Apr 23 17:25:08 CEST 2016] TEST : Test search on site.sitedescription = *france* return 16 documents
*** LOG [Sat Apr 23 17:25:08 CEST 2016] TEST : Test search on vendorNr = *s07610* return 3 documents
*** LOG [Sat Apr 23 17:25:08 CEST 2016] TEST : Test search on vendorDesc = *limited* return 1 documents
*** LOG [Sat Apr 23 17:25:08 CEST 2016] TEST : Test search on itemNr = *0023* return 4 documents
*** LOG [Sat Apr 23 17:25:08 CEST 2016] TEST : Test search on itemDesc = *28w* return 5 documents
*** LOG [Sat Apr 23 17:25:08 CEST 2016] TEST : Test search on whmPickLocation = *00* return 10 documents
*** LOG [Sat Apr 23 17:25:08 CEST 2016] TEST : Test search on all return 16 documents
*** LOG [Sat Apr 23 17:25:08 CEST 2016] TEST : Test search on all with *lpb* return 16 documents
我最终在我的项目中构建了一个搜索功能:

  public Page<InspectionMaster> search(String text, Pageable pageable) {

        // get the full text entity manager
        FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);

        // create the query using Hibernate Search query DSL
        QueryBuilder queryBuilder = fullTextEntityManager
                                    .getSearchFactory()
                                    .buildQueryBuilder()
                                    .forEntity(InspectionMaster.class)
                                    .get();

        // Add wildcard to always have a full search capability
        text = "*" + text.toLowerCase() + "*";

        // Build Query !
        Query query = queryBuilder
                      .bool()
                        .should( queryBuilder.keyword().wildcard().onField("site.siteId").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("site.sitedescription").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("vendorNr").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("vendorDesc").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("itemNr").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("itemDesc").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("whmPickLocation").matching(text).createQuery() )
                      .createQuery();

        // wrap Lucene query in an Hibernate Query object
        FullTextQuery jpaQuery = fullTextEntityManager.createFullTextQuery(query, InspectionMaster.class);
        jpaQuery.setFirstResult(pageable.getOffset());
        jpaQuery.setMaxResults(pageable.getPageSize());

        int resultSize = jpaQuery.getResultSize();

        logService.log("Search for text = "+ text +" return " + jpaQuery.getResultSize() + " documents");       

        // execute search and return results (sorted by relevance as default)
        @SuppressWarnings("unchecked")
        List<InspectionMaster> results = jpaQuery.getResultList();      

    return new PageImpl<>(results, pageable, resultSize);
  }
正如您所看到的,搜索ItemNr和VendorNr是可行的,但搜索其他。。。没什么

当然我错过了什么,但是什么


欢迎任何帮助。提前感谢。

我想您的项目已经有了数据库。Hibernate Search默认情况下仅在实体发生更改时对其进行索引:是否触发MassIndexer使其对所有内容重新进行索引?您好,Sanne。非常感谢,我刚刚添加了fullTextEntityManager.createIndexer().startAndWait();在ContextLoaderListener期间。现在一切都好了,这其实很奇怪。当JUnit启动应用程序时,索引被更新。当这是正常的过程时,没有更新。更奇怪的是,有没有持久性的索引?但是好了,现在一切都好了。再次感谢。我想你的项目已经有数据库了。Hibernate Search默认情况下仅在实体发生更改时对其进行索引:是否触发MassIndexer使其对所有内容重新进行索引?您好,Sanne。非常感谢,我刚刚添加了fullTextEntityManager.createIndexer().startAndWait();在ContextLoaderListener期间。现在一切都好了,这其实很奇怪。当JUnit启动应用程序时,索引被更新。当这是正常的过程时,没有更新。更奇怪的是,有没有持久性的索引?但是好了,现在一切都好了。再次感谢你。
  public Page<InspectionMaster> search(String text, Pageable pageable) {

        // get the full text entity manager
        FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);

        // create the query using Hibernate Search query DSL
        QueryBuilder queryBuilder = fullTextEntityManager
                                    .getSearchFactory()
                                    .buildQueryBuilder()
                                    .forEntity(InspectionMaster.class)
                                    .get();

        // Add wildcard to always have a full search capability
        text = "*" + text.toLowerCase() + "*";

        // Build Query !
        Query query = queryBuilder
                      .bool()
                        .should( queryBuilder.keyword().wildcard().onField("site.siteId").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("site.sitedescription").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("vendorNr").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("vendorDesc").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("itemNr").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("itemDesc").matching(text).createQuery() )
                        .should( queryBuilder.keyword().wildcard().onField("whmPickLocation").matching(text).createQuery() )
                      .createQuery();

        // wrap Lucene query in an Hibernate Query object
        FullTextQuery jpaQuery = fullTextEntityManager.createFullTextQuery(query, InspectionMaster.class);
        jpaQuery.setFirstResult(pageable.getOffset());
        jpaQuery.setMaxResults(pageable.getPageSize());

        int resultSize = jpaQuery.getResultSize();

        logService.log("Search for text = "+ text +" return " + jpaQuery.getResultSize() + " documents");       

        // execute search and return results (sorted by relevance as default)
        @SuppressWarnings("unchecked")
        List<InspectionMaster> results = jpaQuery.getResultList();      

    return new PageImpl<>(results, pageable, resultSize);
  }
*** LOG [Sat Apr 23 17:23:18 CEST 2016] TEST : Test search on site.siteId = *lpb* return 0 documents
*** LOG [Sat Apr 23 17:23:18 CEST 2016] TEST : Test search on site.sitedescription = *france* return 0 documents
*** LOG [Sat Apr 23 17:23:18 CEST 2016] TEST : Test search on vendorNr = *s07610* return 3 documents
*** LOG [Sat Apr 23 17:23:18 CEST 2016] TEST : Test search on vendorDesc = *limited* return 0 documents
*** LOG [Sat Apr 23 17:23:18 CEST 2016] TEST : Test search on itemNr = *0023* return 4 documents
*** LOG [Sat Apr 23 17:23:18 CEST 2016] TEST : Test search on itemDesc = *28w* return 0 documents
*** LOG [Sat Apr 23 17:23:18 CEST 2016] TEST : Test search on whmPickLocation = *00* return 0 documents
*** LOG [Sat Apr 23 17:23:18 CEST 2016] TEST : Test search on all return 7 documents
*** LOG [Sat Apr 23 17:23:18 CEST 2016] TEST : Test search on all with *lpb* return 0 documents