Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top