canonize search terms

pull/4/head
Zlatin Balevsky 2019-06-02 00:42:18 +01:00
parent d2533cc4d6
commit de856cd085
3 changed files with 8 additions and 2 deletions

View File

@ -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 = "[\\.,_-]"
}

View File

@ -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(" ")
}

View File

@ -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))
}