Skip to content

Commit

Permalink
search as-is checkbox implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
wowkmw committed Oct 21, 2019
1 parent 2ff834a commit d275ea9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 23 deletions.
26 changes: 20 additions & 6 deletions OneSearch/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 30 additions & 7 deletions OneSearch/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ private void searchButton_Click(object sender, EventArgs e)
ResulttView.Items.Clear();
ResulttView.Controls.Clear();
searchTerm = textBox3.Text;
string processedQuery;
double seconds;
if (searchTerm is "")
{
MessageBox.Show("Please enter some keyword!");
Expand All @@ -117,13 +119,29 @@ private void searchButton_Click(object sender, EventArgs e)
}
else
{
DateTime a = DateTime.Now;
myLucene.CreateSearcher();
resultList = myLucene.SearchText(searchTerm, numofDoc, out string processedQuery);
myLucene.CleanUpSearcher();
DateTime b = DateTime.Now;
TimeSpan c = b - a;
double seconds = c.TotalSeconds;
bool check = false;
if (AsIsBox.Checked)
{
check = true;
DateTime a = DateTime.Now;
myLucene.CreateSearcher();
resultList = myLucene.SearchText(searchTerm, numofDoc, check, out processedQuery);
myLucene.CleanUpSearcher();
DateTime b = DateTime.Now;
TimeSpan c = b - a;
seconds = c.TotalSeconds;
}
else
{
DateTime a = DateTime.Now;
myLucene.CreateSearcher();
resultList = myLucene.SearchText(searchTerm, numofDoc, check, out processedQuery);
myLucene.CleanUpSearcher();
DateTime b = DateTime.Now;
TimeSpan c = b - a;
seconds = c.TotalSeconds;
}

FinalWordBox.Text = processedQuery;
queryCount++;
int numofresult = resultList.Count;
Expand Down Expand Up @@ -193,5 +211,10 @@ private void SaveResults_Click(object sender, EventArgs e)
MessageBox.Show("Search something first...");
}
}

private void AsIsBox_CheckedChanged(object sender, EventArgs e)
{

}
}
}
33 changes: 23 additions & 10 deletions OneSearch/LuceneCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ namespace OneSearch
{
public class LuceneCore
{
Lucene.Net.Store.Directory luceneIndexDirectory;
Lucene.Net.Analysis.Analyzer analyzer;
Lucene.Net.Index.IndexWriter writer;
IndexSearcher searcher;
public static QueryParser parser;
private Lucene.Net.Store.Directory luceneIndexDirectory;
private Lucene.Net.Analysis.Analyzer analyzer;
private Lucene.Net.Analysis.Analyzer AsIsanalyzer;
private Lucene.Net.Index.IndexWriter writer;
private IndexSearcher searcher;
private QueryParser parser;
private QueryParser AsIsparser;

//Lucene.Net.Search.Similarity newSimilarity;

Expand All @@ -37,11 +39,12 @@ public LuceneCore()
{
luceneIndexDirectory = null;
writer = null;
//analyzer = new Lucene.Net.Analysis.WhitespaceAnalyzer();
AsIsanalyzer = new Lucene.Net.Analysis.WhitespaceAnalyzer();
//analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(VERSION);
analyzer = new Lucene.Net.Analysis.SimpleAnalyzer();

parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, TEXT_FN, analyzer);
AsIsparser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, TEXT_FN, AsIsanalyzer);

//newSimilarity = new NewSimilarity();
}
Expand Down Expand Up @@ -96,10 +99,20 @@ public void CreateSearcher()
/// Searches the index for the querytext
/// </summary>
/// <param name="querytext">The text to search the index</param>
public List<Dictionary<string, string>> SearchText(string querytext, int DocNum, out string processedQuery)
public List<Dictionary<string, string>> SearchText(string querytext, int DocNum, bool check, out string processedQuery)
{
querytext = querytext.ToLower();
Query query = parser.Parse(querytext);
Query query;
if (check)
{
//querytext = querytext.ToLower();
query = AsIsparser.Parse(querytext);
}
else
{
querytext = querytext.ToLower();
query = parser.Parse(querytext);
}

List<Dictionary<string, string>> resultList = new List<Dictionary<string, string>>();
processedQuery = query.ToString();
TopDocs results = searcher.Search(query, DocNum);
Expand Down

0 comments on commit d275ea9

Please sign in to comment.