Foros de discusión

Lucene search using SearchEngineUtil.java

Ankur Bhargava, modificado hace 15 años.

Lucene search using SearchEngineUtil.java

New Member Mensaje: 1 Fecha de incorporación: 5/02/09 Mensajes recientes
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
thumbnail
Luca Preziati, modificado hace 14 años.

RE: Lucene search using SearchEngineUtil.java

Regular Member Mensajes: 120 Fecha de incorporación: 9/02/09 Mensajes recientes
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, modificado hace 12 años.

RE: Lucene search using SearchEngineUtil.java

Junior Member Mensajes: 92 Fecha de incorporación: 19/05/11 Mensajes recientes
Hi ,

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

how it find data. could u pls help me?
rajiv jackz, modificado hace 12 años.

RE: Lucene search using SearchEngineUtil.java

Junior Member Mensajes: 92 Fecha de incorporación: 19/05/11 Mensajes recientes
Hi , i fixed the problem , thanks
thumbnail
francesco scamarcio, modificado hace 12 años.

RE: Lucene search using SearchEngineUtil.java

Regular Member Mensajes: 104 Fecha de incorporación: 17/08/09 Mensajes recientes
i have de same problem. How do you fix it?
thumbnail
Puneet Malode, modificado hace 7 años.

RE: Lucene search using SearchEngineUtil.java

New Member Mensajes: 17 Fecha de incorporación: 20/07/12 Mensajes recientes
Hi Rajiv,
I know it is very old thread. But now I am facing same problem in searching with partial strings. Can you please tell me how you solved this issue?