Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Ankur Bhargava
Lucene search using SearchEngineUtil.java
February 5, 2009 12:12 AM
Answer

Ankur Bhargava

Rank: New Member

Posts: 1

Join Date: February 4, 2009

Recent Posts

I am not able to search string in my indexed contents but i am able to search single word.

for e.g Indexed Content : - "Ankur is liferay developer"
if i search |"Ankur" , "liferay" , "developer" then it gives results but when I search
"liferay developer" it didnt produce any hits.

here is my implementation using SearchEnginUtil class : -

Creating Document and Field :
Field field = new Field ();
field.setName("mysearchfield");
field.setTokenized(true);
field.setValue("Ankur is liferay developer");

Document document = new DocumentImpl();
document.add(field);

SearchEngineUtil.addDocument(1, document);

using above code fragment I am able to index my document in index which is home dir of liferay
while searching :

BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create();

booleanQuery.addRequiredTerm("Ankur is liferay developer", "liferay developer");

TermQuery termQuery = TermQueryFactoryUtil.create("Ankur is liferay developer", "liferay developer");

Hits hits = SearchEngineUtil.search(1, termQuery, -1, -1);

I tried with both booleanQuery , termQuery but it didnt produce any hits if I search any string in content
What could be the reason of searching only single word not String?
pls provide solution as soon as possible.

thanks
ankur
Luca Preziati
RE: Lucene search using SearchEngineUtil.java
June 4, 2009 5:06 AM
Answer

Luca Preziati

Rank: Regular Member

Posts: 120

Join Date: February 9, 2009

Recent Posts

I suppose the problem is locate in the term building.

With this query
booleanQuery.addRequiredTerm("Ankur is liferay developer", "liferay developer");

you are searching the exact string "Ankur is liferay developer".
I think you should use this code...
String keywords="Ankur is liferay developer";
String[] terms = StringUtil.split(keywords);
if(terms.length==1)
booleanQuery.addRequiredTerm(Field.CONTENT, terms[0]);
else{
booleanQuery.addTerm(Field.CONTENT, keywords);
for(String term : terms)
booleanQuery.addTerm(Field.CONTENT, term);
}

or eventually, if all the single word are necessary, the more simple code:

String keywords="Ankur is liferay developer";
String[] terms = StringUtil.split(keywords);
for(String term : terms)
booleanQuery.addTerm(Field.CONTENT, term);
}
rajiv jackz
RE: Lucene search using SearchEngineUtil.java
August 5, 2011 12:52 AM
Answer

rajiv jackz

Rank: Junior Member

Posts: 92

Join Date: May 18, 2011

Recent Posts

Hi ,

where is the data stored which u compare? is it in journalContentArticle?

how it find data. could u pls help me?
rajiv jackz
RE: Lucene search using SearchEngineUtil.java
September 8, 2011 12:40 AM
Answer

rajiv jackz

Rank: Junior Member

Posts: 92

Join Date: May 18, 2011

Recent Posts

Hi , i fixed the problem , thanks
francesco scamarcio
RE: Lucene search using SearchEngineUtil.java
April 2, 2012 12:54 AM
Answer

francesco scamarcio

Rank: Regular Member

Posts: 104

Join Date: August 17, 2009

Recent Posts

i have de same problem. How do you fix it?