浏览代码

Add files via upload

wibyweb 1 年之前
父节点
当前提交
2d969c8611
共有 2 个文件被更改,包括 63 次插入58 次删除
  1. 19 20
      go/core/1core.go
  2. 44 38
      go/core/core.go

+ 19 - 20
go/core/1core.go

@@ -458,6 +458,13 @@ func handler(w http.ResponseWriter, r *http.Request) {
 		}
 
 		count := 0
+		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() {
 			count++
@@ -473,38 +480,30 @@ func handler(w http.ResponseWriter, r *http.Request) {
 
 			//find query inside body of page
 			if exactMatch == false && (numRequiredWords == 0 || numRequiredWords + wordcount == numRequiredWords){
-				/*					//remove the '*' if contained anywhere in query
-									if strings.Contains(queryNoQuotes,"*"){
-										queryNoQuotes = strings.Replace(queryNoQuotes, "*", "", -1)
-									}	*/
-
 				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 {
-					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 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 {
-							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
-				pos = strings.Index(strings.ToLower(body), strings.ToLower(queryNoQuotesOrFlags))
+				pos = strings.Index(strings.ToLower(body), stringtofind)
 			}
 
 			//still not found?, set position to 0

+ 44 - 38
go/core/core.go

@@ -624,6 +624,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
 				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() {
 				count++
 				countResults++
@@ -641,40 +649,33 @@ func handler(w http.ResponseWriter, r *http.Request) {
 				ids = append(ids,id)
 
 				//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
-						pos = strings.Index(strings.ToLower(body), strings.ToLower(requiredword))
+						pos = strings.Index(strings.ToLower(body), requiredwordtofind)
 					} 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 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 {
-								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
-					pos = strings.Index(strings.ToLower(body), strings.ToLower(queryNoQuotesOrFlags))
+					pos = strings.Index(strings.ToLower(body), stringtofind)
 				}
+
 				//still not found?, set position to 0
 				if pos == -1 {
 					pos = 0
@@ -846,6 +847,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
 				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() {
 				count++
 				//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
-				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
-						pos = strings.Index(strings.ToLower(body), strings.ToLower(requiredword))
+						pos = strings.Index(strings.ToLower(body), requiredwordtofind)
 					} 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 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 {
-								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
-					pos = strings.Index(strings.ToLower(body), strings.ToLower(queryNoQuotesOrFlags))
+					pos = strings.Index(strings.ToLower(body), stringtofind)
 				}
+
 				//still not found?, set position to 0
 				if pos == -1 {
 					pos = 0