|
@@ -624,6 +624,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|
query = queryOriginal
|
|
query = queryOriginal
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ wordtocheck := ""
|
|
|
|
+ stringtofind := strings.ToLower(queryNoQuotesOrFlags)
|
|
|
|
+ stringtofind = strings.Replace(stringtofind, "''", "'", -1)
|
|
|
|
+ requiredwordtofind := strings.ToLower(requiredword)
|
|
|
|
+ requiredwordtofind = strings.Replace(requiredwordtofind, "''", "'", -1)
|
|
|
|
+ longestWordtofind := strings.ToLower(longestWord)
|
|
|
|
+ longestWordtofind = strings.Replace(longestWordtofind, "''", "'", -1)
|
|
|
|
+
|
|
for rows.Next() {
|
|
for rows.Next() {
|
|
count++
|
|
count++
|
|
countResults++
|
|
countResults++
|
|
@@ -641,40 +649,33 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|
ids = append(ids,id)
|
|
ids = append(ids,id)
|
|
|
|
|
|
//find query inside body of page
|
|
//find query inside body of page
|
|
- if exactMatch == false && (flagssetbyuser == 0 || flagssetbyuser + wordcount == flagssetbyuser){
|
|
|
|
- //remove the '*' if contained anywhere in query
|
|
|
|
- /*if strings.Contains(queryNoQuotes,"*"){
|
|
|
|
- queryNoQuotes = strings.Replace(queryNoQuotes, "*", "", -1)
|
|
|
|
- } */
|
|
|
|
-
|
|
|
|
|
|
+ if exactMatch == false && (numRequiredWords == 0 || numRequiredWords + wordcount == numRequiredWords){
|
|
if len(requiredword) > 0 { //search for position of required word if any, else search for position of whole query
|
|
if len(requiredword) > 0 { //search for position of required word if any, else search for position of whole query
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(requiredword))
|
|
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), requiredwordtofind)
|
|
} else if pos == -1 {
|
|
} else if pos == -1 {
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(queryNoQuotesOrFlags))
|
|
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), stringtofind)
|
|
}
|
|
}
|
|
|
|
|
|
- if pos == -1 { //prepare to find position of longest query word (or required word) within body
|
|
|
|
- //remove the '*' at the end of the longest word if present
|
|
|
|
- if strings.Contains(longestWord, "*") {
|
|
|
|
- longestWord = strings.Replace(longestWord, "*", "", -1)
|
|
|
|
- }
|
|
|
|
- //search within body for position of longest query word.
|
|
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(longestWord))
|
|
|
|
- //not found?, set position to a different word, make sure there's no wildcard on it
|
|
|
|
|
|
+ if pos == -1 { //not found? find position of longest query word
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), longestWordtofind)
|
|
|
|
+ //not found?, set position to a different word
|
|
if pos == -1 && wordcount > 1 {
|
|
if pos == -1 && wordcount > 1 {
|
|
if longestwordelementnum > 0 {
|
|
if longestwordelementnum > 0 {
|
|
- words[0] = strings.Replace(words[0], "*", "", -1)
|
|
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(words[0]))
|
|
|
|
|
|
+ //wordtocheck = strings.Replace(words[0], "*", "", -1)
|
|
|
|
+ wordtocheck = strings.Replace(words[0], "''", "'", -1)
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), strings.ToLower(wordtocheck))
|
|
}
|
|
}
|
|
if longestwordelementnum == 0 {
|
|
if longestwordelementnum == 0 {
|
|
- words[1] = strings.Replace(words[1], "*", "", -1)
|
|
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(words[1]))
|
|
|
|
|
|
+ //wordtocheck = strings.Replace(words[1], "*", "", -1)
|
|
|
|
+ wordtocheck = strings.Replace(words[1], "''", "'", -1)
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), strings.ToLower(wordtocheck))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else { //if exact match, find position of query within body
|
|
} else { //if exact match, find position of query within body
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(queryNoQuotesOrFlags))
|
|
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), stringtofind)
|
|
}
|
|
}
|
|
|
|
+
|
|
//still not found?, set position to 0
|
|
//still not found?, set position to 0
|
|
if pos == -1 {
|
|
if pos == -1 {
|
|
pos = 0
|
|
pos = 0
|
|
@@ -846,6 +847,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ wordtocheck := ""
|
|
|
|
+ stringtofind := strings.ToLower(queryNoQuotesOrFlags)
|
|
|
|
+ stringtofind = strings.Replace(stringtofind, "''", "'", -1)
|
|
|
|
+ requiredwordtofind := strings.ToLower(requiredword)
|
|
|
|
+ requiredwordtofind = strings.Replace(requiredwordtofind, "''", "'", -1)
|
|
|
|
+ longestWordtofind := strings.ToLower(longestWord)
|
|
|
|
+ longestWordtofind = strings.Replace(longestWordtofind, "''", "'", -1)
|
|
|
|
+
|
|
for rows2.Next() {
|
|
for rows2.Next() {
|
|
count++
|
|
count++
|
|
//this will get set if position of longest word of query is found within body
|
|
//this will get set if position of longest word of query is found within body
|
|
@@ -859,36 +868,33 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
|
|
|
|
//find query inside body of page
|
|
//find query inside body of page
|
|
- if exactMatch == false && (flagssetbyuser == 0 || flagssetbyuser + wordcount == flagssetbyuser){
|
|
|
|
-
|
|
|
|
|
|
+ if exactMatch == false && (numRequiredWords == 0 || numRequiredWords + wordcount == numRequiredWords){
|
|
if len(requiredword) > 0 { //search for position of required word if any, else search for position of whole query
|
|
if len(requiredword) > 0 { //search for position of required word if any, else search for position of whole query
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(requiredword))
|
|
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), requiredwordtofind)
|
|
} else if pos == -1 {
|
|
} else if pos == -1 {
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(queryNoQuotesOrFlags))
|
|
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), stringtofind)
|
|
}
|
|
}
|
|
|
|
|
|
- if pos == -1 { //prepare to find position of longest query word (or required word) within body
|
|
|
|
- //remove the '*' at the end of the longest word if present
|
|
|
|
- if strings.Contains(longestWord, "*") {
|
|
|
|
- longestWord = strings.Replace(longestWord, "*", "", -1)
|
|
|
|
- }
|
|
|
|
- //search within body for position of longest query word.
|
|
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(longestWord))
|
|
|
|
- //not found?, set position to a different word, make sure there's no wildcard on it
|
|
|
|
|
|
+ if pos == -1 { //not found? find position of longest query word
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), longestWordtofind)
|
|
|
|
+ //not found?, set position to a different word
|
|
if pos == -1 && wordcount > 1 {
|
|
if pos == -1 && wordcount > 1 {
|
|
if longestwordelementnum > 0 {
|
|
if longestwordelementnum > 0 {
|
|
- words[0] = strings.Replace(words[0], "*", "", -1)
|
|
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(words[0]))
|
|
|
|
|
|
+ //wordtocheck = strings.Replace(words[0], "*", "", -1)
|
|
|
|
+ wordtocheck = strings.Replace(words[0], "''", "'", -1)
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), strings.ToLower(wordtocheck))
|
|
}
|
|
}
|
|
if longestwordelementnum == 0 {
|
|
if longestwordelementnum == 0 {
|
|
- words[1] = strings.Replace(words[1], "*", "", -1)
|
|
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(words[1]))
|
|
|
|
|
|
+ //wordtocheck = strings.Replace(words[1], "*", "", -1)
|
|
|
|
+ wordtocheck = strings.Replace(words[1], "''", "'", -1)
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), strings.ToLower(wordtocheck))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else { //if exact match, find position of query within body
|
|
} else { //if exact match, find position of query within body
|
|
- pos = strings.Index(strings.ToLower(body), strings.ToLower(queryNoQuotesOrFlags))
|
|
|
|
|
|
+ pos = strings.Index(strings.ToLower(body), stringtofind)
|
|
}
|
|
}
|
|
|
|
+
|
|
//still not found?, set position to 0
|
|
//still not found?, set position to 0
|
|
if pos == -1 {
|
|
if pos == -1 {
|
|
pos = 0
|
|
pos = 0
|