Task 5 — Multi-Source Search Analysis
Objective
Create a search-analysis function that processes multiple source strings and multiple requested search values.
For every requested value, determine:
- how many times it occurs in each source
- how many times it occurs in total
- whether it occurs more than three times
- whether it does not occur at all
Each search operation must also have an ID so that its result can be associated with the values requested by that search.
The searching algorithm must be implemented manually.
Sources
The three source strings are:
s1 := "zxc ert acba abcf dty ert acba abcd zxc qwe acb abcd nmv qwe acba"
s2 := "acba ghk bcacb ert acba abc sdf ert nmv bcacb dty qwe acb abcf ghk qwe"
s3 := "abcd bcacb ghk sdf nmv abc zxc sdf acba abcd sdf qwe acb abc dty qwe ghk bcacb"
Source Collection
Represent the sources as one collection.
For example:
source := []string{
s1,
s2,
s3,
}
The source index corresponds to:
0 -> s1
1 -> s2
2 -> s3
Search Request
Define a structure describing one search request:
type SearchRequest struct {
ID string
Values []string
}
Example:
SearchRequest{
ID: "search-1",
Values: []string{
"dty",
"vbn",
"nmv",
"ert",
},
}
Search Result
Define the occurrence information for one searched value:
type ValueSearchResult struct {
Value string
SourceCounts []int
TotalCount int
MoreThanThree bool
NotFound bool
}
Define the complete result for one request:
type SearchResult struct {
ID string
Results []ValueSearchResult
}
Function
Conceptually:
FindValues(
source []string,
request SearchRequest,
) SearchResult
Source Counts
For each requested value, SourceCounts contains one count for each source.
For example:
SourceCounts: []int{
2,
2,
0,
}
means:
s1 -> 2 occurrences
s2 -> 2 occurrences
s3 -> 0 occurrences
Total Count
The total count is:
sum(SourceCounts)
For:
[]int{
2,
2,
0,
}
the total is:
4
More Than Three
Set:
MoreThanThree: true
when:
TotalCount > 3
Otherwise:
MoreThanThree: false
Not Found
Set:
NotFound: true
when:
TotalCount == 0
Otherwise:
NotFound: false
Search Data 1
The original first search set is:
[]string{
"dty",
"vbn",
"nmv",
"ert",
}
Represent it as:
request := SearchRequest{
ID: "search-1",
Values: []string{
"dty",
"vbn",
"nmv",
"ert",
},
}
Call:
FindValues(source, request)
Search Data 2
The second search set is:
request := SearchRequest{
ID: "search-2",
Values: []string{
"zxc",
"df",
"ghk",
"sdf",
"gbn",
"nmv",
"hk",
},
}
Call:
FindValues(source, request)
Search Data 3
The third search set is:
request := SearchRequest{
ID: "search-3",
Values: []string{
"abc",
"abcf",
"abcd",
"acb",
"acba",
"bcacb",
"cf",
"cd",
},
}
Call:
FindValues(source, request)
Matching Rule
For this task, search values are matched as complete whitespace-separated values.
For example, searching for:
abc
matches the token:
abc
but does not automatically match the first three characters of:
abcd
Similarly:
acb
and:
acba
are treated as different values.
This makes occurrence counts deterministic and reflects the value-oriented structure of the provided source strings.
Requirements
For every requested value:
- manually inspect every source
- count complete-token matches in each source
- store one count for each source
- calculate the total count
- determine whether the total is greater than three
- determine whether the value was not found at all
- store the result under the corresponding search ID
Search ID
Every request must have a unique identifier.
The search ID makes it possible to relate the returned analysis to the collection of values that produced it.
For example:
search-1
identifies the analysis of:
dty
vbn
nmv
ert
Missing Values
Values that are never found must still appear in the result.
For example, if:
vbn
does not occur in any source:
ValueSearchResult{
Value: "vbn",
SourceCounts: []int{0, 0, 0},
TotalCount: 0,
MoreThanThree: false,
NotFound: true,
}
The same applies to other requested values that are absent.
Values Found More Than Three Times
If a searched value has:
TotalCount > 3
the result must explicitly identify that condition:
MoreThanThree: true
This is separate from the individual source counts.
Input Validation
The implementation should reject:
- empty search IDs
- empty search values
Duplicate values inside the same request should either be rejected or normalized so that one value is analyzed only once.
A search request with an empty Values collection may return an empty result.
Restricted Operations
Do not use helper functions that directly solve token searching or counting, including APIs equivalent to:
Split
Fields
Count
Contains
Index
regular expressions
Tokenization, comparison, and counting should be implemented manually.
Implementation Notes
This task combines several operations from the previous exercises:
manual scanning
↓
token identification
↓
value matching
↓
per-source counting
↓
total aggregation
↓
classification
↓
structured result
Keeping the scanning logic separate from the reporting model can make the implementation easier to test and reuse.
The result model intentionally preserves exact counts instead of returning only human-readable text, allowing presentation to be added separately.