Foren

Liferay Lucene query can't set parameter of enable wildcard

Ying Wang, geändert vor 8 Jahren.

Liferay Lucene query can't set parameter of enable wildcard

Junior Member Beiträge: 36 Beitrittsdatum: 16.05.14 Neueste Beiträge
I found directly use lucene query to do search for webcontent is very convenient. We can compose the search term and search boolean logic with a string query text.
But it seems can't support wildcard query. just like the function of "like" in sql

Here is the code I used:


Query stringQuery = StringQueryFactoryUtil.create("+(+(companyId:"+companyId+") +("+termCategoryIds+") +(assetCategoryIds:"+countryCategoryId+") +((+(+(entryClassName:com.liferay.portlet.journal.model.JournalArticle))  +(status:0) +(head:true))) +(+(groupId:"+groupId+") +(scopeGroupId:"+groupId+")) "
					+ "+(userId:"+user.getUserId()+" ("+roleIdsStr+")) )");

 BooleanClause clause = BooleanClauseFactoryUtil.create(searchContext, stringQuery, BooleanClauseOccur.MUST.getName());
	        searchContext.setBooleanClauses(new BooleanClause[] {clause});

	        Hits hits =  SearchEngineUtil.search(searchContext, stringQuery);


The above code run very correctly.But when I added some text like "title: *Book*", it throws out exception.

Caused by: org.apache.lucene.queryParser.ParseException: '*' or '?' not allowed as first character in WildcardQuery


Can anyone tell me how to complete a query text with "*" or "%". Some magic parameter to make it enable? Is it supported by directly using luence search?
Ying Wang, geändert vor 8 Jahren.

RE: Liferay Lucene query can't set parameter of enable wildcard

Junior Member Beiträge: 36 Beitrittsdatum: 16.05.14 Neueste Beiträge
Hello, is there anybody can give me some advice?