Hi,
I have a problem with strange results in my Search. I have User class with indexed name and lastname fields:
Code:
@ManagedBean(name = "userBean")
@Entity
@Table(name = "user_User")
@Indexed
@AnalyzerDef(name = "searchtokenanalyzer", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters = {
@TokenFilterDef(factory = StandardFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = StopFilterFactory.class, params = { @Parameter(name = "ignoreCase", value = "true") }) })
@Analyzer(definition = "searchtokenanalyzer")
public class User extends Node implements Comparable<User> {
private String name;
private String lastname;
private Post currentStatus;
@Column(name = "name", nullable = true)
@Field
@Analyzer(definition = "searchtokenanalyzer")
public String getName() {
return name;
}
@Column(name = "lastname", nullable = true)
@Field
@Analyzer(definition = "searchtokenanalyzer")
public String getLastname() {
return lastname;
}
@OneToOne
public Post getCurrentStatus() {
return currentStatus;
}
...
Class Post has OneToOne relation to user, but it doesn't have any indexed field.
Code:
@Entity
@Table(name = "content_Post")
public class Post extends Node {
The method that has to find Users based on their names or lastnames, returns both User and Post instances.
Code:
Session session = persistence.currentManager();
FullTextSession fullTextSession=Search.getFullTextSession(session);
QueryBuilder qBuilder=fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();
Query query=qBuilder.keyword().wildcard().onField("name").andField("lastname").matching(searchString+"*").createQuery();
org.hibernate.Query hibQuery=fullTextSession.createFullTextQuery(query, User.class);
@SuppressWarnings("unchecked")
List<User> result=hibQuery.list();
I would expect that only User class instances are returned as result, and I don't have an idea what could be a problem here.
Could you please help me about this?