Ver Fonte

Change min query length

sbkwgh há 6 anos atrás
pai
commit
2ff83c06e1

+ 4 - 2
frontend/src/components/SearchBox.vue

@@ -126,6 +126,8 @@
 
 				highlightIndex: null,
 
+				MinQueryLength: 2,
+
 				threads: [],
 				users: []
 			}
@@ -146,7 +148,7 @@
 				//Return if results should not show
 				if(!this.headerBar) return;
 
-				this.showResults = this.searchField.trim().length > 3;
+				this.showResults = this.searchField.trim().length > (this.$store.state.MinQueryLength-1);
 				if(this.showResults) {
 					this.getResults();
 				} else {
@@ -285,7 +287,7 @@
 			},
 			getResults () {
 				let q = this.searchField.trim();
-				if(q.length < 4) return;
+				if(q.length < this.$store.state.MinQueryLength) return;
 
 				this.loading = true;
 				this.threads = [];

+ 1 - 1
frontend/src/components/ThreadPost.vue

@@ -45,7 +45,7 @@
 			<div style='display: inline-flex;'>
 				<avatar-icon :user='post.User' class='post__avatar'></avatar-icon>
 				<div class='post__thread' v-if='showThread' @click.stop='goToThread'>
-					In thread <span class='post__thread__name'>{{post.Thread.name}}</span>
+					In thread <span class='post__thread__name'>{{post.Thread.name | truncateMid(50)}}</span>
 					&nbsp;&middot;&nbsp;
 				</div>
 				<div class='post__user' v-else>

+ 2 - 2
frontend/src/components/routes/Search.vue

@@ -7,7 +7,7 @@
 				<thread-display v-for='thread in threads.slice(0, 3)' :key='thread.id' :thread='thread'></thread-display>
 
 				<div
-					class='search__more search__item' v-if='threads.length > 3'
+					class='search__more search__item' v-if='threads.length > ($store.state.MinQueryLength-1)'
 					@click='$router.push("/search/threads/" + $route.params.q)'
 				>
 					<span class='fa fa-fw fa-comments'></span>
@@ -95,7 +95,7 @@
 				);
 			},
 			queryTooShort () {
-				return this.$route.params.q.length < 4
+				return this.$route.params.q.length < this.$store.state.MinQueryLength
 			}
 		},
 		methods: {

+ 1 - 1
frontend/src/components/routes/SearchUsersThreads.vue

@@ -110,7 +110,7 @@
 				);
 			},
 			queryTooShort () {
-				return this.$route.params.q.length < 4
+				return this.$route.params.q.length < this.$store.state.MinQueryLength
 			}
 		},
 		methods: {

+ 3 - 1
frontend/src/store/index.js

@@ -26,7 +26,9 @@ export default new Vuex.Store({
 		show404Page: false,
 
 		ajaxErrors: [],
-		ajaxErrorsModal: false
+		ajaxErrorsModal: false,
+
+		MinQueryLength: 2
 	},
 	getters: {
 		categoriesWithoutAll (state) {

+ 2 - 2
routes/search.js

@@ -8,9 +8,9 @@ router.get('/thread', async (req, res, next) => {
 	try {
 		let searchString = req.query.q.trim()
 
-		if(searchString.length < 4) {
+		if(searchString.length < 2) {
 			throw Errors.sequelizeValidation(Sequelize, {
-				error: 'search string must be at least 4 characters',
+				error: 'search string must be at least 2 characters',
 				value: searchString
 			})
 		}