留言板

Lucene search 'AND' operation not work with age range ?

Montej Shah,修改在8 年前。

Lucene search 'AND' operation not work with age range ?

Junior Member 帖子: 48 加入日期: 15-2-18 最近的帖子
Hi,
I am using Lucene search for finding user record.
I am adding some parameter to filter data. Like search by first name,last name
Below is code



@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext)
throws Exception {

// Add and operation between all search clause
searchContext.setAndSearch(true);

addSearchTerm(searchQuery, searchContext, "firstName", true);
addSearchTerm(searchQuery, searchContext, "lastName", true);


}

Here you can see i set "setAndSearch" to true so all data are found by 'AND' operation.Mean so query is something like 'select * from member where firstName='A' and lastName='B' .

so search result give for only member who's first name is 'A' and last name is 'b' .
Now i add below code to search by birth date range(min birth-date and maximum birth-date)

// search based on birth date
searchQuery.addRangeTerm(Constants.BIRTH_DATE, Long.valueOf(fromDateValue).longValue(), Long
.valueOf(toDateValue).longValue());


now when i search i want to member data which has birth date between start and end date also has first name ,last name as provided.
But it give me only member based on first and last name data range does not effect
Query : birthDate:[20030911000000 TO 20050910000000] +(firstName:*user*)+(lastName:*a*)

But when i remove firstName and lastName from query then it find out member by range.
Query : [20030911000000 TO 20050910000000]

So finally i want to common data form first name and last name search and date range (means who have first name,last name as providede in search query and birth-date in range of min and max as provided in query )

Any one can help me?
Any help will be appreciated.
Montej Shah,修改在8 年前。

RE: Lucene search 'AND' operation not work with age range ?

Junior Member 帖子: 48 加入日期: 15-2-18 最近的帖子
I have solved this issue,
Instead of searchQuery.addRangeTerm create Query object for search by age range and then add query in BooleanQuery object.


// search based on birth date
searchQuery.addRangeTerm(Constants.BIRTH_DATE, Long.valueOf(fromDateValue).longValue(), Long
.valueOf(toDateValue).longValue());

instead of above code use below code.

// create query for date range (format-->"birthDate:[19310912000000 TO 19350911000000]")
Query stringQuery =
StringQueryFactoryUtil.create("birthDate:[19310912000000 TO 19350911000000]");
// add age range query with 'AND' operator(Means must require to find record)
searchQuery.add(stringQuery, BooleanClauseOccur.MUST);
renu jyothi,修改在6 年前。

RE: Lucene search 'AND' operation not work with age range ?

New Member 帖子: 5 加入日期: 17-2-17 最近的帖子
Hi Montej,

I'm a beginner to liferay.. just want to know which classes u are using ..
is it the com.liferay.portal.kernel.search.Query or the org.apache.lucene.search.Query..
and I dint find the StringQueryFactoryUtil in lucene api.
thumbnail
James Falkner,修改在8 年前。

Moved

Liferay Legend 帖子: 1399 加入日期: 10-9-17 最近的帖子
Moved to proper category.