Bug 833393
| Summary: | "Example 1.7. Using JPA to create and execute a search" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Retired] JBoss Enterprise WFK Platform 2 | Reporter: | Marek Schmidt <maschmid> | ||||
| Component: | doc-Hibernate-Search-Guide | Assignee: | WFK Docs Team <wfk-docs> | ||||
| Status: | CLOSED CURRENTRELEASE | QA Contact: | Marek Schmidt <maschmid> | ||||
| Severity: | high | Docs Contact: | |||||
| Priority: | unspecified | ||||||
| Version: | 2.0.0.GA | CC: | misty, myarboro, ppenicka, sanne | ||||
| Target Milestone: | GA | ||||||
| Target Release: | 2.1.0 | ||||||
| Hardware: | Unspecified | ||||||
| OS: | Unspecified | ||||||
| Whiteboard: | |||||||
| Fixed In Version: | Doc Type: | Bug Fix | |||||
| Doc Text: | Story Points: | --- | |||||
| Clone Of: | Environment: | ||||||
| Last Closed: | 2013-06-27 12:17:08 UTC | Type: | Bug | ||||
| Regression: | --- | Mount Type: | --- | ||||
| Documentation: | --- | CRM: | |||||
| Verified Versions: | Category: | --- | |||||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
| Cloudforms Team: | --- | Target Upstream Version: | |||||
| Embargoed: | |||||||
| Attachments: |
|
||||||
|
Description
Marek Schmidt
2012-06-19 11:53:38 UTC
Created attachment 592927 [details]
source code of the example
attaching the example (Java EE Web Project + Hibernate Search pieces from the Hibernate Search docs)
Sanne, could you please take a look and check whether this is an actual Hibernate Search bug, or if the example should be fixed and how? (note that you need to uncomment the "dateOfBirth" in the org.jboss.tools.examples.service.MemberSearch class and change the hibernate.search.default.indexBase property in persistence.xml to reproduce the issue in the attached example) Marek, great catch. Indeed, the example is wrong.
The expected type of the argument for the matching(V) method should match the fields it's targeting *unless* _ignoreAnalyzer()_ is set as well.
So we have these options to fix the example:
1)
org.apache.lucene.search.Query query = qb
.keyword()
.onFields("name", "email")
.matching(queryString)
.createQuery();
2)
org.apache.lucene.search.Query query = qb
.keyword()
.onFields("name", "email", "dateOfBirth")
.ignoreAnalyzer()
.matching(queryString)
.createQuery();
3) Make the example more complex by specifying a bool() Query using _should_ to provide different options to the String fields and the Date field.
I'd sugges solution 1) as it's simpler, and this is the introduction chapter.
The full boolean syntax is explained already in 5.1.2.6. Combining queries.
Thanks, I'll fix the example in the community docs.
Note to Bec, (since my example is a bit different than the exact one in the docs)
the lines
.onFields("title", "subtitle", "authors.name", "publicationDate")
should be changed to
.onFields("title", "subtitle", "authors.name")
in the 1.5. Searching chapter,
"Example 1.6. Using Hibernate Session to create and execute a search"
and
"Example 1.7. Using JPA to create and execute a search"
Marek - Those changes should be done now. Verified for WFK 2, Revision 2-0 |