Fórum

Lucene search using SearchEngineUtil.java

Ankur Bhargava, modificado 15 Anos atrás.

Lucene search using SearchEngineUtil.java

New Member Mensagem: 1 Data de Entrada: 05/02/09 Postagens Recentes
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 14 Anos atrás.

RE: Lucene search using SearchEngineUtil.java

Regular Member Postagens: 120 Data de Entrada: 09/02/09 Postagens Recentes
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 12 Anos atrás.

RE: Lucene search using SearchEngineUtil.java

Junior Member Postagens: 92 Data de Entrada: 19/05/11 Postagens Recentes
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 12 Anos atrás.

RE: Lucene search using SearchEngineUtil.java

Junior Member Postagens: 92 Data de Entrada: 19/05/11 Postagens Recentes
Hi , i fixed the problem , thanks
thumbnail
francesco scamarcio, modificado 12 Anos atrás.

RE: Lucene search using SearchEngineUtil.java

Regular Member Postagens: 104 Data de Entrada: 17/08/09 Postagens Recentes
i have de same problem. How do you fix it?
thumbnail
Puneet Malode, modificado 7 Anos atrás.

RE: Lucene search using SearchEngineUtil.java

New Member Postagens: 17 Data de Entrada: 20/07/12 Postagens Recentes
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?