Notes
Notes - notes.io |
/*****************************************************************************************************************************
* This is the default similarity search with stock boosting and scoring with the exception of using the custom similarity
* in order to negate query normalization by overriding it to (float)1.0 This is done to allow fair comparison
*************************************************************************************************************************/
public TopDocs tfIdfQuery()
{
TopDocs tfIdfResults = null;
try
{
if (SrcTrms.Count > 0 && directory != null)//make sure there is an idea term to search with or else I cannot score documents
{
//scoredDocs.Clear();
BooleanQuery booleanquery = new BooleanQuery();
PhraseQuery phrasequery = new PhraseQuery();
directory = FSDirectory.Open(new DirectoryInfo(appDefaultindexPath));
IndexReader indexReader = IndexReader.Open(directory, true);
IndexSearcher indexSearch = new IndexSearcher(indexReader);
indexSearch.Similarity = new DefaultSimilarity();
//indexSearch.Similarity = new customDefaultScore();
var queryParser = new QueryParser(Version.LUCENE_30, "BODY", analyzer);
Query query;
//get all the terms and boosts
foreach (SrcTrm i in SrcTrms)
{
String Boost = i.boost;
//determine if this is a phrase or single term
if (i.idea.Contains(" "))
{
//break the string into an array
phrasequery = new PhraseQuery();
String[] phrs = i.idea.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
int ctr = 0;
foreach (String str in phrs)
{
phrasequery.Add(new Term("BODY", str.ToLower()), ctr++);
}
phraseSlop = Convert.ToInt32(txtPhrSlop.Text);//Convert.ToInt32(cmbPhraseSlop.SelectedItem);
phrasequery.Slop = phraseSlop;
if (Boost == "Must")
{
int thy = Convert.ToInt32(Must_Weight);
phrasequery.Boost = (float)thy;
booleanquery.Add(phrasequery, Occur.MUST);
}
else if (Boost == "Never")
{
booleanquery.Add(phrasequery, Occur.MUST_NOT);
}
else if (Boost == "Probable")
{
phrasequery.Boost = (float)Convert.ToInt32(Probable_Weight);
booleanquery.Add(phrasequery, Occur.SHOULD);
}
else if (Boost == "Possible")
{
int thy = Convert.ToInt32(Possible_Weight);
phrasequery.Boost = (float)thy;
booleanquery.Add(phrasequery, Occur.SHOULD);
}
else if (Boost == "Critical")
{
int thy = Convert.ToInt32(Critical_Weight);
phrasequery.Boost = (float)thy;
booleanquery.Add(phrasequery, Occur.SHOULD);
}
else
{
phrasequery.Boost = 1;
booleanquery.Add(phrasequery, Occur.SHOULD);
}
}
else
{
query = queryParser.Parse(i.idea);
if (Boost == "Must")
{
int thy = Convert.ToInt32(Must_Weight);
query.Boost = (float)thy;
booleanquery.Add(query, Occur.MUST);
}
else if (Boost == "Never")
{
booleanquery.Add(query, Occur.MUST_NOT);
}
else if (Boost == "Probable")
{
int thy = Convert.ToInt32(Probable_Weight);
query.Boost = (float)Convert.ToInt32(Probable_Weight);
booleanquery.Add(query, Occur.SHOULD);
}
else if (Boost == "Possible")
{
int thy = Convert.ToInt32(Possible_Weight);
query.Boost = (float)thy;
booleanquery.Add(query, Occur.SHOULD);
}
else if (Boost == "Critical")
{
int thy = Convert.ToInt32(Critical_Weight);
query.Boost = (float)thy;
booleanquery.Add(query, Occur.SHOULD);
}
else
{
booleanquery.Add(query, Occur.SHOULD);
}
}
}
tfIdfResults = indexSearch.Search(booleanquery, tfMaxSize);//indexReader.MaxDoc);
return tfIdfResults;
}
else
return tfIdfResults;
}
return tfIdfResults;
}//end class method tfIdfQuer
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team