Skip to content

Invert search logic #127

Description

@Konstantin8105

Hello,

In according to that code:

chromem-go/query.go

Lines 145 to 160 in f63964a

for k, v := range whereDocument {
switch k {
case "$contains":
if !strings.Contains(document.Content, v) {
return false
}
case "$not_contains":
if strings.Contains(document.Content, v) {
return false
}
default:
// No handling (error) required because we already validated the
// operators. This simplifies the concurrency logic (no err var
// and lock, no context to cancel).
}
}

we can create only simply filter, for example:

whereDocument =map[string]string{
"$contains":"word1",
"$not_contains", "word2",
}

but if we invert key-value, then we can more complex query. Example of code:

 for k, v := range whereDocument { 
 	switch v { // <----
 	case "$contains": 
 		if !strings.Contains(document.Content, k) { // <----
 			return false 
 		} 
 	case "$not_contains": 
 		if strings.Contains(document.Content, k) { // <----
 			return false 
 		} 
 	default: 
 		// No handling (error) required because we already validated the 
 		// operators. This simplifies the concurrency logic (no err var 
 		// and lock, no context to cancel). 
 	} 
 } 

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions