-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: doubts about PrefixQuery
PostPosted: Sun Apr 03, 2011 11:32 pm 
Newbie

Joined: Wed Mar 09, 2011 11:52 am
Posts: 7
i have a field like "Tom Jack Alice Mary",and i want to make a prefixquery so that i can hit "Alice" when i input "a".
As the names in the field are separated by whitespace,so i used a SimpleAnalyzer on the field.Then came the problem.
when i input "a","Jack" and "Mary" is also hitted,but i don't want it be hitted.So it seems that prefixquery only takes effect when no analyzers are used.Anyone can help me how to solve this problem.Thank you very much!


Top
 Profile  
 
 Post subject: Re: doubts about PrefixQuery
PostPosted: Mon Apr 04, 2011 5:29 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

that does not sounds right. Prefix queries definitely work also in conjunction w/ analyzers. I think your problem lies somewhere else. It would help if you post you model together with your Search configuration.

One thought which comes to my mind - you are saying you have a single(?) field with the value "Tom Jack Alice Mary". If you run this through the analyzer you will get four terms "tom", "jack", "alice" and "mary". You will get a successful search if you search for any of the following t*, j*, a* or m*. All four names belong to the same field which means that as long as your query matches one of these names you will get a search result. If you want to match the names really as one single string "Tom Jack Alice Mary", you would indeed not use an analyzer. However, a* wouldn't match then either.

As said, it would really help if you describe your use case a little more.

--Hardy


Top
 Profile  
 
 Post subject: Re: doubts about PrefixQuery
PostPosted: Mon Apr 04, 2011 6:42 am 
Newbie

Joined: Wed Mar 09, 2011 11:52 am
Posts: 7
Ah,thank you very much,Hardy.it's my problem indeed.
In fact,my index contains a field whose values like this:"Tom Jack Alice Mary" (names are separated by white space).
And I need to count which names are hitted and how many of them.So i process the hit value one by one:first split
the hit value using " " and for each splitted string, i use the function String.contains(String inputWord) to find the name
that is hitted.and here,the contains(String inputWord) function made me think that PrefixQuery cannot work with analyzer.
So Hardy,if i need to find which names are hitted and how many of them,i have to process the hit results given by hibernate
search,right?
The field's values ("Tom Jack Alice Mary") are directly from database. so when building the index,is it better If I give each name a different field name.like: Field field1 = new Field("name1",Tom,...),Field field2 = new Field("name2",Jack,...) ...
document.add(field1),document.add(field2),...
Thank you!
hardy.ferentschik wrote:
Hi,

that does not sounds right. Prefix queries definitely work also in conjunction w/ analyzers. I think your problem lies somewhere else. It would help if you post you model together with your Search configuration.

One thought which comes to my mind - you are saying you have a single(?) field with the value "Tom Jack Alice Mary". If you run this through the analyzer you will get four terms "tom", "jack", "alice" and "mary". You will get a successful search if you search for any of the following t*, j*, a* or m*. All four names belong to the same field which means that as long as your query matches one of these names you will get a search result. If you want to match the names really as one single string "Tom Jack Alice Mary", you would indeed not use an analyzer. However, a* wouldn't match then either.

As said, it would really help if you describe your use case a little more.

--Hardy


Top
 Profile  
 
 Post subject: Re: doubts about PrefixQuery
PostPosted: Mon Apr 04, 2011 7:39 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

as mentioned before you will have to post your domain model? For example if you would have say Person entities with a name, eg new Person("Tom"), ... then you would just search for Person instances and count the returned number of instances. This seems not to be the case for you at the moment. For some reason you have a field w/ multiple names. Personally I find this quite strange, but maybe you have a reason for that. Either way you will have to explain your domain model.

Theoretically you can create different field names (name1, name2, ...), but that would only work if you know the number of fields before hand and there are probably other problems along the way.

--Hardy


Top
 Profile  
 
 Post subject: Re: doubts about PrefixQuery
PostPosted: Mon Apr 04, 2011 8:05 am 
Newbie

Joined: Wed Mar 09, 2011 11:52 am
Posts: 7
Here is the simplified domain model.
Code:
@Entity
@Table(name="movie")
public class movie{
@DocumentId(name="movieId")
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="movie_id", nullable=false)
private Integer movieId;
   
@Field
@Column(name="name", nullable=false)
private String name;

@Field
@Column(name="actors")
private String actors;

...
}

The actors column has multi names separated by white space.
let's assume that when a user inputs a last name,i need to find the actors' full names with that last name and count how many of them.


Top
 Profile  
 
 Post subject: Re: doubts about PrefixQuery
PostPosted: Mon Apr 04, 2011 10:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
If you model your domain as described you have indeed a problem. You will have to iterate over the returned movies and inspect the actors string to see what matched.
I wonder though why you not create a Actor entity. A movie would then have a list of actors and you could have a bidirectional relationship between them. If you then also index the actors themselves you can nicely solve your usecase and you have a much better domain model imo

--Hardy


Top
 Profile  
 
 Post subject: Re: doubts about PrefixQuery
PostPosted: Mon Apr 04, 2011 11:45 am 
Newbie

Joined: Wed Mar 09, 2011 11:52 am
Posts: 7
thank you Hardy~i'm afraid i have to use the present model...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.