mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add Seacher class and move OleDb connection method
This commit is contained in:
parent
5484b30514
commit
7b69d98e59
2 changed files with 61 additions and 42 deletions
|
|
@ -1,16 +1,9 @@
|
||||||
using Microsoft.Search.Interop;
|
using Microsoft.Search.Interop;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data.OleDb;
|
|
||||||
|
|
||||||
namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
|
namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
|
||||||
{
|
{
|
||||||
public class QueryConstructor
|
public class QueryConstructor
|
||||||
{
|
{
|
||||||
public OleDbConnection conn;
|
|
||||||
public OleDbCommand command;
|
|
||||||
public OleDbDataReader dataReaderResults;
|
|
||||||
|
|
||||||
private Settings _settings;
|
private Settings _settings;
|
||||||
|
|
||||||
private const string SystemIndex = "SystemIndex";
|
private const string SystemIndex = "SystemIndex";
|
||||||
|
|
@ -89,40 +82,5 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
|
||||||
{
|
{
|
||||||
return $"scope='file:'";
|
return $"scope='file:'";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal List<Result> ExecuteWindowsIndexSearch(string query)
|
|
||||||
{
|
|
||||||
var results = new List<Result>();
|
|
||||||
|
|
||||||
using (conn = new OleDbConnection(CreateQueryHelper().ConnectionString))
|
|
||||||
{
|
|
||||||
conn.Open();
|
|
||||||
|
|
||||||
using (command = new OleDbCommand(query, conn))
|
|
||||||
{
|
|
||||||
// Results return as an OleDbDataReader.
|
|
||||||
using (dataReaderResults = command.ExecuteReader())
|
|
||||||
{
|
|
||||||
if (dataReaderResults.HasRows)
|
|
||||||
{
|
|
||||||
while (dataReaderResults.Read())
|
|
||||||
{
|
|
||||||
if (dataReaderResults.GetValue(0) != DBNull.Value && dataReaderResults.GetValue(1) != DBNull.Value)
|
|
||||||
{
|
|
||||||
var result = new Result
|
|
||||||
{
|
|
||||||
Title = dataReaderResults.GetString(0),
|
|
||||||
SubTitle = dataReaderResults.GetString(1)
|
|
||||||
};
|
|
||||||
results.Add(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data.OleDb;
|
||||||
|
|
||||||
|
namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
|
||||||
|
{
|
||||||
|
internal class Searcher
|
||||||
|
{
|
||||||
|
public OleDbConnection conn;
|
||||||
|
|
||||||
|
public OleDbCommand command;
|
||||||
|
|
||||||
|
public OleDbDataReader dataReaderResults;
|
||||||
|
|
||||||
|
private readonly object _lock = new object();
|
||||||
|
|
||||||
|
internal List<Result> ExecuteWindowsIndexSearch(string query, string connectionString)
|
||||||
|
{
|
||||||
|
var results = new List<Result>();
|
||||||
|
|
||||||
|
using (conn = new OleDbConnection(connectionString))
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
using (command = new OleDbCommand(query, conn))
|
||||||
|
{
|
||||||
|
// Results return as an OleDbDataReader.
|
||||||
|
using (dataReaderResults = command.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (dataReaderResults.HasRows)
|
||||||
|
{
|
||||||
|
while (dataReaderResults.Read())
|
||||||
|
{
|
||||||
|
if (dataReaderResults.GetValue(0) != DBNull.Value && dataReaderResults.GetValue(1) != DBNull.Value)
|
||||||
|
{
|
||||||
|
var result = new Result
|
||||||
|
{
|
||||||
|
Title = dataReaderResults.GetString(0),
|
||||||
|
SubTitle = dataReaderResults.GetString(1)
|
||||||
|
};
|
||||||
|
results.Add(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal List<Result> WindowsIndexSearch(string query, string connectionString, Func<string, string> constructQuery)
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
var constructedQuery = constructQuery(query);
|
||||||
|
return ExecuteWindowsIndexSearch(constructedQuery, connectionString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue