0

如果我有 20 个或更多的搜索字段并且任何组合都应该是有效的,那么最好的方法是什么。有没有什么特殊的方法可以在 openJPA 或原生 SQL 中做到这一点更好。任何想法都会有所帮助。谢谢。

4

4 回答 4

1

您可以在存储过程或参数化 SQL 语句中尝试类似的操作。通过这种方式,即使只有少数字段具有值,您也可以传入所有字段。

@param1 varchar(25),
@param2 int,
@param3 varchar(10),
@param4 char(1)

SELECT column1, column2, column3, column4
FROM TABLE
WHERE (column1 = @param1 OR @param1 IS NULL)
AND (column2 = @param2 OR @param2 IS NULL)
AND (column3 = @param3 OR @param3 IS NULL)
AND (column4 = @param4 OR @param4 IS NULL)
于 2010-04-14T19:40:01.683 回答
0

I think you might want to use something like "Hibernate Search" which brings the power of full text search engines to DB model. Thus, you can provide a google search like feature to do whatever combination of search your customers want to perform.

I had developed a demo app with a GUI to test out various query types.

Check out - http://code.google.com/p/hb-search-demo/

于 2010-04-14T19:20:09.393 回答
0

I believe that using criteria api is the best way forward.

Please read that link and check for your own:

http://openjpa.apache.org/builds/2.0.0-beta3/apache-openjpa-2.0.0-beta3/docs/manual/jpa_overview_criteria.html

于 2010-04-14T19:21:45.810 回答
0

I don't like running full text searches through SQL. For stuff like to use a search engine like Solr.

http://lucene.apache.org/solr/

an overview of its features:

http://lucene.apache.org/solr/features.html

于 2010-04-14T19:26:07.183 回答