@dovid
תודה רבה על המענה הנפלא!
יצרנו תוכנה בסיסית לבדוק את sqlite
הבעיה שהאטיות שלו בבניית האינדקס פשוט לא פרקטית
אולי אנחנו לא בנינו את הקוד נכון?
בכל אופן מצו"ב הקוד בc# אם מישהו יכול לעזור
using System;
using System.Data.SQLite;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace TestSqlite
{
public partial class Form1 : Form
{
private ProgressBar progressBar;
private Label progressLabel;
public Form1()
{
InitializeComponent();
InitializeUI();
}
private void InitializeUI()
{
Button startIndexingButton = new Button();
startIndexingButton.Text = "Start Indexing";
startIndexingButton.Click += StartIndexingButton_Click;
startIndexingButton.Dock = DockStyle.Top;
progressBar = new ProgressBar();
progressBar.Dock = DockStyle.Bottom;
progressLabel = new Label();
progressLabel.Dock = DockStyle.Bottom;
Controls.Add(progressBar);
Controls.Add(progressLabel);
Controls.Add(startIndexingButton);
}
private void StartIndexingButton_Click(object sender, EventArgs e)
{
string folderPath = @"C:\Users\0533105132\Desktop\MyBooks"; // Replace with the path to your folder.
string databasePath = "index.db";
CreateDatabase(databasePath);
// Recursively process text files in the specified folder.
ProcessFolder(folderPath, databasePath);
MessageBox.Show("Indexing complete.");
}
private void CreateDatabase(string databasePath)
{
using (SQLiteConnection connection = new SQLiteConnection($"Data Source={databasePath}"))
{
connection.Open();
string createTableQuery = @"
CREATE TABLE IF NOT EXISTS WordIndex (
Word TEXT,
FilePath TEXT,
LineNumber INT,
WordPosition INT
);
";
using (SQLiteCommand command = new SQLiteCommand(createTableQuery, connection))
{
command.ExecuteNonQuery();
}
}
}
private void ProcessFolder(string folderPath, string databasePath)
{
string[] files = Directory.GetFiles(folderPath, "*.txt", SearchOption.AllDirectories);
progressBar.Maximum = files.Length;
progressBar.Value = 0;
foreach (string file in files)
{
progressLabel.Text = $"Processing: {Path.GetFileName(file)}";
Application.DoEvents(); // Update the label text
ProcessFile(file, databasePath);
progressBar.Value++;
}
progressLabel.Text = "Processing complete.";
}
private void ProcessFile(string filePath, string databasePath)
{
using (SQLiteConnection connection = new SQLiteConnection($"Data Source={databasePath}"))
{
connection.Open();
using (SQLiteCommand command = new SQLiteCommand(connection))
{
StringBuilder insertBatch = new StringBuilder();
string[] lines = File.ReadAllLines(filePath, Encoding.GetEncoding(1255));
int lineNumber = 0;
foreach (string line in lines)
{
lineNumber++;
string[] words = Regex.Split(line, @"\W+");
foreach (string word in words)
{
if (!string.IsNullOrWhiteSpace(word))
{
string normalizedWord = word.ToLower();
insertBatch.AppendLine("INSERT INTO WordIndex (Word, FilePath, LineNumber, WordPosition) " +
$"VALUES ('{normalizedWord}', '{filePath}', {lineNumber}, {insertBatch.Length});");
}
}
}
// Execute all insert statements in a single transaction
command.CommandText = insertBatch.ToString();
command.ExecuteNonQuery();
}
}
}
}
}
מצו"ב גם תמונה של הטבלה
