mirror of https://github.com/zlatinb/muwire
searches by hash
parent
9cdabb51d1
commit
b308ac2f37
|
@ -25,6 +25,8 @@ import com.muwire.core.files.FileLoadedEvent
|
||||||
import com.muwire.core.files.FileUnsharedEvent
|
import com.muwire.core.files.FileUnsharedEvent
|
||||||
import com.muwire.core.hostcache.HostDiscoveredEvent
|
import com.muwire.core.hostcache.HostDiscoveredEvent
|
||||||
|
|
||||||
|
import net.i2p.data.Base64
|
||||||
|
|
||||||
class MainWindowView extends BasicWindow {
|
class MainWindowView extends BasicWindow {
|
||||||
|
|
||||||
private final Core core
|
private final Core core
|
||||||
|
@ -191,6 +193,12 @@ class MainWindowView extends BasicWindow {
|
||||||
|
|
||||||
private void search() {
|
private void search() {
|
||||||
String query = searchTextBox.getText()
|
String query = searchTextBox.getText()
|
||||||
|
query = query.trim()
|
||||||
|
if (query.length() == 0)
|
||||||
|
return
|
||||||
|
if (query.length() > 128)
|
||||||
|
query = query.substring(0, 128)
|
||||||
|
|
||||||
SearchModel model = new SearchModel(query, core, textGUI.getGUIThread())
|
SearchModel model = new SearchModel(query, core, textGUI.getGUIThread())
|
||||||
textGUI.addWindowAndWait(new SearchView(model,core, textGUI, sizeForTables()))
|
textGUI.addWindowAndWait(new SearchView(model,core, textGUI, sizeForTables()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,9 @@ import com.muwire.core.search.QueryEvent
|
||||||
import com.muwire.core.search.SearchEvent
|
import com.muwire.core.search.SearchEvent
|
||||||
import com.muwire.core.search.UIResultBatchEvent
|
import com.muwire.core.search.UIResultBatchEvent
|
||||||
import com.muwire.core.search.UIResultEvent
|
import com.muwire.core.search.UIResultEvent
|
||||||
|
|
||||||
|
import net.i2p.data.Base64
|
||||||
|
|
||||||
import com.googlecode.lanterna.gui2.TextGUIThread
|
import com.googlecode.lanterna.gui2.TextGUIThread
|
||||||
import com.googlecode.lanterna.gui2.table.TableModel
|
import com.googlecode.lanterna.gui2.table.TableModel
|
||||||
class SearchModel {
|
class SearchModel {
|
||||||
|
@ -25,12 +28,28 @@ class SearchModel {
|
||||||
core.eventBus.register(UIResultBatchEvent.class, this)
|
core.eventBus.register(UIResultBatchEvent.class, this)
|
||||||
|
|
||||||
|
|
||||||
def replaced = query.toLowerCase().trim().replaceAll(SplitPattern.SPLIT_PATTERN, " ")
|
boolean hashSearch = false
|
||||||
def terms = replaced.split(" ")
|
byte [] root = null
|
||||||
def nonEmpty = []
|
if (query.length() == 44 && query.indexOf(" ") < 0) {
|
||||||
terms.each { if (it.length() > 0) nonEmpty << it }
|
try {
|
||||||
def searchEvent = new SearchEvent(searchTerms : nonEmpty, uuid : UUID.randomUUID(), oobInfohash: true,
|
root = Base64.decode(query)
|
||||||
|
hashSearch = true
|
||||||
|
} catch (Exception e) {
|
||||||
|
// not hash search
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def searchEvent
|
||||||
|
if (hashSearch) {
|
||||||
|
searchEvent = new SearchEvent(searchHash : root, uuid : UUID.randomUUID(), oobInfohash : true, compressedResults : true)
|
||||||
|
} else {
|
||||||
|
def replaced = query.toLowerCase().trim().replaceAll(SplitPattern.SPLIT_PATTERN, " ")
|
||||||
|
def terms = replaced.split(" ")
|
||||||
|
def nonEmpty = []
|
||||||
|
terms.each { if (it.length() > 0) nonEmpty << it }
|
||||||
|
searchEvent = new SearchEvent(searchTerms : nonEmpty, uuid : UUID.randomUUID(), oobInfohash: true,
|
||||||
searchComments : core.muOptions.searchComments, compressedResults : true)
|
searchComments : core.muOptions.searchComments, compressedResults : true)
|
||||||
|
}
|
||||||
boolean firstHop = core.muOptions.allowUntrusted || core.muOptions.searchExtraHop
|
boolean firstHop = core.muOptions.allowUntrusted || core.muOptions.searchExtraHop
|
||||||
core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : firstHop,
|
core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : firstHop,
|
||||||
replyTo: core.me.destination, receivedOn: core.me.destination,
|
replyTo: core.me.destination, receivedOn: core.me.destination,
|
||||||
|
|
Loading…
Reference in New Issue