added 'contains' filter
This commit is contained in:
parent
c7ac4a48c3
commit
60da3b9f91
4 changed files with 103 additions and 0 deletions
23
scraping.go
23
scraping.go
|
@ -74,6 +74,10 @@ func getFilterResult(filter *Filter, db *gorm.DB, urlCache map[string]string, us
|
||||||
{
|
{
|
||||||
getFilterResultSubstring(filter)
|
getFilterResultSubstring(filter)
|
||||||
}
|
}
|
||||||
|
case filter.Type == "contains":
|
||||||
|
{
|
||||||
|
getFilterResultContains(filter)
|
||||||
|
}
|
||||||
case filter.Type == "math":
|
case filter.Type == "math":
|
||||||
{
|
{
|
||||||
switch {
|
switch {
|
||||||
|
@ -313,6 +317,25 @@ func getFilterResultSubstring(filter *Filter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFilterResultContains(filter *Filter) {
|
||||||
|
substring := filter.Var1
|
||||||
|
invert, err := strconv.ParseBool(*filter.Var2)
|
||||||
|
if err != nil {
|
||||||
|
invert = false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, parent := range filter.Parents {
|
||||||
|
for _, result := range parent.Results {
|
||||||
|
log.Println(result, substring, invert, strings.Contains(result, substring))
|
||||||
|
if strings.Contains(result, substring) {
|
||||||
|
filter.Results = append(filter.Results, result)
|
||||||
|
} else if invert {
|
||||||
|
filter.Results = append(filter.Results, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getFilterResultSum(filter *Filter) {
|
func getFilterResultSum(filter *Filter) {
|
||||||
var sum float64 = 0.0
|
var sum float64 = 0.0
|
||||||
for _, parent := range filter.Parents {
|
for _, parent := range filter.Parents {
|
||||||
|
|
|
@ -277,6 +277,45 @@ function onTypeChange(node) {
|
||||||
var3Div.appendChild(var3Input);
|
var3Div.appendChild(var3Input);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "contains": {
|
||||||
|
var var1Input = document.createElement("input");
|
||||||
|
var1Input.name = "var1";
|
||||||
|
var1Input.id = "var1Input";
|
||||||
|
var1Input.value = var1Value;
|
||||||
|
var1Input.classList.add("form-control");
|
||||||
|
var1Label.innerHTML = "Substring";
|
||||||
|
var1Input.placeholder = "some";
|
||||||
|
var1Div.appendChild(var1Input);
|
||||||
|
var notSelect = document.createElement("select");
|
||||||
|
notSelect.name = "var2";
|
||||||
|
notSelect.id = "var2Input";
|
||||||
|
notSelect.classList.add("form-control");
|
||||||
|
var no = document.createElement("option");
|
||||||
|
no.value = "false";
|
||||||
|
no.innerHTML = "No";
|
||||||
|
notSelect.appendChild(no);
|
||||||
|
var yes = document.createElement("option");
|
||||||
|
yes.value = "true";
|
||||||
|
yes.innerHTML = "Yes";
|
||||||
|
notSelect.appendChild(yes);
|
||||||
|
var2Div.appendChild(notSelect);
|
||||||
|
var2Label.innerHTML = "Invert";
|
||||||
|
if (var2Value == "true" || var2Value == "false") {
|
||||||
|
notSelect.value = var2Value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
notSelect.value = "false";
|
||||||
|
}
|
||||||
|
var var3Input = document.createElement("input");
|
||||||
|
var3Input.name = "var3";
|
||||||
|
var3Input.id = "var3Input";
|
||||||
|
var3Input.value = var3Value;
|
||||||
|
var3Input.classList.add("form-control");
|
||||||
|
var3Input.disabled = true;
|
||||||
|
var3Label.innerHTML = "-";
|
||||||
|
var3Div.appendChild(var3Input);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "math": {
|
case "math": {
|
||||||
var mathSelect = document.createElement("select");
|
var mathSelect = document.createElement("select");
|
||||||
mathSelect.name = "var1";
|
mathSelect.name = "var1";
|
||||||
|
|
|
@ -266,6 +266,46 @@ function onTypeChange(node: DiagramNode | null = null){
|
||||||
var3Div.appendChild(var3Input);
|
var3Div.appendChild(var3Input);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "contains": {
|
||||||
|
let var1Input = document.createElement("input");
|
||||||
|
var1Input.name = "var1";
|
||||||
|
var1Input.id = "var1Input";
|
||||||
|
var1Input.value = var1Value;
|
||||||
|
var1Input.classList.add("form-control")
|
||||||
|
var1Label.innerHTML = "Substring";
|
||||||
|
var1Input.placeholder = "some";
|
||||||
|
var1Div.appendChild(var1Input);
|
||||||
|
|
||||||
|
let notSelect = document.createElement("select");
|
||||||
|
notSelect.name = "var2";
|
||||||
|
notSelect.id = "var2Input";
|
||||||
|
notSelect.classList.add("form-control");
|
||||||
|
let no = document.createElement("option");
|
||||||
|
no.value = "false"
|
||||||
|
no.innerHTML = "No";
|
||||||
|
notSelect.appendChild(no);
|
||||||
|
let yes = document.createElement("option");
|
||||||
|
yes.value = "true"
|
||||||
|
yes.innerHTML = "Yes";
|
||||||
|
notSelect.appendChild(yes);
|
||||||
|
var2Div.appendChild(notSelect);
|
||||||
|
var2Label.innerHTML = "Invert";
|
||||||
|
if (var2Value == "true" || var2Value == "false"){
|
||||||
|
notSelect.value = var2Value;
|
||||||
|
} else {
|
||||||
|
notSelect.value = "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
let var3Input = document.createElement("input");
|
||||||
|
var3Input.name = "var3";
|
||||||
|
var3Input.id = "var3Input";
|
||||||
|
var3Input.value = var3Value;
|
||||||
|
var3Input.classList.add("form-control");
|
||||||
|
var3Input.disabled = true;
|
||||||
|
var3Label.innerHTML = "-";
|
||||||
|
var3Div.appendChild(var3Input);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "math": {
|
case "math": {
|
||||||
let mathSelect = document.createElement("select");
|
let mathSelect = document.createElement("select");
|
||||||
mathSelect.name = "var1";
|
mathSelect.name = "var1";
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
<option value="replace">Replace</option>
|
<option value="replace">Replace</option>
|
||||||
<option value="match">Match</option>
|
<option value="match">Match</option>
|
||||||
<option value="substring">Substring</option>
|
<option value="substring">Substring</option>
|
||||||
|
<option value="contains">Contains</option>
|
||||||
<option value="math">Math</option>
|
<option value="math">Math</option>
|
||||||
<option value="store">Store</option>
|
<option value="store">Store</option>
|
||||||
<option value="condition">Condition</option>
|
<option value="condition">Condition</option>
|
||||||
|
|
Loading…
Add table
Reference in a new issue