掲示板
Lucene search using SearchEngineUtil.java
15年前 に Ankur Bhargava によって更新されました。
Lucene search using SearchEngineUtil.java
New Member 投稿: 1 参加年月日: 09/02/05 最新の投稿
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
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
14年前 に Luca Preziati によって更新されました。
RE: Lucene search using SearchEngineUtil.java
Regular Member 投稿: 120 参加年月日: 09/02/09 最新の投稿
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);
}
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);
}
12年前 に rajiv jackz によって更新されました。
RE: Lucene search using SearchEngineUtil.java
Junior Member 投稿: 92 参加年月日: 11/05/19 最新の投稿
Hi ,
where is the data stored which u compare? is it in journalContentArticle?
how it find data. could u pls help me?
where is the data stored which u compare? is it in journalContentArticle?
how it find data. could u pls help me?
12年前 に rajiv jackz によって更新されました。
RE: Lucene search using SearchEngineUtil.java
Junior Member 投稿: 92 参加年月日: 11/05/19 最新の投稿
Hi , i fixed the problem , thanks
11年前 に francesco scamarcio によって更新されました。
RE: Lucene search using SearchEngineUtil.java
Regular Member 投稿: 104 参加年月日: 09/08/17 最新の投稿
i have de same problem. How do you fix it?
7年前 に Puneet Malode によって更新されました。
RE: Lucene search using SearchEngineUtil.java
New Member 投稿: 17 参加年月日: 12/07/20 最新の投稿
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?
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?