11using Microsoft . EntityFrameworkCore ;
2+ using JiebaNet . Segmenter ;
3+ using LinqKit ;
24using Netnr . Core ;
35using Netnr . Blog . Data ;
46using Netnr . Blog . Domain ;
5- using JiebaNet . Segmenter ;
6- using LinqKit ;
7+ using Netnr . SharedFast ;
78
89namespace Netnr . Blog . Application
910{
@@ -137,7 +138,19 @@ join b in db.UserWriting on a.UwId equals b.UwId
137138 kws = kws . Distinct ( ) . ToList ( ) ;
138139
139140 var inner = PredicateBuilder . New < UserWriting > ( ) ;
140- kws . ForEach ( k => inner . Or ( x => x . UwTitle . Contains ( k ) ) ) ;
141+ switch ( GlobalTo . TDB )
142+ {
143+ case SharedEnum . TypeDB . SQLite :
144+ kws . ForEach ( k => inner . Or ( x => EF . Functions . Like ( x . UwTitle , $ "%{ k } %") ) ) ;
145+ break ;
146+ case SharedEnum . TypeDB . PostgreSQL :
147+ kws . ForEach ( k => inner . Or ( x => EF . Functions . ILike ( x . UwTitle , $ "%{ k } %") ) ) ;
148+ break ;
149+ default :
150+ kws . ForEach ( k => inner . Or ( x => x . UwTitle . Contains ( k ) ) ) ;
151+ break ;
152+ }
153+
141154 query = query . Where ( inner ) ;
142155 }
143156
@@ -549,7 +562,12 @@ orderby a.GistCreateTime descending
549562
550563 if ( ! string . IsNullOrWhiteSpace ( q ) )
551564 {
552- query1 = query1 . Where ( x => x . a . GistFilename . Contains ( q ) || x . a . GistContent . Contains ( q ) || x . a . GistRemark . Contains ( q ) ) ;
565+ query1 = GlobalTo . TDB switch
566+ {
567+ SharedEnum . TypeDB . SQLite => query1 . Where ( x => EF . Functions . Like ( x . a . GistFilename , $ "%{ q } %") || EF . Functions . Like ( x . a . GistRemark , $ "%{ q } %") || EF . Functions . Like ( x . a . GistContent , $ "%{ q } %") ) ,
568+ SharedEnum . TypeDB . PostgreSQL => query1 . Where ( x => EF . Functions . ILike ( x . a . GistFilename , $ "%{ q } %") || EF . Functions . ILike ( x . a . GistRemark , $ "%{ q } %") || EF . Functions . ILike ( x . a . GistContent , $ "%{ q } %") ) ,
569+ _ => query1 . Where ( x => x . a . GistFilename . Contains ( q ) || x . a . GistRemark . Contains ( q ) || x . a . GistContent . Contains ( q ) ) ,
570+ } ;
553571 }
554572
555573 //所属用户
@@ -576,11 +594,31 @@ orderby a.GistCreateTime descending
576594 {
577595 var query2 = query1 . Select ( x => new
578596 {
579- SearchOrder = ( x . a . GistFilename . Contains ( q ) ? 4 : 0 ) + ( x . a . GistContent . Contains ( q ) ? 2 : 0 ) + ( x . a . GistRemark . Contains ( q ) ? 1 : 0 ) ,
597+ SearchOrder = ( x . a . GistFilename . Contains ( q ) ? 4 : 0 ) + ( x . a . GistRemark . Contains ( q ) ? 2 : 0 ) + ( x . a . GistContent . Contains ( q ) ? 1 : 0 ) ,
580598 x . Nickname ,
581599 x . a
582600 } ) . OrderByDescending ( x => x . SearchOrder ) ;
583601
602+ switch ( GlobalTo . TDB )
603+ {
604+ case SharedEnum . TypeDB . SQLite :
605+ query2 = query1 . Select ( x => new
606+ {
607+ SearchOrder = ( EF . Functions . Like ( x . a . GistFilename , $ "%{ q } %") ? 4 : 0 ) + ( EF . Functions . Like ( x . a . GistRemark , $ "%{ q } %") ? 2 : 0 ) + ( EF . Functions . Like ( x . a . GistContent , $ "%{ q } %") ? 1 : 0 ) ,
608+ x . Nickname ,
609+ x . a
610+ } ) . OrderByDescending ( x => x . SearchOrder ) ;
611+ break ;
612+ case SharedEnum . TypeDB . PostgreSQL :
613+ query2 = query1 . Select ( x => new
614+ {
615+ SearchOrder = ( EF . Functions . Like ( x . a . GistFilename , $ "%{ q } %") ? 4 : 0 ) + ( EF . Functions . Like ( x . a . GistRemark , $ "%{ q } %") ? 2 : 0 ) + ( EF . Functions . Like ( x . a . GistContent , $ "%{ q } %") ? 1 : 0 ) ,
616+ x . Nickname ,
617+ x . a
618+ } ) . OrderByDescending ( x => x . SearchOrder ) ;
619+ break ;
620+ }
621+
584622 query = query2 . Select ( x => new Gist
585623 {
586624 GistCode = x . a . GistCode ,
@@ -686,7 +724,12 @@ orderby a.DsCreateTime descending
686724
687725 if ( ! string . IsNullOrWhiteSpace ( q ) )
688726 {
689- query = query . Where ( x => x . DsName . Contains ( q ) || x . DsRemark . Contains ( q ) ) ;
727+ query = GlobalTo . TDB switch
728+ {
729+ SharedEnum . TypeDB . SQLite => query . Where ( x => EF . Functions . Like ( x . DsName , $ "%{ q } %") || EF . Functions . Like ( x . DsRemark , $ "%{ q } %") ) ,
730+ SharedEnum . TypeDB . PostgreSQL => query . Where ( x => EF . Functions . ILike ( x . DsName , $ "%{ q } %") || EF . Functions . ILike ( x . DsRemark , $ "%{ q } %") ) ,
731+ _ => query . Where ( x => x . DsName . Contains ( q ) || x . DsRemark . Contains ( q ) ) ,
732+ } ;
690733 }
691734
692735 var pag = new SharedPaginationVM
@@ -758,7 +801,12 @@ orderby a.RunCreateTime descending
758801
759802 if ( ! string . IsNullOrWhiteSpace ( q ) )
760803 {
761- query = query . Where ( x => x . RunRemark . Contains ( q ) ) ;
804+ query = GlobalTo . TDB switch
805+ {
806+ SharedEnum . TypeDB . SQLite => query . Where ( x => EF . Functions . Like ( x . RunRemark , $ "%{ q } %") ) ,
807+ SharedEnum . TypeDB . PostgreSQL => query . Where ( x => EF . Functions . ILike ( x . RunRemark , $ "%{ q } %") ) ,
808+ _ => query . Where ( x => x . RunRemark . Contains ( q ) ) ,
809+ } ;
762810 }
763811
764812 var pag = new SharedPaginationVM
@@ -833,7 +881,12 @@ orderby a.DrCreateTime descending
833881
834882 if ( ! string . IsNullOrWhiteSpace ( q ) )
835883 {
836- query = query . Where ( x => x . DrName . Contains ( q ) || x . DrRemark . Contains ( q ) ) ;
884+ query = GlobalTo . TDB switch
885+ {
886+ SharedEnum . TypeDB . SQLite => query . Where ( x => EF . Functions . Like ( x . DrName , $ "%{ q } %") || EF . Functions . Like ( x . DrRemark , $ "%{ q } %") ) ,
887+ SharedEnum . TypeDB . PostgreSQL => query . Where ( x => EF . Functions . ILike ( x . DrName , $ "%{ q } %") || EF . Functions . ILike ( x . DrRemark , $ "%{ q } %") ) ,
888+ _ => query . Where ( x => x . DrName . Contains ( q ) || x . DrRemark . Contains ( q ) ) ,
889+ } ;
837890 }
838891
839892 var pag = new SharedPaginationVM
@@ -1069,7 +1122,12 @@ join b in db.UserInfo on a.Uid equals b.UserId
10691122
10701123 if ( ! string . IsNullOrWhiteSpace ( q ) )
10711124 {
1072- query = query . Where ( x => x . GrContent . Contains ( q ) || x . GrTag . Contains ( q ) ) ;
1125+ query = GlobalTo . TDB switch
1126+ {
1127+ SharedEnum . TypeDB . SQLite => query . Where ( x => EF . Functions . Like ( x . GrContent , $ "%{ q } %") || EF . Functions . Like ( x . GrTag , $ "%{ q } %") ) ,
1128+ SharedEnum . TypeDB . PostgreSQL => query . Where ( x => EF . Functions . ILike ( x . GrContent , $ "%{ q } %") || EF . Functions . ILike ( x . GrTag , $ "%{ q } %") ) ,
1129+ _ => query . Where ( x => x . GrContent . Contains ( q ) || x . GrTag . Contains ( q ) ) ,
1130+ } ;
10731131 }
10741132
10751133 var pag = new SharedPaginationVM
0 commit comments