Regarding word search and lucene.net c# - asp.net

i will use lucene.net first time so couple of confusion arising in mind when see the line of code. i got a sample code for searching word with lucene and few line are not clear to me.here is sample code below.
Question 1
ListBox1.Items.Clear();
var searcher = new Lucene.Net.Search.IndexSearcher(MapPath("~/searchlucene/"));
var oParser = new Lucene.Net.QueryParsers.QueryParser("content", new StandardAnalyzer());
string sHeader = " OR (header:" + TextBox1.Text + ")";
string sType = " OR (type:" + TextBox1.Text + ")";
string sSearchQuery = "(" + TextBox1.Text + sHeader + sType + ")";
var oHitColl = searcher.Search(oParser.Parse(sSearchQuery));
for (int i = 0; i < oHitColl.Length(); i++)
{
Document oDoc = oHitColl.Doc(i);
ListBox1.Items.Add(new ListItem(oDoc.Get("header") + oDoc.Get("type") + oDoc.Get("content")));
}
searcher.Close();
Question 2
this below lines not clear what is going on...!! please discuss the objective of each line below.
string sHeader = " OR (header:" + TextBox1.Text + ")";
string sType = " OR (type:" + TextBox1.Text + ")";
string sSearchQuery = "(" + TextBox1.Text + sHeader + sType + ")";
var oHitColl = searcher.Search(oParser.Parse(sSearchQuery));
for (int i = 0; i < oHitColl.Length(); i++)
{
Document oDoc = oHitColl.Doc(i);
ListBox1.Items.Add(new ListItem(oDoc.Get("header") + oDoc.Get("type") + oDoc.Get("content")));
}
Question 3
what is header:
what is type:
why heade & type concatinated after search keyword like string
sSearchQuery = "(" + TextBox1.Text + sHeader + sType + ")";
Question 4
why content is missing in searchquery content
what would be the result if i write like
string sHeader = " OR (header:" + TextBox1.Text + ")";
string sType = " OR (type:" + TextBox1.Text + ")";
string sContent = " OR (content:" + TextBox1.Text + ")";
string sSearchQuery = "(" + TextBox1.Text + sHeader + sType + sContent ")";
why header, type & content is reading....what for??
*oDoc.Get("header") + oDoc.Get("type") + oDoc.Get("content")*
why i need to read header,type & content like
oDoc.Get("header") + oDoc.Get("type") + oDoc.Get("content")
we can read content only....why type & header is also required??

The first code builds a query that searches several fields, assuming that the input in TextBox1 does not mess with the query (like containing parentheses or whitespaces). Building a search query with string concatenation is often hard to get right, I would use the MultiFieldQueryParser instead.
var fields = new[] { "content", "header", "type" };
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
var queryParser = new MultiFieldQueryParser(Version.LUCENE_30, fields, analyzer);
var query = queryParser.Parse(TextBox1.Text);
var result = searcher.Search(query, 25); /* find 25 best matches */
Your for-loop iterates through the result and reads the values of the stored fields and add them to a listbox. This requires that the fields where indexed with Field.Store.YES to work.

Related

Need to give cell value when mail has been sent with time and date in google script code [duplicate]

I want to give last cell value of col no. 20 when mail has been sent with time and date in the below script. and using this code when more than one rows are added at a time then "sent" value is being added to the last row only and remaining rows are left blank. when new other row is added since value is not equal to sent those values are also been attached So, when mail sent complete column need to be given value as sent. Once please check this
function sendEmail() {
//setup function
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,16);
var AllValues = WholeRange.getValues();
var message = "";
//iterate loop
for (i in AllValues) {
//set current row
var CurrentRow = AllValues[i];
//define column to check if sent (starts from "0" not "1")
var EmailSent = CurrentRow[14];
var caseworker = CurrentRow[7];
//if row has been sent, then continue to next iteration
if (EmailSent == "sent")
continue;
//set HTML template for information
message +=
"<p><b>Bank: </b>" + CurrentRow[1] + "</p>" +
"<p><b>Branch: </b>" + CurrentRow[2] + "</p>" +
"<p><b>Region: </b>" + CurrentRow[3] + "</p>" +
"<p><b>Lan Number: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Customer Name: </b>" + CurrentRow[5] + "</p>" +
"<p><b>Loan Type: </b>" + CurrentRow[6] + "</p>" +
"<p><b>Case Worker: </b>" + CurrentRow[7] + "</p>" +
"<p><b>Site Visit Status: </b>" + CurrentRow[8] + "</p>" +
"<p><b>Site Visit Done By: </b>" + CurrentRow[9] + "</p>" +
"<p><b>Document recieved: </b>" + CurrentRow[11] + "</p>" +
"<p><b>File Upload: </b>" + CurrentRow[12] + "</p>" +
"<p><b>Remarks: </b>" + CurrentRow[10] + "</p><br><br>";
//set the row to look at
var setRow = parseInt(i) + StartRow;
//mark row as "sent"
ActiveSheet.getRange(setRow, 15).setValue("sent");
}
//define who to send grants to
var SendTo = "########gmail.com" + "," + "##########gmail.com" + "," + " ##########gmail.com";
//set subject line
var Subject = "New case initiated to Shirisha";
//send the actual email
MailApp.sendEmail({
to: SendTo,
cc: "##########gmail.com",
subject: Subject,
htmlBody: message,
});
}

Please Verify My ASP.NET Code to insert data to oracle database

No matter what I do the following code does not seem to work. It always breaks at ExecuteNonQuery().
Anything I am missiong?
Always throws
System.InvalidOperationException: 'Operation is not valid due to the current state of the object.'
protected void Submit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
OracleConnection conn = new OracleConnection(connectionString);
int room_id = Int32.Parse(DropDownList2.SelectedValue);
int activity_id = Int32.Parse(DropDownList1.SelectedValue);
string session_code = TextBox1.Text;
int start_time = GetTimeSeconds(startTime.Text);
int period = GetTimeSeconds(duration.Text);
string book_date = bookDate.Text;
string ref_no = DropDownList3.SelectedValue;
conn.Open();
using (OracleCommand cmd = new OracleCommand(
"insert into BRAZESH.ALL_SESSION(SESSION_CODE,START_TIME,\"PERIOD\",BOOKED_DATE,ROOM_ID,ACTIVITY_ID,REF_NO)" +
" values ('" + session_code + "'," + start_time + "," + period + ",to_date('" + book_date + "', 'yyyy-mm-dd')," + room_id + "," + activity_id + ", '" + ref_no + "')"))
{
try
{
cmd.ExecuteNonQuery();
}catch (OracleException ex)
{
throw ex;
}
}
}
}
You are not using conn while defining the connection to be used by the command. use the following line. Read details on usage here
using (OracleCommand cmd = new OracleCommand(
"insert into BRAZESH.ALL_SESSION(SESSION_CODE,START_TIME,\"PERIOD\",BOOKED_DATE,ROOM_ID,ACTIVITY_ID,REF_NO)" +
" values ('" + session_code + "'," + start_time + "," + period + ",to_date('" + book_date + "', 'yyyy-mm-dd')," + room_id + "," + activity_id + ", '" + ref_no + "')",conn))

Forward Slash is removed in path

I have set the html from code behind in ItemDataBound event of repeater but in html path is not right.
Dim video_path = imgUrl + VideoPath + VideoName.split(".")(0) + ".mp4"
Dim poster_path = imgUrl + VideoPath + VideoName.split(".")(0) + ".png"
Dim DvVidContent As HtmlContainerControl = CType(e.Item.FindControl("DvVidContent"), HtmlContainerControl)
Dim onclick = "'ShowVideoDialog('size_vp_" + count.ToString() + "', '" + video_path.ToString().Trim() + "');'"
Dim Header As String = "<div style='position:relative;' Sequence='" + count.ToString() + "' id='" + ID.ToString() + "' class='SessionFolderViewChild'><img onerror='handleError(this);' src='" + poster_path.ToString() + "' alt='Thumbnail'/><img class='dv_play_icon' onclick='" + onclick + "' id='PlayVideo' style='position:absolute;top:8px;left:26px;height:100px;width:100px;' src='../../Images/icn_Play.png'/></a></div>"
DvVidContent.InnerHtml = Header.Trim()
count = count +
After Html rendering its remove the forward slash and look like
onclick="ShowVideoDialog("size_vp_1','.. .. resources sbs attachments steps351 step565 130906720751358852.mp4');

The meaning of the ampersand

In this line:
var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&msg=' + msg;
What does the ampersand(&) mean?
I think the ampersands are meant for query string separation from each other
var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&msg=' + msg;
becomes
var dataString = 'name=John Doe&email=johndoe#gmail.com&subject=some email subject&msg=hey activate your account';
This can then be appended to your Url
var finalUrl = "http://mysite.com?" + dataString;

How to connect mysql to DevExpress ASPxScheduler without SqlDataSource

I have an ASP.net project I'm looking at and they want to use MySQL. I'm used to SQL server but using mySQL shouldn't be a problem.
Normally the control would like a SqlDataSource to bind to but that's not available with MySQL (from other posts on this site).
What's the best way to connect MySQL and the DevExpress ASPxScheduler so that you can create appointments?
Why not an ObjectDataSource and write the data layer? Or use LLBLGen, I think it works just fine with MySQL. The one caveat I've seen is that the MySQL ODBC and ADO drivers have issues with metadata.
I did end up using the objectdatasource and the ObjectCreated method and wrote the datalayer to insert records into the mysql database. I've included my code just incase someone needs some help with some of the logic.
protected void appointmentsDataSource_ObjectCreated(object sender, ObjectDataSourceEventArgs e)
{
e.ObjectInstance = new CustomEventDataSource(GetCustomEvents());
}
public void InsertAppointment()
{
//need to reformat the dates
string tempStartDate;
string tempStartMinutes;
if (appointmentobject.Start.Minute.ToString().Length == 1)
{
tempStartMinutes = "0" + appointmentobject.Start.Minute.ToString();
}
else
{
tempStartMinutes = appointmentobject.Start.Minute.ToString();
}
tempStartDate = AppointmentObject.Start.Year + "-"
+ AppointmentObject.Start.Month + "-"
+ appointmentobject.Start.Day + " "
+ appointmentobject.Start.Hour + ":"
+ tempStartMinutes;
string tempEndDate;
string tempEndMinutes;
if (appointmentobject.End.Minute.ToString().Length == 1)
{
tempEndMinutes = "0" + appointmentobject.End.Minute.ToString();
}
else
{
tempEndMinutes = appointmentobject.End.Minute.ToString();
}
tempEndDate = AppointmentObject.End.Year + "-"
+ AppointmentObject.End.Month + "-"
+ appointmentobject.End.Day + " "
+ appointmentobject.End.Hour + ":"
+ tempEndMinutes;
//TODO Add CustomField : Need to add to this Insert Statement
//Change the appointment subject
string NewSubject = AppointmentObject.CustomFields["fldFirstName"]
+ ", " + AppointmentObject.CustomFields["fldLastName"]
+ ", " + AppointmentObject.CustomFields["fldClassID"]
+ ", " + AppointmentObject.CustomFields["fldPhoneNumberDay"];
string mySQLQueryString = #"INSERT INTO appointment (StartDate,EndDate,Subject,Status,Description,label,location,Type,FirstName,
LastName,PhoneNumberDay,PhoneNumberEvening,DriversLicenseNumber,Email,RentalCar,Payment,ConfirmationNumber,
PermitNumber,ClassID,CreateDate,CreateUser,NoticeToReport)
VALUES('" + tempStartDate + "','"
+ tempEndDate + "', '"
//+ AppointmentObject.Subject + "',"
+ NewSubject + "',"
+ AppointmentObject.StatusId + ",'"
+ AppointmentObject.Description + "',"
+ AppointmentObject.LabelId + ", '"
+ AppointmentObject.Location + "',"
+ "0, '" //type
+ AppointmentObject.CustomFields["fldFirstName"] + "','"
+ AppointmentObject.CustomFields["fldLastName"] + "','"
+ AppointmentObject.CustomFields["fldPhoneNumberDay"] + "','"
+ AppointmentObject.CustomFields["fldPhoneNumberEvening"] + "','"
+ AppointmentObject.CustomFields["fldDriversLicenseNumber"] + "','"
+ AppointmentObject.CustomFields["fldEmail"] + "',"
+ AppointmentObject.CustomFields["fldRentalCar"] + ","
+ AppointmentObject.CustomFields["fldPayment"] + ",'"
+ AppointmentObject.CustomFields["fldConfirmationNumber"] + "','"
+ AppointmentObject.CustomFields["fldPermitNumber"] + "',"
+ AppointmentObject.CustomFields["fldClassID"] + ", '"
//ignore create date for now.
//+ AppointmentObject.CustomFields["fldCreateDate"] + "', '"
+ "2009-01-01 12:00', '"
+ AppointmentObject.CustomFields["fldCreateUser"] + "', "
+ AppointmentObject.CustomFields["fldNoticeToReport"] + ")";
MySqlConnections test = new MySqlConnections();
test.InsertRow(mySQLQueryString);
}
public class MySqlConnections
{
private static string DriverConnectionString = "Database=driverexam;Data Source=localhost;User Id=ART;Password=art01";
public DataSet SelectRows(DataSet dataset, string query, string tablename)
{
MySqlConnection conn = new MySqlConnection(DriverConnectionString);
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = new MySqlCommand(query, conn);
adapter.Fill(dataset, tablename);
conn.Close();
return dataset;
}
public bool InsertRow(string query)
{
// MySqlConnection conn = new MySqlConnection(DriverConnectionString);
MySqlConnection conn = new MySqlConnection();
MySqlCommand cmd = new MySqlCommand();
conn.ConnectionString = DriverConnectionString;
try
{
conn.Open();
cmd.Connection = conn;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
conn.Close();
Console.WriteLine("Success Occurred ");
} //end of try
catch(Exception ex)
{
Console.WriteLine("Error Occurred - " + ex.Message);
}
return true;
}
}

Resources