Re-order search results to show best matches at the top
This commit is contained in:
		
							parent
							
								
									e5bfc83282
								
							
						
					
					
						commit
						379604bfb1
					
				@ -44,6 +44,7 @@
 | 
				
			|||||||
    import l from './localize';
 | 
					    import l from './localize';
 | 
				
			||||||
    import UserView from './UserView.vue';
 | 
					    import UserView from './UserView.vue';
 | 
				
			||||||
    import * as _ from 'lodash';
 | 
					    import * as _ from 'lodash';
 | 
				
			||||||
 | 
					    import {EventBus} from './event-bus';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    type Options = {
 | 
					    type Options = {
 | 
				
			||||||
        kinks: Kink[],
 | 
					        kinks: Kink[],
 | 
				
			||||||
@ -57,6 +58,26 @@
 | 
				
			|||||||
    function sort(x: Character, y: Character): number {
 | 
					    function sort(x: Character, y: Character): number {
 | 
				
			||||||
        if(x.status === 'looking' && y.status !== 'looking') return -1;
 | 
					        if(x.status === 'looking' && y.status !== 'looking') return -1;
 | 
				
			||||||
        if(x.status !== 'looking' && y.status === 'looking') return 1;
 | 
					        if(x.status !== 'looking' && y.status === 'looking') return 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const xc = core.cache.profileCache.getSync(x.name);
 | 
				
			||||||
 | 
					        const yc = core.cache.profileCache.getSync(y.name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (xc && !yc) {
 | 
				
			||||||
 | 
					            return -1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!xc && yc) {
 | 
				
			||||||
 | 
					            return 1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (xc && yc) {
 | 
				
			||||||
 | 
					            if (xc.matchScore > yc.matchScore)
 | 
				
			||||||
 | 
					                return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (xc.matchScore < yc.matchScore)
 | 
				
			||||||
 | 
					                return 1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(x.name < y.name) return -1;
 | 
					        if(x.name < y.name) return -1;
 | 
				
			||||||
        if(x.name > y.name) return 1;
 | 
					        if(x.name > y.name) return 1;
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
@ -87,6 +108,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        searchString = '';
 | 
					        searchString = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // tslint:disable-next-line no-any
 | 
				
			||||||
 | 
					        scoreWatcher: ((event: any) => void) | null = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @Hook('created')
 | 
					        @Hook('created')
 | 
				
			||||||
        async created(): Promise<void> {
 | 
					        async created(): Promise<void> {
 | 
				
			||||||
            if(options === undefined)
 | 
					            if(options === undefined)
 | 
				
			||||||
@ -121,6 +146,43 @@
 | 
				
			|||||||
                this.results = data.characters.map((x) => core.characters.get(x))
 | 
					                this.results = data.characters.map((x) => core.characters.get(x))
 | 
				
			||||||
                    .filter((x) => core.state.hiddenUsers.indexOf(x.name) === -1 && !x.isIgnored).sort(sort);
 | 
					                    .filter((x) => core.state.hiddenUsers.indexOf(x.name) === -1 && !x.isIgnored).sort(sort);
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (this.scoreWatcher) {
 | 
				
			||||||
 | 
					                EventBus.$off('character-score', this.scoreWatcher);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // tslint:disable-next-line no-unsafe-any no-any
 | 
				
			||||||
 | 
					            this.scoreWatcher = (event: any): void => {
 | 
				
			||||||
 | 
					                // console.log('scoreWatcher', event);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (
 | 
				
			||||||
 | 
					                    (this.results)
 | 
				
			||||||
 | 
					                    // tslint:disable-next-line no-unsafe-any no-any
 | 
				
			||||||
 | 
					                    && (event.character)
 | 
				
			||||||
 | 
					                    // tslint:disable-next-line no-unsafe-any no-any
 | 
				
			||||||
 | 
					                    && (_.find(this.results, (c: Character) => c.name === event.character.character.name))
 | 
				
			||||||
 | 
					                ) {
 | 
				
			||||||
 | 
					                    this.results = this.results.sort(sort);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            EventBus.$on(
 | 
				
			||||||
 | 
					                'character-score',
 | 
				
			||||||
 | 
					                this.scoreWatcher
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @Hook('beforeDestroy')
 | 
				
			||||||
 | 
					        beforeDestroy(): void {
 | 
				
			||||||
 | 
					            if (this.scoreWatcher) {
 | 
				
			||||||
 | 
					                EventBus.$off(
 | 
				
			||||||
 | 
					                    'character-score',
 | 
				
			||||||
 | 
					                    this.scoreWatcher
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                delete this.scoreWatcher;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -128,10 +190,10 @@
 | 
				
			|||||||
        onDataChange(): void {
 | 
					        onDataChange(): void {
 | 
				
			||||||
            this.searchString = _.join(
 | 
					            this.searchString = _.join(
 | 
				
			||||||
                _.map(
 | 
					                _.map(
 | 
				
			||||||
 | 
					                    // tslint:disable-next-line no-unsafe-any no-any
 | 
				
			||||||
                    _.flatten(_.map(this.data as any)),
 | 
					                    _.flatten(_.map(this.data as any)),
 | 
				
			||||||
                    (v) => {
 | 
					                    // tslint:disable-next-line no-unsafe-any no-any
 | 
				
			||||||
                        return _.get(v, 'name', v);
 | 
					                    (v) => _.get(v, 'name', v)
 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
                ', '
 | 
					                ', '
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
				
			|||||||
@ -693,13 +693,15 @@
 | 
				
			|||||||
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
 | 
					            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            &.match {
 | 
					            &.match {
 | 
				
			||||||
                border-left: 12px solid #027b02;
 | 
					                border-left: 12px solid #048a04;
 | 
				
			||||||
                background-color: rgba(1, 115, 1, 0.45);
 | 
					                background-color: rgba(0, 110, 0, 0.47);
 | 
				
			||||||
 | 
					                // border-left: 12px solid #027b02;
 | 
				
			||||||
 | 
					                // background-color: rgba(1, 115, 1, 0.45);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            &.weak-match {
 | 
					            &.weak-match {
 | 
				
			||||||
                border-left: 12px solid #015a01;
 | 
					                border-left: 12px solid #014a01;
 | 
				
			||||||
                background-color: rgba(0, 70, 0, 0.4);
 | 
					                background-color: rgba(0, 79, 0, 0.4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                .bbcode {
 | 
					                .bbcode {
 | 
				
			||||||
                    filter: grayscale(0.25);
 | 
					                    filter: grayscale(0.25);
 | 
				
			||||||
 | 
				
			|||||||
@ -141,7 +141,7 @@ export class CacheManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.queue = _.sortBy(this.queue, 'score');
 | 
					        this.queue = _.sortBy(this.queue, 'score');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        console.log('QUEUE', _.map(this.queue, (q) => `${q.name}: ${q.score}`));
 | 
					        // console.log('QUEUE', _.map(this.queue, (q) => `${q.name}: ${q.score}`));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const entry = this.queue.pop() as ProfileCacheQueueEntry;
 | 
					        const entry = this.queue.pop() as ProfileCacheQueueEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -30,9 +30,9 @@ export class CharacterProfiler {
 | 
				
			|||||||
        const friendlyScore = this.getInterestScoreForFriendlies(c);
 | 
					        const friendlyScore = this.getInterestScoreForFriendlies(c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // tslint:disable-next-line: number-literal-format binary-expression-operand-order
 | 
					        // tslint:disable-next-line: number-literal-format binary-expression-operand-order
 | 
				
			||||||
 | 
					 | 
				
			||||||
        const score = ((1.0 * genderScore) + (1.0 * statusScore) + (1.0 * adScore) + (1.0 * friendlyScore));
 | 
					        const score = ((1.0 * genderScore) + (1.0 * statusScore) + (1.0 * adScore) + (1.0 * friendlyScore));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // tslint:disable-next-line: number-literal-format binary-expression-operand-order
 | 
				
			||||||
        return (c.status === 'looking') ? score + 10.0 : score;
 | 
					        return (c.status === 'looking') ? score + 10.0 : score;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -189,7 +189,7 @@
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.messages-both {
 | 
					.messages-both {
 | 
				
			||||||
  .message-ad {
 | 
					  .message-ad:not(.message-score) {
 | 
				
			||||||
    background-color: theme-color-level("info", -4);
 | 
					    background-color: theme-color-level("info", -4);
 | 
				
			||||||
    padding: 0 2px 2px 2px;
 | 
					    padding: 0 2px 2px 2px;
 | 
				
			||||||
    box-shadow: $gray-500 -2px -2px 2px inset;
 | 
					    box-shadow: $gray-500 -2px -2px 2px inset;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user