求设计模式

发布于 2024-10-04 01:30:53 字数 858 浏览 0 评论 0原文

我们正在开发带有搜索模型的网络应用程序。

在搜索 servlet 中,它捕获来自客户端的请求参数,然后构建一个 hibernate-search 查询来进行搜索。

现在的问题是来自客户端的参数是可变的!。

我们接受的所有参数如下:

1) 关键字。

用于搜索的关键字,仅传递该参数即可处理搜索请求。

有效示例:

/search?keyword="test"

2) lowleftX,lowleftY,upperrightX,upperrightY。

这四个参数必须同时出现或者永远不会出现。因为这四个参数用于lucene中的TermRangeQuery。如果其中之一发生,则其余三种也必然发生。

并且,这四个参数可以与“关键字”同时出现。

有效示例:

/search?lowleftX=10&lowleftY=10&upperrightX=40&upperrightY=30
/search?lowleftX=10&lowleftY=10&upperrightX=40&upperrightY=30&keyword="test"

3) 类别

用于限制搜索范围(仅在特定类别内搜索)。

4) start,limit

这两个参数用于分页。

5) returnFields

将从索引中检索(如果存储在索引中)并返回给客户端的returnFields。

所以我不知道如何使用估计语法构建查询(if....else....if...)。

谁能告诉我怎么做?

We are working on web application with a search model.

In the search servlet it capture the request parameters from the client, and then build a hibernate-search query for searching.

Now the problem is the parameters from the client are mutable!.

All the parameters we accepts are listed as following:

1) keyword.

The keyword(s) using for searching,a search request can be processed even just this parameter is passed.

Valid example:

/search?keyword="test"

2) lowleftX,lowleftY,upperrightX,upperrightY.

These four parameter must occur at the same time or never.Since these four paramers are used for a TermRangeQuery in lucene. If one of them occur,the rest three must be occur also.

And, these four parameter can occur with the "keyword" at the sametime.

Valid example:

/search?lowleftX=10&lowleftY=10&upperrightX=40&upperrightY=30
/search?lowleftX=10&lowleftY=10&upperrightX=40&upperrightY=30&keyword="test"

3) category

This is used to limit the search scope(just search within the special category).

4) start,limit

These two parameters are using for paging.

5) returnFields

The returnFields which will be retrieved from the index (if it is stored in the index) and return to the client.

So I have no idea about how to build the query using the estimate syntax (if....else....if...).

Can anyone tell me how ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2024-10-11 01:30:53

我不知道你所说的“估计语法”是什么意思,但在我看来,第 1 -3 点是实际的 Lucene 查询。您必须检查参数并根据参数的名称和数量决定您拥有哪种类型的查询。然后,使用 Query 的不同子类(特别是 BooleanQuery)构建适当的 Lucene 查询并使用它来创建 Hibernate Search FullTextQuery。在此全文查询中,您指定开始和限制参数。如果您使用投影直接从索引检索字段值,您还可以在全文查询上设置投影字段名​​称。
我希望这会有所帮助。

I have no idea what you mean with "estimate syntax", but it seems to me that point 1 -3 are the actual Lucene query. You would have to inspect the parameters and decide depending on the name and number of parameters which type of query you have. Using the different sub classes of Query, in particular BooleanQuery, you then build an appropriate Lucene query and use it to create a Hibernate Search FullTextQuery. On this fulltext query you specify the start and limit paramters. If you are using projections to retrieve the field values directly from the index you also set the projected field names on the fulltext query.
I hope this helps a little.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文