Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

UI tidy up. Initial query work (WIP)

  • Loading branch information...
commit fc19b5266643f414e832495d07c169769801cfae 1 parent 63406cf
@AdaTheDev authored
View
53 ElasticTweets.Library/ElasticSearcher.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using ElasticTweets.Library.Data;
+using ElasticTweets.Library.Providers;
+using ElasticTweets.Library.Queries;
+using Nest;
+using Nest.FactoryDsl;
+
+namespace ElasticTweets.Library
+{
+ public sealed class ElasticSearcher
+ {
+ private readonly IClientProvider _clientProvider;
+ private readonly IElasticConnectionSettings _elasticConnectionSettings;
+ private readonly IElasticClient _client;
+
+ public ElasticSearcher(IClientProvider clientProvider, IElasticConnectionSettings elasticConnectionSettings)
+ {
+ if (clientProvider == null) throw new ArgumentNullException("clientProvider");
+ if (elasticConnectionSettings == null) throw new ArgumentNullException("elasticConnectionSettings");
+
+ _clientProvider = clientProvider;
+ _elasticConnectionSettings = elasticConnectionSettings;
+ _client = _clientProvider.GetClient(_elasticConnectionSettings);
+ }
+
+ public IEnumerable<Tweet> SearchRaw(IElasticQuery query)
+ {
+ var response = ExecuteRaw(query.RawQueryText);
+ return Results(response);
+ }
+
+ public IEnumerable<Tweet> SearchClientApi(IElasticQuery query)
+ {
+ var response = ExecuteClient(query.Builder);
+ return Results(response);
+ }
+
+ private IEnumerable<Tweet> Results(IQueryResponse<Tweet> response)
+ {
+ return response.Documents;
+ }
+ private IQueryResponse<Tweet> ExecuteRaw(string query)
+ {
+ return _client.SearchRaw<Tweet>(query);
+ }
+
+ private IQueryResponse<Tweet> ExecuteClient(SearchBuilder searchBuilder)
+ {
+ return _client.Search<Tweet>(searchBuilder);
+ }
+ }
+}
View
11 ElasticTweets.Library/Queries/IElasticQuery.cs
@@ -0,0 +1,11 @@
+using Nest.FactoryDsl;
+
+namespace ElasticTweets.Library.Queries
+{
+ public interface IElasticQuery
+ {
+ string Description { get; }
+ string RawQueryText { get; }
+ SearchBuilder Builder { get; }
+ }
+}
View
41 ElasticTweets.Library/Queries/TweetsContainingLinksQuery.cs
@@ -0,0 +1,41 @@
+using Nest.FactoryDsl;
+using Nest.FactoryDsl.Filter;
+using Nest.FactoryDsl.Query;
+
+namespace ElasticTweets.Library.Queries
+{
+ public class TweetsContainingLinksQuery : IElasticQuery
+ {
+ /*
+ * {
+ * "query" : {
+ * "constant_score" : {
+ * "filter" : {
+ * "exists" : { "field" : "url"}
+ * }
+ * }
+ * }
+ * }
+ */
+ private const string RawQuery =
+ "{ \"query\" : {\"constant_score\" : {\"filter\" : {\"exists\" : { \"field\" : \"url\"}}}}}";
+
+
+ public string Description
+ {
+ get { return "Finds tweets that contain links"; }
+ }
+
+ public string RawQueryText { get { return RawQuery; } }
+
+ public SearchBuilder Builder
+ {
+ get
+ {
+ var searchBuilder = new SearchBuilder();
+ searchBuilder.Query(new ConstantScoreQueryBuilder(new ExistsFilterBuilder("url")));
+ return searchBuilder;
+ }
+ }
+ }
+}
View
284 ElasticTweets/Form1.Designer.cs
@@ -28,160 +28,232 @@ protected override void Dispose(bool disposing)
/// </summary>
private void InitializeComponent()
{
- this.lblSourceDirectory = new System.Windows.Forms.Label();
- this.txtSourceDirectory = new System.Windows.Forms.TextBox();
- this.lblElasticHost = new System.Windows.Forms.Label();
- this.txtHost = new System.Windows.Forms.TextBox();
- this.lblPort = new System.Windows.Forms.Label();
- this.txtPort = new System.Windows.Forms.TextBox();
- this.lblIndexName = new System.Windows.Forms.Label();
- this.txtIndexName = new System.Windows.Forms.TextBox();
- this.btnImport = new System.Windows.Forms.Button();
this.folderDialog = new System.Windows.Forms.FolderBrowserDialog();
- this.btnChangeDirectory = new System.Windows.Forms.Button();
+ this.tabControl1 = new System.Windows.Forms.TabControl();
+ this.tabPage1 = new System.Windows.Forms.TabPage();
this.lblElasticSearch = new System.Windows.Forms.Label();
+ this.btnChangeDirectory = new System.Windows.Forms.Button();
+ this.btnImport = new System.Windows.Forms.Button();
+ this.txtIndexName = new System.Windows.Forms.TextBox();
+ this.lblIndexName = new System.Windows.Forms.Label();
+ this.txtPort = new System.Windows.Forms.TextBox();
+ this.lblPort = new System.Windows.Forms.Label();
+ this.txtHost = new System.Windows.Forms.TextBox();
+ this.lblElasticHost = new System.Windows.Forms.Label();
+ this.txtSourceDirectory = new System.Windows.Forms.TextBox();
+ this.lblSourceDirectory = new System.Windows.Forms.Label();
+ this.tabPage2 = new System.Windows.Forms.TabPage();
+ this.grdSearchResults = new System.Windows.Forms.DataGridView();
+ this.btnSearch = new System.Windows.Forms.Button();
+ this.tabControl1.SuspendLayout();
+ this.tabPage1.SuspendLayout();
+ this.tabPage2.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.grdSearchResults)).BeginInit();
this.SuspendLayout();
//
- // lblSourceDirectory
+ // folderDialog
//
- this.lblSourceDirectory.AutoSize = true;
- this.lblSourceDirectory.Location = new System.Drawing.Point(11, 15);
- this.lblSourceDirectory.Name = "lblSourceDirectory";
- this.lblSourceDirectory.Size = new System.Drawing.Size(123, 13);
- this.lblSourceDirectory.TabIndex = 0;
- this.lblSourceDirectory.Text = "Tweet Data JS Directory";
+ this.folderDialog.ShowNewFolderButton = false;
//
- // txtSourceDirectory
+ // tabControl1
//
- this.txtSourceDirectory.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.txtSourceDirectory.Location = new System.Drawing.Point(140, 10);
- this.txtSourceDirectory.Name = "txtSourceDirectory";
- this.txtSourceDirectory.Size = new System.Drawing.Size(335, 20);
- this.txtSourceDirectory.TabIndex = 1;
+ this.tabControl1.Controls.Add(this.tabPage1);
+ this.tabControl1.Controls.Add(this.tabPage2);
+ this.tabControl1.Location = new System.Drawing.Point(8, 12);
+ this.tabControl1.Name = "tabControl1";
+ this.tabControl1.SelectedIndex = 0;
+ this.tabControl1.Size = new System.Drawing.Size(578, 378);
+ this.tabControl1.TabIndex = 11;
//
- // lblElasticHost
+ // tabPage1
//
- this.lblElasticHost.AutoSize = true;
- this.lblElasticHost.Location = new System.Drawing.Point(11, 59);
- this.lblElasticHost.Name = "lblElasticHost";
- this.lblElasticHost.Size = new System.Drawing.Size(29, 13);
- this.lblElasticHost.TabIndex = 2;
- this.lblElasticHost.Text = "Host";
+ this.tabPage1.Controls.Add(this.lblElasticSearch);
+ this.tabPage1.Controls.Add(this.btnChangeDirectory);
+ this.tabPage1.Controls.Add(this.btnImport);
+ this.tabPage1.Controls.Add(this.txtIndexName);
+ this.tabPage1.Controls.Add(this.lblIndexName);
+ this.tabPage1.Controls.Add(this.txtPort);
+ this.tabPage1.Controls.Add(this.lblPort);
+ this.tabPage1.Controls.Add(this.txtHost);
+ this.tabPage1.Controls.Add(this.lblElasticHost);
+ this.tabPage1.Controls.Add(this.txtSourceDirectory);
+ this.tabPage1.Controls.Add(this.lblSourceDirectory);
+ this.tabPage1.Location = new System.Drawing.Point(4, 22);
+ this.tabPage1.Name = "tabPage1";
+ this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
+ this.tabPage1.Size = new System.Drawing.Size(570, 352);
+ this.tabPage1.TabIndex = 0;
+ this.tabPage1.Text = "Import";
+ this.tabPage1.UseVisualStyleBackColor = true;
//
- // txtHost
+ // lblElasticSearch
//
- this.txtHost.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.txtHost.Location = new System.Drawing.Point(82, 55);
- this.txtHost.Name = "txtHost";
- this.txtHost.Size = new System.Drawing.Size(132, 20);
- this.txtHost.TabIndex = 3;
+ this.lblElasticSearch.AutoSize = true;
+ this.lblElasticSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.lblElasticSearch.Location = new System.Drawing.Point(20, 51);
+ this.lblElasticSearch.Name = "lblElasticSearch";
+ this.lblElasticSearch.Size = new System.Drawing.Size(203, 13);
+ this.lblElasticSearch.TabIndex = 21;
+ this.lblElasticSearch.Text = "ElasticSearch Connection Settings";
//
- // lblPort
+ // btnChangeDirectory
//
- this.lblPort.AutoSize = true;
- this.lblPort.Location = new System.Drawing.Point(11, 83);
- this.lblPort.Name = "lblPort";
- this.lblPort.Size = new System.Drawing.Size(26, 13);
- this.lblPort.TabIndex = 4;
- this.lblPort.Text = "Port";
+ this.btnChangeDirectory.Location = new System.Drawing.Point(487, 18);
+ this.btnChangeDirectory.Name = "btnChangeDirectory";
+ this.btnChangeDirectory.Size = new System.Drawing.Size(24, 22);
+ this.btnChangeDirectory.TabIndex = 20;
+ this.btnChangeDirectory.Text = "...";
+ this.btnChangeDirectory.UseVisualStyleBackColor = true;
+ this.btnChangeDirectory.Click += new System.EventHandler(this.btnChangeDirectory_Click);
//
- // txtPort
+ // btnImport
//
- this.txtPort.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.txtPort.Location = new System.Drawing.Point(82, 78);
- this.txtPort.Name = "txtPort";
- this.txtPort.Size = new System.Drawing.Size(40, 20);
- this.txtPort.TabIndex = 5;
+ this.btnImport.Location = new System.Drawing.Point(23, 157);
+ this.btnImport.Name = "btnImport";
+ this.btnImport.Size = new System.Drawing.Size(72, 26);
+ this.btnImport.TabIndex = 19;
+ this.btnImport.Text = "Import";
+ this.btnImport.UseVisualStyleBackColor = true;
+ this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
+ //
+ // txtIndexName
+ //
+ this.txtIndexName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.txtIndexName.Location = new System.Drawing.Point(91, 111);
+ this.txtIndexName.Name = "txtIndexName";
+ this.txtIndexName.Size = new System.Drawing.Size(132, 20);
+ this.txtIndexName.TabIndex = 18;
//
// lblIndexName
//
this.lblIndexName.AutoSize = true;
- this.lblIndexName.Location = new System.Drawing.Point(12, 106);
+ this.lblIndexName.Location = new System.Drawing.Point(21, 116);
this.lblIndexName.Name = "lblIndexName";
this.lblIndexName.Size = new System.Drawing.Size(64, 13);
- this.lblIndexName.TabIndex = 6;
+ this.lblIndexName.TabIndex = 17;
this.lblIndexName.Text = "Index Name";
//
- // txtIndexName
+ // txtPort
//
- this.txtIndexName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.txtIndexName.Location = new System.Drawing.Point(82, 101);
- this.txtIndexName.Name = "txtIndexName";
- this.txtIndexName.Size = new System.Drawing.Size(132, 20);
- this.txtIndexName.TabIndex = 7;
+ this.txtPort.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.txtPort.Location = new System.Drawing.Point(91, 88);
+ this.txtPort.Name = "txtPort";
+ this.txtPort.Size = new System.Drawing.Size(40, 20);
+ this.txtPort.TabIndex = 16;
//
- // btnImport
+ // lblPort
//
- this.btnImport.Location = new System.Drawing.Point(14, 147);
- this.btnImport.Name = "btnImport";
- this.btnImport.Size = new System.Drawing.Size(72, 27);
- this.btnImport.TabIndex = 8;
- this.btnImport.Text = "Import";
- this.btnImport.UseVisualStyleBackColor = true;
- this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
+ this.lblPort.AutoSize = true;
+ this.lblPort.Location = new System.Drawing.Point(20, 93);
+ this.lblPort.Name = "lblPort";
+ this.lblPort.Size = new System.Drawing.Size(26, 13);
+ this.lblPort.TabIndex = 15;
+ this.lblPort.Text = "Port";
//
- // folderDialog
+ // txtHost
//
- this.folderDialog.ShowNewFolderButton = false;
+ this.txtHost.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.txtHost.Location = new System.Drawing.Point(91, 65);
+ this.txtHost.Name = "txtHost";
+ this.txtHost.Size = new System.Drawing.Size(132, 20);
+ this.txtHost.TabIndex = 14;
//
- // btnChangeDirectory
+ // lblElasticHost
//
- this.btnChangeDirectory.Location = new System.Drawing.Point(478, 8);
- this.btnChangeDirectory.Name = "btnChangeDirectory";
- this.btnChangeDirectory.Size = new System.Drawing.Size(24, 23);
- this.btnChangeDirectory.TabIndex = 9;
- this.btnChangeDirectory.Text = "...";
- this.btnChangeDirectory.UseVisualStyleBackColor = true;
- this.btnChangeDirectory.Click += new System.EventHandler(this.btnChangeDirectory_Click);
+ this.lblElasticHost.AutoSize = true;
+ this.lblElasticHost.Location = new System.Drawing.Point(20, 69);
+ this.lblElasticHost.Name = "lblElasticHost";
+ this.lblElasticHost.Size = new System.Drawing.Size(29, 13);
+ this.lblElasticHost.TabIndex = 13;
+ this.lblElasticHost.Text = "Host";
//
- // lblElasticSearch
+ // txtSourceDirectory
//
- this.lblElasticSearch.AutoSize = true;
- this.lblElasticSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.lblElasticSearch.Location = new System.Drawing.Point(11, 41);
- this.lblElasticSearch.Name = "lblElasticSearch";
- this.lblElasticSearch.Size = new System.Drawing.Size(203, 13);
- this.lblElasticSearch.TabIndex = 10;
- this.lblElasticSearch.Text = "ElasticSearch Connection Settings";
+ this.txtSourceDirectory.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.txtSourceDirectory.Location = new System.Drawing.Point(149, 20);
+ this.txtSourceDirectory.Name = "txtSourceDirectory";
+ this.txtSourceDirectory.Size = new System.Drawing.Size(335, 20);
+ this.txtSourceDirectory.TabIndex = 12;
+ //
+ // lblSourceDirectory
+ //
+ this.lblSourceDirectory.AutoSize = true;
+ this.lblSourceDirectory.Location = new System.Drawing.Point(20, 25);
+ this.lblSourceDirectory.Name = "lblSourceDirectory";
+ this.lblSourceDirectory.Size = new System.Drawing.Size(123, 13);
+ this.lblSourceDirectory.TabIndex = 11;
+ this.lblSourceDirectory.Text = "Tweet Data JS Directory";
+ //
+ // tabPage2
+ //
+ this.tabPage2.Controls.Add(this.grdSearchResults);
+ this.tabPage2.Controls.Add(this.btnSearch);
+ this.tabPage2.Location = new System.Drawing.Point(4, 22);
+ this.tabPage2.Name = "tabPage2";
+ this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
+ this.tabPage2.Size = new System.Drawing.Size(570, 352);
+ this.tabPage2.TabIndex = 1;
+ this.tabPage2.Text = "Query";
+ this.tabPage2.UseVisualStyleBackColor = true;
+ //
+ // grdSearchResults
+ //
+ this.grdSearchResults.AllowUserToAddRows = false;
+ this.grdSearchResults.AllowUserToDeleteRows = false;
+ this.grdSearchResults.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.grdSearchResults.Location = new System.Drawing.Point(6, 35);
+ this.grdSearchResults.Name = "grdSearchResults";
+ this.grdSearchResults.ReadOnly = true;
+ this.grdSearchResults.Size = new System.Drawing.Size(558, 297);
+ this.grdSearchResults.TabIndex = 1;
+ //
+ // btnSearch
+ //
+ this.btnSearch.Location = new System.Drawing.Point(6, 6);
+ this.btnSearch.Name = "btnSearch";
+ this.btnSearch.Size = new System.Drawing.Size(75, 23);
+ this.btnSearch.TabIndex = 0;
+ this.btnSearch.Text = "Search";
+ this.btnSearch.UseVisualStyleBackColor = true;
+ this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// frmImport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Gainsboro;
- this.ClientSize = new System.Drawing.Size(517, 185);
- this.Controls.Add(this.lblElasticSearch);
- this.Controls.Add(this.btnChangeDirectory);
- this.Controls.Add(this.btnImport);
- this.Controls.Add(this.txtIndexName);
- this.Controls.Add(this.lblIndexName);
- this.Controls.Add(this.txtPort);
- this.Controls.Add(this.lblPort);
- this.Controls.Add(this.txtHost);
- this.Controls.Add(this.lblElasticHost);
- this.Controls.Add(this.txtSourceDirectory);
- this.Controls.Add(this.lblSourceDirectory);
+ this.ClientSize = new System.Drawing.Size(598, 402);
+ this.Controls.Add(this.tabControl1);
this.Name = "frmImport";
this.Text = "ElasticTweets - Import";
+ this.tabControl1.ResumeLayout(false);
+ this.tabPage1.ResumeLayout(false);
+ this.tabPage1.PerformLayout();
+ this.tabPage2.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.grdSearchResults)).EndInit();
this.ResumeLayout(false);
- this.PerformLayout();
}
#endregion
- private System.Windows.Forms.Label lblSourceDirectory;
- private System.Windows.Forms.TextBox txtSourceDirectory;
- private System.Windows.Forms.Label lblElasticHost;
- private System.Windows.Forms.TextBox txtHost;
- private System.Windows.Forms.Label lblPort;
- private System.Windows.Forms.TextBox txtPort;
- private System.Windows.Forms.Label lblIndexName;
- private System.Windows.Forms.TextBox txtIndexName;
- private System.Windows.Forms.Button btnImport;
private System.Windows.Forms.FolderBrowserDialog folderDialog;
- private System.Windows.Forms.Button btnChangeDirectory;
+ private System.Windows.Forms.TabControl tabControl1;
+ private System.Windows.Forms.TabPage tabPage1;
+ private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Label lblElasticSearch;
+ private System.Windows.Forms.Button btnChangeDirectory;
+ private System.Windows.Forms.Button btnImport;
+ private System.Windows.Forms.TextBox txtIndexName;
+ private System.Windows.Forms.Label lblIndexName;
+ private System.Windows.Forms.TextBox txtPort;
+ private System.Windows.Forms.Label lblPort;
+ private System.Windows.Forms.TextBox txtHost;
+ private System.Windows.Forms.Label lblElasticHost;
+ private System.Windows.Forms.TextBox txtSourceDirectory;
+ private System.Windows.Forms.Label lblSourceDirectory;
+ private System.Windows.Forms.DataGridView grdSearchResults;
+ private System.Windows.Forms.Button btnSearch;
}
}
View
21 ElasticTweets/Form1.cs
@@ -18,14 +18,7 @@ public frmImport()
{
InitializeComponent();
}
-
- private void btnImport_Click(object sender, EventArgs e)
- {
- ToggleControls(false);
-
- Task.Factory.StartNew(DoImport).ContinueWith(_ => ToggleControls(true));
- }
-
+
private void DoImport()
{
string validationResult = ValidateInputs();
@@ -113,6 +106,18 @@ private void btnChangeDirectory_Click(object sender, EventArgs e)
{
folderDialog.ShowDialog();
txtSourceDirectory.Text = folderDialog.SelectedPath;
+ }
+
+ private void btnSearch_Click(object sender, EventArgs e)
+ {
+ MessageBox.Show("Schhhhtop...it's not ready yet!");
+ }
+
+ private void btnImport_Click(object sender, EventArgs e)
+ {
+ ToggleControls(false);
+
+ Task.Factory.StartNew(DoImport).ContinueWith(_ => ToggleControls(true));
}
}
}
View
8 readme.txt
@@ -1,6 +1,12 @@
Basic intro to this project can be found on my blog: http://www.adathedev.co.uk/2013/02/import-twitter-archive-elasticsearch.html
-ElasticTweets - very basic WinForms GUI (and I mean basic, no basic input validation etc) allowing you to import the tweet data into ElasticSearch
+ElasticTweets - basic WinForms GUI allowing you to import the tweet data into ElasticSearch
ElasticTweets.Library - all the engine room nuts and bolts
ElasticTweets.Library.UnitTests - does what it says on the tin...unit tests
+Purpose of this project:
+* to provide a way to import your Twitter archive into ElasticSearch
+* starter project for getting to know ElasticSearch, how to interact with via .NET and the client libraries available (currently
+using NEST)
+* providing real examples of the types of ElasticSearch queries you can perform
+
Please sign in to comment.
Something went wrong with that request. Please try again.