name
및 description
이있는 모델이 있습니다. 사용자가 name 또는 description의 문자열 부분을 검색 할 수 있도록 허용해야합니다. 대신 SQL 쿼리를 사용하여이 작업을 수행합니다. playframework
에 설치할 수있는 search
모듈을 사용하려고 생각했습니다. 검색 모듈에 대한 문서를 보면playframework의 검색 모듈을 사용하여 적절한
, 나는이
같은 SQL 쿼리를 사용하는 경우@Entity
@Indexed
class Item{
@Field
public String name;
@Field
public String description;
public Date creationDate;
...
...
}
이 application.conf에서, 나는
play.search.reindex=enabled
을 설정
모델에 이러한 주석을 넣어public static List<Item> getSearchResults(String kw){
List<Item> items = null;
if(kw!=null && kw.length()>0) {
String trimkw = kw.trim().toLowerCase();
String pattern = "%"+trimkw+"%";
String query="select distinct b from Item b where (lower(name) like :pattern or lower(description) like :pattern)";
items = Item.find(query).bind("pattern", pattern).fetch();
System.out.println("getSearchResults():: items="+items.size());
}
return items;
}
제대로 작동하고 입력 문자열이 대소 문자 등 인 경우를 처리합니다. 또한 i t는
I have items JavaRing ,Android
when the kw="JAvA"
the search returns a list containing JavaRing
, 예를 들어 .. 부분 문자열을 결과를 얻을 나는이
import play.modules.search.Search;
import play.modules.search.Query;
...
String qstr = "name:"+trimkw+" OR description:"+trimkw;
System.out.println("query string="+qstr);
Query q = Search.search(qstr, Item.class);
items = q.fetch();
System.out.println("items="+items.size());
같은 검색 모듈을 사용하여 시도하지만 이전에 사용 된 것과 동일한 키워드 빈 목록을 반환 케이스.
keyword = "JAvA"
query string=name:java OR description:java
items=0
검색 문자열을 코딩 한 방식에 문제가 있습니까?