fix incorrect results returned by phrase search
previously phrase searcher would not validate that consecutive terms were actually occurring in the same array position fixes #292
This commit is contained in:
parent
6e9da3bab7
commit
b4d4ee2fff
|
@ -16,6 +16,20 @@ type Location struct {
|
|||
ArrayPositions []float64 `json:"array_positions"`
|
||||
}
|
||||
|
||||
// SameArrayElement returns true if two locations are point to
|
||||
// the same array element
|
||||
func (l *Location) SameArrayElement(other *Location) bool {
|
||||
if len(l.ArrayPositions) != len(other.ArrayPositions) {
|
||||
return false
|
||||
}
|
||||
for i, elem := range l.ArrayPositions {
|
||||
if other.ArrayPositions[i] != elem {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type Locations []*Location
|
||||
|
||||
type TermLocationMap map[string]Locations
|
||||
|
|
|
@ -119,7 +119,7 @@ func (s *PhraseSearcher) Next() (*search.DocumentMatch, error) {
|
|||
nextLocations, ok := termLocMap[nextTerm]
|
||||
if ok {
|
||||
for _, nextLocation := range nextLocations {
|
||||
if nextLocation.Pos == location.Pos+float64(i) {
|
||||
if nextLocation.Pos == location.Pos+float64(i) && nextLocation.SameArrayElement(location) {
|
||||
// found a location match for this term
|
||||
crvtlm.AddLocation(nextTerm, nextLocation)
|
||||
continue INNER
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"body": ["bad call", "defenseless receiver"]
|
||||
}
|
|
@ -322,5 +322,55 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"search": {
|
||||
"from": 0,
|
||||
"size": 10,
|
||||
"query": {
|
||||
"field": "body",
|
||||
"match_phrase": "bad call"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"total_hits": 1,
|
||||
"hits": [
|
||||
{
|
||||
"id": "b"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"search": {
|
||||
"from": 0,
|
||||
"size": 10,
|
||||
"query": {
|
||||
"field": "body",
|
||||
"match_phrase": "defenseless receiver"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"total_hits": 1,
|
||||
"hits": [
|
||||
{
|
||||
"id": "b"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"search": {
|
||||
"from": 0,
|
||||
"size": 10,
|
||||
"query": {
|
||||
"field": "body",
|
||||
"match_phrase": "bad receiver"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"total_hits": 0,
|
||||
"hits": []
|
||||
}
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue