如何在 Hibernate Search 3.0 中使用多个参数进行搜索。0.ga
How to search with multiple parameters in Hibernate Search 3.0.0.ga
使用:
- 休眠 3.2.7.ga
- 休眠搜索 3.0.0.ga
- Hibernate-Anotations 3.3.0.ga
- Hibernate-Commons-Cnnotations 3.0.0.ga
- Lucene-Core 2.9.4
- Lucene 分析器 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" );
此外,如果可能的话,我很高兴知道如何搜索“onlyOneword”和“包含多个空格的文本”
谢谢!
尝试像这样使用 BooleanQuery:
org.apache.lucene.search.Query query1 = ....;
org.apache.lucene.search.Query query2 = ....;
org.apache.lucene.search.Query query3 = ....;
BooleanQuery booleanQuery = new BooleanQuery();
luceneBooleanQuery.add(query1, BooleanClause.Occur.MUST);
luceneBooleanQuery.add(query2, BooleanClause.Occur.SHOULD);
luceneBooleanQuery.add(query3, BooleanClause.Occur.SHOULD);
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(booleanQuery, DomainClass.class);
应该可以。
使用:
- 休眠 3.2.7.ga
- 休眠搜索 3.0.0.ga
- Hibernate-Anotations 3.3.0.ga
- Hibernate-Commons-Cnnotations 3.0.0.ga
- Lucene-Core 2.9.4
- Lucene 分析器 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" );
此外,如果可能的话,我很高兴知道如何搜索“onlyOneword”和“包含多个空格的文本”
谢谢!
尝试像这样使用 BooleanQuery:
org.apache.lucene.search.Query query1 = ....;
org.apache.lucene.search.Query query2 = ....;
org.apache.lucene.search.Query query3 = ....;
BooleanQuery booleanQuery = new BooleanQuery();
luceneBooleanQuery.add(query1, BooleanClause.Occur.MUST);
luceneBooleanQuery.add(query2, BooleanClause.Occur.SHOULD);
luceneBooleanQuery.add(query3, BooleanClause.Occur.SHOULD);
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(booleanQuery, DomainClass.class);
应该可以。