mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
Search: Add separator.
webapi: Search results and explore: set tag TagSharedByCount if file owner is active peer.
This commit is contained in:
@@ -21,7 +21,7 @@ func text2Hashes(text string, hashes map[[32]byte]string) {
|
|||||||
if unicode.IsSpace(char) {
|
if unicode.IsSpace(char) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return strings.ContainsAny(string(char), "+-._()[],")
|
return strings.ContainsAny(string(char), "+-._()[],–")
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, word := range words {
|
for _, word := range words {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/PeernetOfficial/core"
|
"github.com/PeernetOfficial/core"
|
||||||
|
"github.com/PeernetOfficial/core/blockchain"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (api *WebapiInstance) dispatchSearch(input SearchRequest) (job *SearchJob) {
|
func (api *WebapiInstance) dispatchSearch(input SearchRequest) (job *SearchJob) {
|
||||||
@@ -44,16 +45,20 @@ resultLoop:
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// new result
|
|
||||||
newFile := blockRecordFileToAPI(file)
|
|
||||||
|
|
||||||
// Deduplicate based on file hash from the same peer.
|
// Deduplicate based on file hash from the same peer.
|
||||||
for n := range job.AllFiles {
|
for n := range job.AllFiles {
|
||||||
if bytes.Equal(job.AllFiles[n].Hash, newFile.Hash) && bytes.Equal(job.AllFiles[n].NodeID, newFile.NodeID) {
|
if bytes.Equal(job.AllFiles[n].Hash, file.Hash) && bytes.Equal(job.AllFiles[n].NodeID, file.NodeID) {
|
||||||
continue resultLoop
|
continue resultLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if peer := core.NodelistLookup(file.NodeID); peer != nil {
|
||||||
|
file.Tags = append(file.Tags, blockchain.TagFromNumber(blockchain.TagSharedByCount, 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// new result
|
||||||
|
newFile := blockRecordFileToAPI(file)
|
||||||
|
|
||||||
job.Files = append(job.Files, &newFile)
|
job.Files = append(job.Files, &newFile)
|
||||||
job.AllFiles = append(job.AllFiles, &newFile)
|
job.AllFiles = append(job.AllFiles, &newFile)
|
||||||
job.requireSort = true
|
job.requireSort = true
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ func queryRecentShared(backend *core.Backend, fileType int, limitPeer, limitTota
|
|||||||
|
|
||||||
for _, record := range blockDecoded.RecordsDecoded {
|
for _, record := range blockDecoded.RecordsDecoded {
|
||||||
if file, ok := record.(blockchain.BlockRecordFile); ok && isFileTypeMatchBlock(&file, fileType) {
|
if file, ok := record.(blockchain.BlockRecordFile); ok && isFileTypeMatchBlock(&file, fileType) {
|
||||||
|
file.Tags = append(file.Tags, blockchain.TagFromNumber(blockchain.TagSharedByCount, 1))
|
||||||
|
|
||||||
// found a new file! append.
|
// found a new file! append.
|
||||||
if filesFromPeer < limitPeer {
|
if filesFromPeer < limitPeer {
|
||||||
files = append(files, file)
|
files = append(files, file)
|
||||||
|
|||||||
Reference in New Issue
Block a user