如何在多个表中搜索单词

时间:2022-09-13 09:45:06

I have made an web application with some tables. Now, I want to search in these tables. Currently I have successfully made a class that encapsulates queries for each table such as getAllPersonsByFirstName... and so on. And then the user can select from checkboxes which tables he/she wants to include in the search. If multiple tables are selected I send the string (obtained from the inputfield) to each method then merge the results into a Set collection.

我用一些表创建了一个Web应用程序。现在,我想在这些表中搜索。目前我已经成功地创建了一个类,它封装了每个表的查询,例如getAllPersonsByFirstName ......等等。然后,用户可以从复选框中选择他/她想要包括在搜索中的表。如果选择了多个表,我将字符串(从inputfield获取)发送到每个方法,然后将结果合并到Set集合中。

However, as I see it this have some limited use because if I want to paginate the results (5,10,100 on each page) I will have trouble knowing how many rows I should limit the search to. I am using JPA so I know I can set the offset and maximum, but when having multiple tables I can't see how this would work.

但是,正如我所看到的,这有一些限制使用,因为如果我想对结果进行分页(每页5,10,100),我将无法知道应该限制搜索的行数。我正在使用JPA所以我知道我可以设置偏移量和最大值,但是当有多个表时,我看不出它是如何工作的。

So what I thought of was making one big final query that is sent to the database, made upon smaller methods but I am not sure if this is the way to go. At least the offset-maximum in JPA would work.

所以我想到的是发送一个大的最终查询发送到数据库,使用较小的方法,但我不知道这是否是要走的路。至少JPA中的偏移最大值可以起作用。

Probably there is better ways to do so I would apprciate some help on how to achive pagination support. (Using JPA, EJB, JSF and binding result to a datatable)

可能有更好的方法这样做我会得到一些关于如何实现分页支持的帮助。 (使用JPA,EJB,JSF和绑定结果到数据表)

2 个解决方案

#1


0  

here is some hints http://forums.mysql.com/read.php?107,36833,36833 if database is mysql.

如果数据库是mysql,这里有一些提示http://forums.mysql.com/read.php?107,36833,36833。

you can use Sphinx if you huge amount of data

如果你有大量的数据,你可以使用Sphinx

#2


0  

Since you are using EclipseLink I recommend you look into their Expression framework.

由于您使用的是EclipseLink,我建议您查看它们的Expression框架。

It allows you to do programmatic queries in a very sane way.

它允许您以非常理智的方式进行编程查询。

ExpressionBuilder emp = new ExpressionBuilder();
Expression exp = emp.get("address").get("street").equal("Meadowlands");
Vector employees = session.readAllObjects(Employee.class,
               exp.and(emp.get("salary").greaterThan(10000)));

You can combine several Expressions into a larger expression to query many tables at once. You can also specify pagination and query limits on the query expression as it's executed.

您可以将多个表达式组合成一个更大的表达式,以便一次查询多个表。您还可以在查询表达式执行时指定分页和查询限制。

#1


0  

here is some hints http://forums.mysql.com/read.php?107,36833,36833 if database is mysql.

如果数据库是mysql,这里有一些提示http://forums.mysql.com/read.php?107,36833,36833。

you can use Sphinx if you huge amount of data

如果你有大量的数据,你可以使用Sphinx

#2


0  

Since you are using EclipseLink I recommend you look into their Expression framework.

由于您使用的是EclipseLink,我建议您查看它们的Expression框架。

It allows you to do programmatic queries in a very sane way.

它允许您以非常理智的方式进行编程查询。

ExpressionBuilder emp = new ExpressionBuilder();
Expression exp = emp.get("address").get("street").equal("Meadowlands");
Vector employees = session.readAllObjects(Employee.class,
               exp.and(emp.get("salary").greaterThan(10000)));

You can combine several Expressions into a larger expression to query many tables at once. You can also specify pagination and query limits on the query expression as it's executed.

您可以将多个表达式组合成一个更大的表达式,以便一次查询多个表。您还可以在查询表达式执行时指定分页和查询限制。