나는 Mongodb에서 텍스트 검색에 대해 집계 메소드를 사용하고 있습니다. 나는 이것으로 다양한 방법을 시도했지만 여전히 내 결과를 필터링하는 올바른 방법을 찾을 수 없습니다. 인덱스를 설정했는데 $ 텍스트 검색만으로도 잘 작동하며 쿼리만으로도 잘 작동합니다. 나는이 쿼리에 의해 더 모델을 필터링 할 수 있도록하려는 그러나Mongodb - 검색 쿼리로 집계 텍스트 검색을 사용하는 방법
Model.aggregate([
{ $match: { $text: { $search: searchValue } } },
{ $project: { displayTitle: 1, title: 1, body: 1, _type: 1, _id: 1, score: { $meta: "textScore" } } },
{ $match: { score: { $gt: 1.0 } } }
], function (err, models) {
})
:
다음은 텍스트 검색을 수행 내 코드의
나는이 일 것이라고 생각했을 것이다Model.find({_parentIds: {$in: arrayOfIds}})
:
Model.aggregate([
{ $match: { $text: { $search: searchValue }, _parentIds: {$in: arrayOfIds} } },
{ $project: { displayTitle: 1, title: 1, body: 1, _type: 1, _id: 1, score: { $meta: "textScore" } } },
{ $match: { score: { $gt: 1.0 } } }
])
하지만 슬프게도 그렇지 않습니다. 아무도 이것을 시도 했습니까, 아니면 제가 빠진 것이 있습니까? 이 같은 것
[{
displayTitle: "first item",
title: "first_item",
_type: "item",
_parentIds: ["123", "234"]
}, {
displayTitle: "second item",
title: "second_item",
_type: "item",
_parentIds: ["123", "234"]
}, {
displayTitle: "third item",
title: "third_item",
_type: "item",
_parentIds: ["345", "456"]
}]
내 현재 검색 :
searchValue = "item"
arrayOfIds = ["345"];
만 다시이 문서를 기다리고있을 것입니다 :
{
displayTitle: "third item",
title: "third_item",
_type: "item",
_parentIds: ["345", "456"]
}
여기
내가 통해 찾고 있어요 예를 들어 모음입니다
감사!
당신이 샘플 문서 예상 출력을 추가시겠습니까? – Veeram
@Veeram - 샘플 컬렉션과 예상 출력을 추가했습니다. – darylhedley