0

我们正在开发具有搜索模型的 Web 应用程序。

在搜索 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) 开始,限制

这两个参数用于分页。

5) 返回字段

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

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

谁能告诉我怎么做?

4

1 回答 1

0

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.

于 2010-11-21T12:17:31.047 回答