Skip to content

Commit c9b4957

Browse files
committed
don't lower-case reg exprs in subs filters; remove non-matching results
1 parent ff03ef7 commit c9b4957

File tree

6 files changed

+218
-22
lines changed

6 files changed

+218
-22
lines changed

core/src/com/biglybt/core/subs/SubscriptionHistory.java

+14
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,27 @@
4444
boolean enabled,
4545
boolean auto_dl );
4646

47+
/**
48+
* Delete marks the result as explicitly deleted - it won't be re-discovered
49+
* @param result_ids
50+
*/
51+
4752
public void
4853
deleteResults(
4954
String[] result_ids );
5055

5156
public void
5257
deleteAllResults();
5358

59+
/**
60+
* This removes the result, it will be available for re-discovery if filters permit
61+
* @param result_ids
62+
*/
63+
64+
public void
65+
removeResults(
66+
String[] result_ids );
67+
5468
public void
5569
markAllResultsRead();
5670

core/src/com/biglybt/core/subs/SubscriptionResult.java

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.util.Map;
2424

25+
import com.biglybt.core.metasearch.FilterableResult;
2526
import com.biglybt.pifimpl.local.utils.UtilitiesImpl;
2627

2728
public interface
@@ -69,4 +70,7 @@
6970

7071
public boolean
7172
isDeleted();
73+
74+
public FilterableResult
75+
getFilterableResult();
7276
}

core/src/com/biglybt/core/subs/impl/SubscriptionHistoryImpl.java

+50
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,56 @@
846846
}
847847
}
848848

849+
@Override
850+
public void
851+
removeResults(
852+
String[] result_ids )
853+
{
854+
ByteArrayHashMap<String> rids = new ByteArrayHashMap<>();
855+
856+
for (int i=0;i<result_ids.length;i++){
857+
858+
rids.put( Base32.decode( result_ids[i]), "" );
859+
}
860+
861+
boolean changed = false;
862+
863+
synchronized( this ){
864+
865+
LinkedHashMap<String,SubscriptionResultImpl> results_map = manager.loadResults( subs );
866+
867+
List<SubscriptionResultImpl> new_results = new ArrayList<>( results_map.size());
868+
869+
for ( SubscriptionResultImpl result: results_map.values()){
870+
871+
if ( !result.isDeleted() && rids.containsKey( result.getKey1())){
872+
873+
changed = true;
874+
875+
result.deleteInternal();
876+
877+
}else{
878+
879+
new_results.add( result );
880+
}
881+
}
882+
883+
if ( changed ){
884+
885+
SubscriptionResultImpl[] results = new_results.toArray( new SubscriptionResultImpl[ new_results.size()]);
886+
887+
updateReadUnread( results );
888+
889+
manager.saveResults( subs, results, null );
890+
}
891+
}
892+
893+
if ( changed ){
894+
895+
saveConfig(SubscriptionListener.CR_RESULTS);
896+
}
897+
}
898+
849899
@Override
850900
public void
851901
markAllResultsRead()

core/src/com/biglybt/core/subs/impl/SubscriptionResultFilterImpl.java

+55-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.util.ArrayList;
55
import java.util.List;
6+
import java.util.Locale;
67
import java.util.Map;
78
import java.util.StringTokenizer;
89
import java.util.regex.Pattern;
@@ -14,8 +15,10 @@
1415
import com.biglybt.core.metasearch.Result;
1516
import com.biglybt.core.subs.Subscription;
1617
import com.biglybt.core.subs.SubscriptionException;
18+
import com.biglybt.core.subs.SubscriptionResult;
1719
import com.biglybt.core.subs.SubscriptionResultFilter;
1820
import com.biglybt.core.subs.SubscriptionUtils;
21+
import com.biglybt.core.util.Debug;
1922
import com.biglybt.core.util.DisplayFormatters;
2023
import com.biglybt.core.util.SystemTime;
2124
import com.biglybt.core.util.TimeFormatter;
@@ -117,8 +120,10 @@
117120
maxAgeSecs = MapUtils.importLong(filters, "max_age",-1l);
118121

119122
String rawCategory = MapUtils.getMapString(filters,"category", null);
120-
if(rawCategory != null) {
121-
categoryFilter = rawCategory.toLowerCase();
123+
124+
if (rawCategory != null){
125+
126+
categoryFilter = rawCategory.toLowerCase( Locale.US );
122127
}
123128

124129
} catch(Exception e) {
@@ -361,10 +366,10 @@
361366
}
362367

363368
types[i] = type;
364-
filters[i] = filter;
369+
filters[i] = filter.toLowerCase( Locale.US );
365370

366371
try{
367-
patterns[i] = Pattern.compile( filter.trim());
372+
patterns[i] = Pattern.compile( filter.trim(), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
368373

369374
}catch( Throwable e ){
370375

@@ -393,6 +398,28 @@
393398

394399
throws SubscriptionException
395400
{
401+
try{
402+
SubscriptionResult[] results = subs.getHistory().getResults( false );
403+
404+
List<String> to_remove = new ArrayList<>();
405+
406+
for ( SubscriptionResult result: results ){
407+
408+
if ( isFiltered( result.getFilterableResult())){
409+
410+
to_remove.add( result.getID());
411+
}
412+
}
413+
414+
if ( !to_remove.isEmpty()){
415+
416+
subs.getHistory().removeResults( to_remove.toArray( new String[ to_remove.size()]));
417+
}
418+
}catch( Throwable e ){
419+
420+
Debug.out( e );
421+
}
422+
396423
Map map = JSONUtils.decodeJSON( subs.getJSON());
397424

398425
Map filters = new JSONObject();
@@ -470,13 +497,23 @@
470497
return( res );
471498
}
472499

473-
private String[] importStrings(Map filters,String key,String separator) throws IOException {
500+
private String[]
501+
importStrings(
502+
Map filters,String key,String separator)
503+
504+
throws IOException
505+
{
474506
String rawStringFilter = MapUtils.getMapString(filters,key,null);
475-
if(rawStringFilter != null) {
507+
508+
if ( rawStringFilter != null) {
509+
476510
StringTokenizer st = new StringTokenizer(rawStringFilter,separator);
511+
477512
String[] stringFilter = new String[st.countTokens()];
513+
478514
for(int i = 0 ; i < stringFilter.length ; i++) {
479-
stringFilter[i] = st.nextToken().toLowerCase();
515+
516+
stringFilter[i] = st.nextToken();
480517
}
481518
return stringFilter;
482519
}
@@ -504,9 +541,14 @@ private String[] importStrings(Map filters,String key,String separator) throws I
504541
map.put( key, encoded );
505542
}
506543

507-
public Result[] filter(Result[] results) {
544+
public Result[]
545+
filter(
546+
Result[] results)
547+
{
508548
List<Result> filteredResults = new ArrayList<>(results.length);
549+
509550
for(int i = 0 ; i < results.length ; i++) {
551+
510552
Result result = results[i];
511553

512554
if ( !isFiltered( result )){
@@ -520,6 +562,7 @@ public Result[] filter(Result[] results) {
520562
return fResults;
521563
}
522564

565+
523566
public boolean
524567
isFiltered(
525568
FilterableResult result )
@@ -546,7 +589,7 @@ public Result[] filter(Result[] results) {
546589
return( false );
547590
}
548591

549-
public boolean
592+
private boolean
550593
isFilteredSupport(
551594
FilterableResult result )
552595
{
@@ -559,7 +602,7 @@ public Result[] filter(Result[] results) {
559602
return( true );
560603
}
561604

562-
name = name.toLowerCase();
605+
name = name.toLowerCase( Locale.US );
563606

564607
String[] names = { name };
565608

@@ -597,7 +640,7 @@ public Result[] filter(Result[] results) {
597640
if ( category == null || category.isEmpty()){
598641
categories = new String[0];
599642
}else{
600-
categories = new String[]{ category.toLowerCase() };
643+
categories = new String[]{ category.toLowerCase( Locale.US ) };
601644
}
602645
}
603646
matches = categories;
@@ -611,7 +654,7 @@ public Result[] filter(Result[] results) {
611654
}else{
612655
tags = new String[temp.length];
613656
for ( int k=0;k<temp.length;k++){
614-
tags[k] = temp[k].toLowerCase();
657+
tags[k] = temp[k].toLowerCase( Locale.US );
615658
}
616659
}
617660
}

core/src/com/biglybt/core/subs/impl/SubscriptionResultImpl.java

+76
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Map;
2929

3030
import com.biglybt.core.config.COConfigurationManager;
31+
import com.biglybt.core.metasearch.FilterableResult;
3132
import com.biglybt.core.metasearch.Result;
3233
import com.biglybt.core.subs.SubscriptionResult;
3334
import com.biglybt.core.subs.util.SearchSubsResultBase;
@@ -763,4 +764,79 @@
763764
return( result );
764765
}
765766
}
767+
768+
@Override
769+
public FilterableResult
770+
getFilterableResult()
771+
{
772+
Map<Integer,Object> properties = toPropertyMap();
773+
774+
return(
775+
new FilterableResult(){
776+
public String
777+
getName()
778+
{
779+
return( (String)properties.get( SearchResult.PR_NAME ));
780+
}
781+
782+
public String
783+
getCategory()
784+
{
785+
return((String)properties.get( SearchResult.PR_CATEGORY ));
786+
}
787+
788+
public String[]
789+
getTags()
790+
{
791+
return((String[])properties.get( SearchResult.PR_TAGS ));
792+
}
793+
794+
public long
795+
getSize()
796+
{
797+
return((Long)properties.get( SearchResult.PR_SIZE ));
798+
}
799+
800+
public int
801+
getNbSeeds()
802+
{
803+
long seeds = (Long)properties.get( SearchResult.PR_SEED_COUNT );
804+
805+
return((int)(seeds<0?0:seeds));
806+
}
807+
808+
public int
809+
getNbPeers()
810+
{
811+
long leechers = (Long)properties.get( SearchResult.PR_LEECHER_COUNT );
812+
813+
return((int)(leechers<0?0:leechers));
814+
}
815+
816+
public long
817+
getTime()
818+
{
819+
Date pub_date = (Date)properties.get( SearchResult.PR_PUB_DATE );
820+
821+
if ( pub_date == null ){
822+
823+
return( getTimeFound());
824+
825+
}else{
826+
827+
long pt = pub_date.getTime();
828+
829+
if ( pt <= 0 ){
830+
831+
return( getTimeFound());
832+
833+
}else{
834+
835+
return( pt );
836+
}
837+
}
838+
839+
}
840+
});
841+
}
766842
}

0 commit comments

Comments
 (0)