Cloudant를 처음 사용했지만 DB2 용 SQL에서 얼마 동안 개발했습니다. Lucene 쿼리 엔진과 Cloudant 인덱스를 사용하여 쿼리에서 결과를 반환한다고 생각하는 문제가 발생했습니다. 그러나 쿼리는 내가 원하는 모든 결과를 얻을 수 있지만 올바르게 정렬되지는 않습니다. "officialName"필드를 기반으로 사전 순으로 결과를 정렬하고 싶습니다. 왜냐하면 우리는 n 개의 결과 중 처음 21 개만 반환하기 때문에 (그리고 js 처리기를 사용하여 페이징을 통해 더 많은 결과를 호출 할 수 있습니다) 자바 측에서 정렬 할 수 없지만 Cloudant를 통해 그렇게해야합니다. 우리의 애플리케이션은 Java를 실행하고 IBM의 Bluemix 및 WebSphere Liberty Profile을 사용하여 실행됩니다. cloudant-client-2.8.0.jar 및 cloudant-HTTP-2.8.0.jar 파일을 패키지화하여 Cloudant 데이터베이스에 액세스합니다. 우리는 많은 쿼리를 사용하므로 연결 자체가 정상입니다.Lucene 검색을 사용하는 Cloudant 검색이 예상대로 정렬되지 않음
다음Search search = getCloudantDbForOurApp().search("bySearchPP-ddoc/bySearchPP-indx").includeDocs(true);
SearchResult<DeliverableDetails> result = search.sort(getSortJsonString(searchString)).querySearchResult(getSearchQuery(searchString), DeliverableDetails.class);
이 방법 getSortJsonString입니다 : 여기
는 Cloudant 클라이언트 검색 객체를 구축 코드입니다. 검색 문자열은 대개 null이 아니므로주의해야합니다. -score 속성을 남기거나 꺼내면 검색에는 영향을 미치지 만 알파 정렬 된 결과는 얻지 못한다는 점에 유의해야합니다.{
"_id": "_design/bySearchPP-ddoc",
"_rev": "4-a91fc4ddeccc998c58adb487a121c168",
"views": {},
"language": "javascript",
"indexes": {
"bySearchPP-indx": {
"analyzer": {
"name": "perfield",
"default": "standard",
"fields": {
"alias": "simple",
"contact": "simple",
"deploymentTarget": "keyword",
"businessUnit": "keyword",
"division": "keyword",
"officialName": "simple",
"deliverableName": "simple",
"pid": "keyword"
}
},
"index": "function(doc) {
if (doc.docType === \"Page\") {
index(\"officialName\", doc.officialName, {\"store\":true, \"boost\":4.0});
index(\"deliverableName\", doc.deliverableName, {\"store\":true, \"boost\":3.0});
if (doc.aliases) {
for (var i in doc.aliases) {
index(\"alias\", doc.aliases[i], {\"store\":true, \"boost\":2.0});
}
}
if (doc.allContacts) {
for (var j in doc.allContacts) {
index(\"contact\", doc.allContacts[j], {\"store\":true, \"boost\":0.5});
}
}
index(\"deploymentTarget\", doc.deploymentTarget, {\"store\":true});
index(\"businessUnit\", doc.businessUnit, {\"store\":true});
index(\"division\", doc.division, {\"store\":true});
index(\"pid\", doc.pid.toLowerCase(), {\"store\":true});
}
}"
}
}
}
나는 확실하지 않다 다음과 같이 내가 설정에게 Cloudant 대시 보드를 사용하여 설계 문서 및 인덱스가
...
query += "(";
query += "officialName:" + searchString + "^3";
query += " OR " + "deliverableName:" + searchString + "^3";
query += " OR " + "alias:" + searchString + "^3";
query += " OR " + "contact:" + searchString;
query += ")";
....
// The query will look like below, where<search_string> is some user inputted value
// (officialName:<search_string>*^3 OR deliverableName:<search_string>*^3 OR alias:<search_string>*^3 OR contact:<search_string>*)
: 여기
private String getSortJsonString(String searchString) {
String sortJson;
if (searchString != null && !searchString.isEmpty()) {
sortJson = "[\"-<score>\",\"officialName<string>\"]";
} else {
sortJson = "\"officialName<string>\"";
}
return sortJson;
}
은 참조를 위해 getSearchQuery 방법의 관련 코드입니다 정렬 작업이 제대로 작동하지 않거나 잘못 입력 한 경우. 어느 쪽이든, 어떤 도움을 크게 주시면 감사하겠습니다. -Doug
먼저 점수로 정렬 한 다음 공식 이름별로 정렬합니다. 이것은 문제가되지 않습니까? – markwatsonatx
[SearchResultRow] (http://static.javadoc.io/com.cloudant/cloudant-client/2.2.0/com/cloudant/client/api/model/SearchResult.SearchResultRow.html)에서 주문을 볼 수 있습니다. 정렬에 사용 된 값을 볼 수 있습니다. 각 행에 대한 배열의 첫 번째 값은 정렬에 사용 된 첫 번째 값에 해당합니다. (Object obj : row.getOrder()) { for System.out.println (obj); } – markwatsonatx
@markwatsonatx - 점수 태그를 가져 왔는지 여부에 관계없이 작동하지 않았습니다. 그는 디버그 팁 주셔서 감사합니다. 공식 이름 값이 반환되지 않았 음을 나타냅니다. 파고가 있었는데 필드가 색인되었지만 토큰 화되어서는 안된다는 것을 알았습니다. 색인 양식 간단한 분석기를 키워드로 변경했을 때 효과적이었습니다! 팁 주셔서 감사. – Doug