如何在Hibernate Search 3.0.0.ga中搜索多个参数

时间:2015-05-21 07:00:34

标签: java lucene hibernate-search

使用:

  • Hibernate 3.2.7.ga
  • Hibernate-Search 3.0.0.ga
  • Hibernate-Anotations 3.3.0.ga
  • Hibernate-Commons-Cnnotations 3.0.0.ga
  • Lucene-Core 2.9.4
  • Lucene-Analyzers 2.9.4
  • Lucene-Queryparser 2.9.4

如何使用多个参数进行搜索,如:

SELECT * 
FROM example 
WHERE column1 = "text1"
AND (column2 = "text2" OR column2 ="text3")

使用Hibernate-Search documentation我只找到了搜索示例:

Session session = universalHibernateDAO.getHibernateSession();
FullTextSession fullTextSession = Search.createFullTextSession(session);

Transaction tx = fullTextSession.beginTransaction();
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_29,
    new String[]{"summary", "body"}, analyzer);
org.apache.lucene.search.Query query = parser.parse( "Java rocks!" );
Query hibQuery = fullTextSession.createFullTextQuery( query, PscpExpedient.class );
List<PscpExpedient> result = (List<PscpExpedient>)hibQuery.list();

tx.commit();

如果以某种方式存在,那将是完美的:

org.apache.lucene.search.Query query = parser.parse("column1: text1", 
                                                      "column2: text2 | text3" );

另外,如果可以的话,很高兴知道如何搜索&#34; onlyOneword&#34;和#34;带有多个空格的文本&#34;

谢谢!

1 个答案:

答案 0 :(得分:1)

尝试使用这样的BooleanQuery:

tasklist

它应该有用。