Merge pull request #475 from nickago/MM-1773

MM-1773a Add wildcard searching for postgresql
Этот коммит содержится в:
Christopher Speller
2015-08-31 09:03:11 -04:00
родитель 2384fe0c7b b69221aa7f
Коммит ccb5d076d5
3 изменённых файлов: 36 добавлений и 13 удалений

Просмотреть файл

@@ -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 {
@@ -358,7 +360,7 @@ func (s SqlPostStore) getParentsPosts(channelId string, offset int, limit int) S
var posts []*model.Post var posts []*model.Post
_, err := s.GetReplica().Select(&posts, _, err := s.GetReplica().Select(&posts,
`SELECT `SELECT
q2.* q2.*
FROM FROM
Posts q2 Posts q2
@@ -366,7 +368,7 @@ func (s SqlPostStore) getParentsPosts(channelId string, offset int, limit int) S
(SELECT DISTINCT (SELECT DISTINCT
q3.RootId q3.RootId
FROM FROM
(SELECT (SELECT
RootId RootId
FROM FROM
Posts Posts
@@ -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 &&