Merge pull request #475 from nickago/MM-1773
MM-1773a Add wildcard searching for postgresql
Этот коммит содержится в:
@@ -5,9 +5,11 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SqlPostStore struct {
|
type SqlPostStore struct {
|
||||||
@@ -417,6 +419,12 @@ func (s SqlPostStore) Search(teamId string, userId string, terms string, isHasht
|
|||||||
var posts []*model.Post
|
var posts []*model.Post
|
||||||
|
|
||||||
if utils.Cfg.SqlSettings.DriverName == "postgres" {
|
if utils.Cfg.SqlSettings.DriverName == "postgres" {
|
||||||
|
|
||||||
|
// Parse text for wildcards
|
||||||
|
if wildcard, err := regexp.Compile("\\*($| )"); err == nil {
|
||||||
|
terms = wildcard.ReplaceAllLiteralString(terms, ":* ")
|
||||||
|
}
|
||||||
|
|
||||||
searchQuery := fmt.Sprintf(`SELECT
|
searchQuery := fmt.Sprintf(`SELECT
|
||||||
*
|
*
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/platform/model"
|
|
||||||
"github.com/mattermost/platform/utils"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattermost/platform/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPostStoreSave(t *testing.T) {
|
func TestPostStoreSave(t *testing.T) {
|
||||||
@@ -547,11 +547,9 @@ func TestPostStoreSearch(t *testing.T) {
|
|||||||
t.Fatal("returned wrong serach result")
|
t.Fatal("returned wrong serach result")
|
||||||
}
|
}
|
||||||
|
|
||||||
if utils.Cfg.SqlSettings.DriverName == "mysql" {
|
r5 := (<-store.Post().Search(teamId, userId, "matter*", false)).Data.(*model.PostList)
|
||||||
r5 := (<-store.Post().Search(teamId, userId, "matter*", false)).Data.(*model.PostList)
|
if len(r5.Order) != 1 && r5.Order[0] != o1.Id {
|
||||||
if len(r5.Order) != 1 && r5.Order[0] != o1.Id {
|
t.Fatal("returned wrong serach result")
|
||||||
t.Fatal("returned wrong serach result")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r6 := (<-store.Post().Search(teamId, userId, "#hashtag", true)).Data.(*model.PostList)
|
r6 := (<-store.Post().Search(teamId, userId, "#hashtag", true)).Data.(*model.PostList)
|
||||||
@@ -573,4 +571,9 @@ func TestPostStoreSearch(t *testing.T) {
|
|||||||
if len(r9.Order) != 2 {
|
if len(r9.Order) != 2 {
|
||||||
t.Fatal("returned wrong search result")
|
t.Fatal("returned wrong search result")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r10 := (<-store.Post().Search(teamId, userId, "matter* jer*", false)).Data.(*model.PostList)
|
||||||
|
if len(r10.Order) != 2 {
|
||||||
|
t.Fatal("returned wrong search result")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -456,9 +456,21 @@ module.exports.textToJsx = function(text, options) {
|
|||||||
var mentionRegex = /^(?:@)([a-z0-9_]+)$/gi; // looks loop invariant but a weird JS bug needs it to be redefined here
|
var mentionRegex = /^(?:@)([a-z0-9_]+)$/gi; // looks loop invariant but a weird JS bug needs it to be redefined here
|
||||||
var explicitMention = mentionRegex.exec(trimWord);
|
var explicitMention = mentionRegex.exec(trimWord);
|
||||||
|
|
||||||
if ((trimWord.toLowerCase().indexOf(searchTerm) > -1 || word.toLowerCase().indexOf(searchTerm) > -1) && searchTerm != '') {
|
if (searchTerm !== '') {
|
||||||
|
let searchWords = searchTerm.split(' ');
|
||||||
highlightSearchClass = ' search-highlight';
|
for (let idx in searchWords) {
|
||||||
|
let searchWord = searchWords[idx];
|
||||||
|
if (searchWord === word.toLowerCase() || searchWord === trimWord.toLowerCase()) {
|
||||||
|
highlightSearchClass = ' search-highlight';
|
||||||
|
break;
|
||||||
|
} else if (searchWord.charAt(searchWord.length - 1) === '*') {
|
||||||
|
let searchWordPrefix = searchWord.slice(0,-1);
|
||||||
|
if (trimWord.toLowerCase().indexOf(searchWordPrefix) > -1 || word.toLowerCase().indexOf(searchWordPrefix) > -1) {
|
||||||
|
highlightSearchClass = ' search-highlight';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (explicitMention &&
|
if (explicitMention &&
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user