Last active
September 9, 2015 14:16
-
-
Save pedro-ramirez-suarez/6655b7df8d4383aed40a to your computer and use it in GitHub Desktop.
Motor de búsqueda distribuido con DiPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
//Abrimos la conexión a DiPS | |
diPSClient.Connect('ws://localhost:8888/dips'); | |
… | |
diPSClient.Subscribe("searchresults", function (msg) { | |
… | |
//actualizar la UI | |
for (var x in msg) { | |
$('#st' + word).append('<p><b>' + msg[x].BookName + '(' + msg[x].LineNumber + '):</b> ' + msg[x].Line.replace(word, '<b>' + word + '</b>') + '</p>'); | |
} | |
}); | |
… | |
function searchWord() { | |
… | |
//Esta es la entidad que vamos a enviar al publicar el evento | |
var search = { | |
Word: $('#term').val(), | |
SearchId: $('#term').val() | |
}; | |
//Lanzamos la búsqueda | |
diPSClient.Publish("wordsearch", search); | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
client = new DiPS.Client.DiPSClient(ConfigurationManager.AppSettings["dipsserver"]); | |
client.Subscribe("wordsearch", (m) => | |
{ | |
SearchWordService(m); | |
}); | |
... | |
private static void SearchWordService(dynamic s) | |
{ | |
//Itera sobre todos los archivos de una carpeta | |
var found = new List<SearchWordResult>(); | |
var files = folder.GetFiles(); | |
int line ; | |
foreach (var f in files) | |
{ | |
... | |
//Busca en cada uno de los archivos la palabra | |
} | |
//publica los resultados | |
client.Publish("searchresults",found); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Entidad usada para lanzar una búsqueda | |
/// </summary> | |
public class SearchWord | |
{ | |
public string Word { get; set; } | |
public string SearchId { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Entidad usada para enviar resultados | |
/// (una lista de estas entidades es el resultado) | |
/// </summary> | |
public class SearchWordResult | |
{ | |
public string Word { get; set; } | |
public string BookName { get; set; } | |
public int LineNumber { get; set; } | |
public string Line { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dipsclient' | |
client = DiPS::DiPSClient.new "ws://localhost:8888/dips" | |
puts "Connecting" | |
#Wait a little to get the connection ready | |
sleep 2.0 | |
client.Subscribe ("wordsearch") { |m| | |
word = m["Word"] | |
allfound = Array.new | |
texts = 'C:\\books\Ruby\\' | |
#search in all the files of certain folder | |
Dir.foreach(texts) do |item| | |
... | |
#Busca en cada unos de los archivos la palabra | |
end | |
#publish the result | |
client.Publish "searchresults", allfound | |
} | |
puts "Enter to exit" | |
k = gets.chomp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment