NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/**
* This search scorer just counts the number of terms that are found in each document. It could leave out reports with too small of
* a return size selected by the user. This score has no value for relevance between documents as it relates to length or frequency
* of recurring terms.
* **/
public TopDocs simpleRank()
{
TopDocs EmptyDocs = new TopDocs(0, null, 1);
TopDocs rankDocs = 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();
ScoreDoc[] ttlScoresArray = null;
String strTypeSearch = "Custom Rank Scoring";
BooleanQuery booleanquery = new BooleanQuery();
PhraseQuery phrasequery; //used for multi term queries
Query query; //used for single term queries
directory = FSDirectory.Open(new DirectoryInfo(appDefaultindexPath));
IndexReader indexReader = IndexReader.Open(directory, true);
IndexSearcher indexSearch = new IndexSearcher(indexReader);
//indexSearch.Similarity = DefaultSimilarity;
indexSearch.Similarity = new customDefaultScore();
//indexSearch.Similarity = new CustomScore();
var queryParser = new QueryParser(Version.LUCENE_30, "BODY", analyzer);
//get all the terms and boosts
foreach (SrcTrm i in SrcTrms)
{
float bst = 1;
//MessageBox.Show(i.boost);
String Boost = i.boost;
//determine if this is a phrase or single term
//if (i.idea.Contains(" "))
//{
//MessageBox.Show("This is a phrase");
//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++);
//MessageBox.Show("The term is now: " + str);
}
phraseSlop = Convert.ToInt32(txtPhrSlop.Text);// Convert.ToInt32(cmbPhraseSlop.SelectedItem);
phrasequery.Slop = phraseSlop;
if (Boost == "Must")
{
bst = (float)Convert.ToInt32(Must_Weight);
//bst = 1;
//cstmScoreQry csQuery = new cstmScoreQry(phrasequery, bst, ttlScoresArray);
cstmRankQry rkQry = new cstmRankQry(phrs, phrasequery, bst, ttlScoresArray);
booleanquery.Add(rkQry, Occur.MUST);
}
else if (Boost == "Never")
{
bst = 1;
//cstmScoreQry csQuery = new cstmScoreQry(phrasequery, bst, ttlScoresArray);
cstmRankQry rkQry = new cstmRankQry(phrs, phrasequery, bst, ttlScoresArray);
booleanquery.Add(rkQry, Occur.MUST_NOT);
}
else if (Boost == "Probable")
{
bst = (float)Convert.ToInt32(Probable_Weight);
//bst = 1;
//cstmScoreQry csQuery = new cstmScoreQry(phrasequery, bst, ttlScoresArray);
//booleanquery.Add(csQuery, Occur.SHOULD);
cstmRankQry rkQry = new cstmRankQry(phrs, phrasequery, bst, ttlScoresArray);
booleanquery.Add(rkQry, Occur.SHOULD);
}
else if (Boost == "Possible")
{
bst = (float)Convert.ToInt32(Possible_Weight);
//bst = 1;
//cstmScoreQry csQuery = new cstmScoreQry(phrasequery, bst, ttlScoresArray);
//booleanquery.Add(csQuery, Occur.SHOULD);
cstmRankQry rkQry = new cstmRankQry(phrs, phrasequery, bst, ttlScoresArray);
booleanquery.Add(rkQry, Occur.SHOULD);
}
else if (Boost == "Critical")
{
bst = (float)Convert.ToInt32(Critical_Weight);
//bst = 1;
//cstmScoreQry csQuery = new cstmScoreQry(phrasequery, bst, ttlScoresArray);
//booleanquery.Add(csQuery, Occur.SHOULD);
cstmRankQry rkQry = new cstmRankQry(phrs, phrasequery, bst, ttlScoresArray);
booleanquery.Add(rkQry, Occur.SHOULD);
}
else
{
bst = 1;
//cstmScoreQry csQuery = new cstmScoreQry(phrasequery, bst, ttlScoresArray);
//booleanquery.Add(csQuery, Occur.SHOULD);
cstmRankQry rkQry = new cstmRankQry(phrs, phrasequery, bst, ttlScoresArray);
booleanquery.Add(rkQry, Occur.SHOULD);
}


}
rankDocs = indexSearch.Search(booleanquery, rankMaxSize);//indexReader.MaxDoc);
//foreach (ScoreDoc rd in rankSearch.ScoreDocs)
// foreach (ScoreDoc rd in rankDocs.ScoreDocs)
// {
// if(rd.Score > 2)
// {
// MessageBox.Show("Rank Score here: " + rd.Score.ToString());
// }
//}
return rankDocs;
}
}
return rankDocs;
}
/************************************************************************************
* This method goes through the ideas collection and provides the boost and terms
* to be recorded for the analysis phase.
* */
private String getQuery()
{
String theseTrms = "";
foreach (SrcTrm st in SrcTrms)
{
if (st.idea.Contains(" "))
{
//its a multi term phrase
theseTrms += "Phrase: " + st.idea.ToString() + " Boost: " + getBoostValue(st.boost.ToString()) + "rn";
}
else
{
theseTrms += "Term: " + st.idea.ToString() + " Boost: " + getBoostValue(st.boost.ToString()) + "rn";
}
}
return theseTrms;
}

/********************************************************************************
* This method uses a case select to determine the numerical boost values
* for the getQuery method.
*/


private TopDocs spanQuery()
{
TopDocs spResults = null;
try
{

//SpanQuery spnQry = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term("BODY", "arrest")), new SpanTermQuery(new Term("BODY", "mirandized")) }, 30, false);
BooleanQuery booleanquery = new BooleanQuery();
PhraseQuery phrasequery; //used for multi term queries
Query query; //used for single term queries
directory = FSDirectory.Open(new DirectoryInfo(appDefaultindexPath));
IndexReader indexReader = IndexReader.Open(directory, true);
IndexSearcher indexSearch = new IndexSearcher(indexReader);
//indexSearch.Similarity = DefaultSimilarity;
var queryParser = new QueryParser(Version.LUCENE_30, "BODY", analyzer);
//TopDocs resultDocs = null;
//loop thru all the phrases
SpanQuery spNrQry = null;
List<SpanQuery> spnQry = new List<SpanQuery> { };
int slp = Convert.ToInt32(txtPhrSlop.Text);
foreach (SrcTrm i in SrcTrms)
{
//get the boost right off the bat
float bst = 1;
//MessageBox.Show("Idea is: " + i.idea );
if (i.idea.Contains(" ")) //if the idea is a phrase be careful of hyphens!!!
{
//MessageBox.Show("This is a phrase: " + i.idea);
String[] phrs = i.idea.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
foreach (String str in phrs)
{
//MessageBox.Show("str is: " + str);
spnQry.Add(new SpanTermQuery(new Term("BODY", str)));
}

spNrQry = new SpanNearQuery(spnQry.ToArray(), slp, false);
//MessageBox.Show("The span terms are: " + spNrQry.ToString());
//MessageBox.Show("This many spans: " + spResults.MaxScore );
//add this span query to the boolean query with the correct weights
if (i.boost == "Must")
{
bst = (float)Convert.ToInt32(Must_Weight);
spNrQry.Boost = bst;
booleanquery.Add(spNrQry, Occur.MUST);
}
else if (i.boost == "Never")
{
booleanquery.Add(spNrQry, Occur.MUST_NOT);
}
else if (i.boost == "Probable")
{
bst = (float)Convert.ToInt32(Probable_Weight);
spNrQry.Boost = bst;
booleanquery.Add(spNrQry, Occur.SHOULD);
}
else if (i.boost == "Possible")
{
bst = (float)Convert.ToInt32(Possible_Weight);
spNrQry.Boost = bst;
booleanquery.Add(spNrQry, Occur.SHOULD);
}
//This may need to be Should below
else if (i.boost == "Critical")
{
bst = (float)Convert.ToInt32(Critical_Weight);
//MessageBox.Show("The boost is: " + bst);
spNrQry.Boost = bst;
booleanquery.Add(spNrQry, Occur.SHOULD);
}

}
else //this must be a single term
{
//I am not sure if I should inclulde singletons here as it will give tf/idf unless I use the custom one where its reduced
}
}

//MessageBox.Show("The span terms are: " + booleanquery.ToString());

spResults = indexSearch.Search(booleanquery, spanMaxSize);//indexReader.MaxDoc);
int thsRes = spResults.TotalHits;
//MessageBox.Show("The number span terms are: " + thsRes.ToString());
// MessageBox.Show("This many spans: " + spResults.TotalHits.ToString());
return spResults;
}
catch (Exception err)
{
return spResults;
}
}


     
 
what is notes.io
 

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

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.