Files
core/search/Search Term.go
Akilan Selvacoumar ae5f1d2fd7 New features (#110)
* added upload status

* added changes for progress bar with more logs and bug fixes, Documentation yet to be added

* huge changes that need more doucmenting

* added possibility to get profile using NodeID

* added fix profile listing user profile information

* removed profile image from the explore reult struct

* saving current changes

* added filter to search based on NodeID

* Monday bug fixing

* updates to the profile

* changes for tracing the blockchain profile image not shown

* added condition to ensure TAG is not sent and removed debug prints

* updated webapi docs
2023-06-28 00:38:17 +01:00

58 lines
1.2 KiB
Go

/*
File name: Search Term.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/
package search
import (
"github.com/google/uuid"
)
func (index *SearchIndexStore) Search(term string) (results []SearchIndexRecord) {
if index == nil { // Search index may not be available.
return nil
}
termS, isExact, _ := sanitizeInputTerm(term)
if len(termS) < wordMinLength {
return
}
resultMap := make(map[uuid.UUID]*SearchIndexRecord)
resultMapToSlice := func() (results []SearchIndexRecord) {
for _, result := range resultMap {
results = append(results, *result)
}
return results
}
// start with exact search
hashExact, wordH := hashWord(termS)
if hashExact != nil {
index.LookupHash(SearchSelector{Hash: hashExact, Word: wordH, ExactSearch: true}, resultMap)
}
// exact search only?
if isExact {
return resultMapToSlice()
}
// break up the term into hashes
hashes := make(map[[32]byte]string)
text2Hashes(termS, hashes)
// The exact search was already performed, exclude it.
hashMapDelete(hashExact, hashes)
// look up the hashes!
for hash, keyword := range hashes {
index.LookupHash(SearchSelector{Hash: hash[:], Word: keyword}, resultMap)
}
return resultMapToSlice()
}