วิธีเพิ่มแบบสอบถามไวด์การ์ดใน Hibernate Search 3.1.1GA

วิธีเพิ่มแบบสอบถามไวด์การ์ดเมื่อใช้การค้นหาไฮเบอร์เนต ฉันใช้ Hibernate Search 3.1.1GA jar และไม่สามารถอัปเกรด jar ของฉันเป็นเวอร์ชันที่สูงกว่าได้ ในเวอร์ชันบนของไฮเบอร์เนต เราสามารถใช้วิธีไวด์การ์ดโดยใช้ Query Builder

ฉันติดอยู่ โปรดช่วยฉันด้วย


person Sumant    schedule 26.11.2014    source แหล่งที่มา


คำตอบ (1)


ฉันถือว่าคุณกำลังอ้างถึงคำค้นหา Hibernate Search DSL บางสิ่งเช่นนี้:

Query luceneQuery = queryBuilder
    .keyword()
      .wildcard()
    .onField("foo")
    .matching("bar*")
    .createQuery();

DSL นี้ไม่ใช่ส่วนหนึ่งของ Search 3.1.1 และถูกเพิ่มเข้ามาในภายหลัง ในเวอร์ชันนี้ คุณต้องสร้างการสืบค้นโดยใช้การสืบค้น Lucene ดั้งเดิม จริงๆ แล้ว Search DSL ทั้งหมดนั้นอยู่ภายใต้การควบคุมของการสร้างข้อความค้นหาแบบเนทีฟเหล่านี้ให้กับคุณ ในกรณีของคุณ คุณต้องการดู org.apache.lucene.search.WildcardQuery หรือคุณสามารถใช้ org.apache.lucene.queryParser.QueryParser เพื่อใช้ไวยากรณ์ข้อความค้นหา Lucene ซึ่งอนุญาตให้ใช้ไวด์การ์ดได้เช่นกัน

person Hardy    schedule 26.11.2014
comment
ขอบคุณที่ช่วยเหลือ. QueryBuilder ไม่พร้อมใช้งานสำหรับเวอร์ชันของฉัน กรุณาแบ่งปันรหัสเพิ่มเติม - person Sumant; 27.11.2014
comment
นั่นคือสิ่งที่ฉันกำลังพูด คุณไม่จำเป็นต้องมี QueryBuilder คุณสร้างแบบสอบถาม Lucene ดั้งเดิม ตรวจสอบเอกสาร Hibernate Search เช่นเดียวกับ Lucene มีตัวอย่างมากมาย - person Hardy; 27.11.2014
comment
ฮาร์ดี้: ฉันทำตามที่คุณแนะนำแล้ว แต่มีข้อยกเว้น เกิดจาก: java.lang.NoSuchMethodError: org.hibernate.search.SearchFactory.buildQueryBuilder()Lorg/hibernate/search/query/dsl/QueryContextBuilder; ที่ org.springframework.aop.support.AopUtils.invoidJoinpointUsingReflection (AopUtils.java:310) ที่ org.springframework.aop.framework.ReflectiveMethodInvocation.invoidJoinpoint (ReflectiveMethodInvocation.java:182) - person Sumant; 27.11.2014
comment
เกณฑ์เกณฑ์ = session.createCriteria(NSAliasImpl.class).add(Restrictions.eq(itemId, itemId)); FullTextSession fullTextSession = Search.getFullTextSession(เซสชัน); ธุรกรรม tx = fullTextSession.beginTransaction(); QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(NSAliasImpl.class).get(); - person Sumant; 27.11.2014
comment
org.apache.lucene.search.Query query = queryBuilder.keyword().wildcard().onField(trackerId).ignoreAnalyzer().matching(+ searchParam +).createQuery(); - person Sumant; 27.11.2014
comment
เป็นไปได้ด้วยอาร์เรย์ของสตริงใน onFields();? โปรดดูคำถามของฉัน @Hardy: stackoverflow.com/questions/28528012/ - person alexander; 16.02.2015