hello i use lucene-core 2.4 hibernate-search 3.0.1 Jboss 4.2GA
i create search for user :
Code:
@Override
public List<Person> getAlbumByQuery(String userQuery, int min , int max)
{
FullTextEntityManager ftem = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);
String[] personFields = {"German", "photos.German"};
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(personFields, foo.GermanAnalyzer());
org.apache.lucene.search.Query luceneQuery;
try{
luceneQuery = queryParser.parse(query);
} catch (Exception e)
{ e.printStackTrace();
return null;
}
System.out.println("LUCENE QUERY :" + luceneQuery);
Query jpaQuery = ftem.createFullTextQuery(luceneQuery, Person.class);
if(min > 0)
jpaQuery.setFirstResult(min);
if(max > 0)
jpaQuery.setMaxResults(max);
return (List<Person>) jpaQuery.getResultList();
}
In class Person i have got:
Code:
@Indexed
public class Person implements Serializable, Cloneable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@DocumentId
private long id;
@Field(name="German",index=Index.TOKENIZED, store = Store.NO)
private String title;
@Field(index=Index.UN_TOKENIZED)
@DateBridge(resolution=Resolution.SECOND)
private Timestamp publicationTimestamp;
//other
@IndexedEmbedded
@OneToMany
@JoinColumns({
@JoinColumn(name="albumId", referencedColumnName="id")
})
private List<Photo> photos;
}
And my GermanAnalyzer:
Code:
public class GermanAnalyzer extends Analyzer {
@Override
public TokenStream tokenStream(String fieldName, Reader reader) {
TokenStream result = new StandardTokenizer(reader);
result = new StandardFilter(result);
result = new LowerCaseFilter(result);
result = new SnowballFilter(result, fieldName);
return result;
}
}
1) Its correct to define German snowball ?? fieldName must have got name="German"
i read post:
viewtopic.php?f=9&t=991924&start=0 so i think its correct because i cant use @AnalyzerDef
2)as yout see i define search the parametr is userQuery but i need filter results by publicationTimestamp. In mysql something like that:
SELET * FROM Person WHERE title LIKE "%something%"
AND publicationTimestamp > CURRENT_TIMESTAMP3) If i define @AnalyzerDef in class Person and another @AnalyzerDef in class Photo
so than i must set analyzer to null in constructor MultiFieldQueryParser: MultiFieldQueryParser queryParser = new MultiFieldQueryParser(personFields,
null);
??
And its working fine when i delete @IndexedEmbedded from Photo and delete "photos.German" from personFields
because if i have got right for SnowballFilder name
photos.German isnt correct
Its possible add this parametr into query ??