From de856cd0859898b9b5019ab301e9771e72532789 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 2 Jun 2019 00:42:18 +0100 Subject: [PATCH] canonize search terms --- core/src/main/groovy/com/muwire/core/Constants.groovy | 2 ++ .../main/groovy/com/muwire/core/search/SearchIndex.groovy | 3 ++- .../controllers/com/muwire/gui/MainFrameController.groovy | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/Constants.groovy b/core/src/main/groovy/com/muwire/core/Constants.groovy index 1f6bc264..624bad15 100644 --- a/core/src/main/groovy/com/muwire/core/Constants.groovy +++ b/core/src/main/groovy/com/muwire/core/Constants.groovy @@ -10,4 +10,6 @@ class Constants { public static final int MAX_HEADERS = 16 public static final float DOWNLOAD_SEQUENTIAL_RATIO = 0.8f + + public static final String SPLIT_PATTERN = "[\\.,_-]" } diff --git a/core/src/main/groovy/com/muwire/core/search/SearchIndex.groovy b/core/src/main/groovy/com/muwire/core/search/SearchIndex.groovy index 98f1f566..783272c6 100644 --- a/core/src/main/groovy/com/muwire/core/search/SearchIndex.groovy +++ b/core/src/main/groovy/com/muwire/core/search/SearchIndex.groovy @@ -1,5 +1,6 @@ package com.muwire.core.search +import com.muwire.core.Constants class SearchIndex { @@ -31,7 +32,7 @@ class SearchIndex { } private static String[] split(String source) { - source = source.replaceAll("[\\.,_-]", " ") + source = source.replaceAll(Constants.SPLIT_PATTERN, " ").toLowerCase() source.split(" ") } diff --git a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy index c5d6e34a..bd7a17e7 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy @@ -10,6 +10,7 @@ import griffon.metadata.ArtifactProviderFor import javax.annotation.Nonnull import javax.inject.Inject +import com.muwire.core.Constants import com.muwire.core.Core import com.muwire.core.download.DownloadStartedEvent import com.muwire.core.download.UIDownloadEvent @@ -39,7 +40,9 @@ class MainFrameController { def group = mvcGroup.createMVCGroup("SearchTab", uuid.toString(), params) model.results[uuid.toString()] = group - def searchEvent = new SearchEvent(searchTerms : [search], uuid : uuid) + // this can be improved a lot + def terms = search.toLowerCase().trim().split(Constants.SPLIT_PATTERN) + def searchEvent = new SearchEvent(searchTerms : terms, uuid : uuid) core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : true, replyTo: core.me.destination, receivedOn: core.me.destination)) }