Sharepoint 2010 FullTextSQLQuery not returning all results - c#

I'm currently having a very strange issue.
This is the query i'm using:
string queryText = string.Format("SELECT Path, TelefoneContacto, EmpresaContacto, DireccaoContacto, MailContacto, TelemovelContacto, NomeContacto FROM scope() WHERE FREETEXT(NomeContacto, '{0}') AND (CONTAINS(Path,'/Contactos/Pages/')) ORDER BY \"NomeContacto\" ASC", keyword);
FullTextSqlQuery query = new FullTextSqlQuery(site);
query.ResultTypes = ResultType.RelevantResults;
query.EnableStemming = true;
query.TrimDuplicates = true;//alterado 4 Junho 2012
query.Hint = QueryHint.OptimizeWithPropertyStore;
query.KeywordInclusion = KeywordInclusion.AllKeywords;
query.Culture = SPContext.Current.Web.Locale;
query.RowLimit = 200;
query.QueryText = queryText;
Now, an example.
The column in which i'm searching is "NomeContacto".
Imagine i'm searching for a person whose NomeContacto = "Rodrigo José Amaral Costa Nunes". If i search "Costa", it returns 38 results, but none are the above.
However, if the keyword is "Rodrigo Costa", then the only result (correctly) is the person above.
Is there even an explanation for this?

Thanks, but i solved it.
Turns out that it was the
query.TrimDuplicates = true;
line that was causing the issue. I changed it from true to false and it now returns 10 more results in the "costa" search.
However, this does not make any sense. TrimDuplicates is for duplicate values, why was it limiting the results for completely different pages?
Thanks anyway

You can try to specify locale for you content in FREETEXT predicate
CONTAINS | FREETEXT
([<column_identifier>,]'<content_search_condition>' [,LCID])
More info about localizaed searches here

Related

Lucene .NET searching

Hi i am trying to make autocomplete system using Lucene library to search over 170K records.
But there is a litle problem.
For example when i search for Candice Gra(...), it brings records like
Candice Jackson
Candice Hamilton
Candice Hayes
Bu not Candice Graham to make Lucene find Candice Graham i need to type Candice Graham exactly.
Here is the code that i'm building query.
Directory directory = FSDirectory.Open(new DirectoryInfo(context.Server.MapPath("
ISet<string> stopWordSet = new HashSet<string>(stopWords);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30, stopWordSet);
IndexReader indexReader = IndexReader.Open(directory, true);
Searcher indexSearch = new IndexSearcher(indexReader);
//Singe Field Search
var queryParser = new QueryParser(Version.LUCENE_30,
"Title",
analyzer);
string strQuery = string.Format("{0}", q);
var query = queryParser.Parse(strQuery);
If i build strQuery like this (* appended to the query)
string strQuery = string.Format("{0}*", q);
But using this way brings irrelevant records too.
For example if i search Candice Gra(...) again it returns records like
Grass
Gravity
Gray (etc.)
By the way i used KeywordAnalyzer and SimpleAnalyzer but these are not worked either.
Any ideas?
You should escape your spaces if you want them included in the search;
var query = queryParser.Parse(QueryParser.Escape(strQuery));
I think you need to put a AND keyword between these two words.
"Candice" AND "Gra"
http://lucene.apache.org/core/2_9_4/queryparsersyntax.html#AND

Linq 2 Sql - Getting the Id of the newly inserted row - Not working?

Lets assume this code:
Classified classified = new Classified();
classified.Title = title;
classified.IsActive = true;
user.Classifieds.Add(classified);
dContext.SubmitChanges();
Response.Redirect(string.Format("/classifieds/post/?cid=", classified.Id));
Well, classifiedId has no value, Since i am redirected to http://www.mysite.loc/classifieds/post/?cid=
anyone?
The problem is in your string format:
Response.Redirect(string.Format("/classifieds/post/?cid={0}", classified.Id));
You forgot to include the {0} so it knows where to place the ID.

Linq: Except(null)

I know the title of this question is obscure, but I don't know how to describe exactly just in a few words. What I want is to do a simple statistic on web page visitors. When people visi the page, it's IP will be stored in database, I count the IP to see how many visit times for a page, but I don't want to conclude my IP for sure. So my code is:
WebStatDataContext dc = new WebStatDataContext(_connString);
var query = from v in dc.VisitorInfos
where v.IP == "208.xxx.xxx.69"&&v.Site==site
select v.IP;
var all = from v1 in dc.VisitorInfos
where v1.Site==site
select v1.IP;
int result = all.Except(query).Count();
return result;
However, I found that it returns "1", if "query" is null. If "query" is not null, the result is correct. What happens here?

Filtering related data in a DataGridView

I have a DataGridView that pulls data from a couple tables similarly to this setup. It works great. Good post and answer. Continuing with the example in that post, I now want to create a filter that yields all transactions in the DataGridView that apply to a specific account by using a LIKE parameter on the account description.
I have a solution by checking the accounts table for the description and obtaining the IDAccount value then using that value in the DataGridView filter, but I was hoping there would be a more automated way using bindings.
Any ideas? Thank you for your suggestions.
Edit:
Supposing I have a TextBox control called AccountDescriptionBox, I'd like to be able to do something like
dataGridView1.Filter = string.Format("{0} LIKE '{1}'", "IDAccount", AccountDescriptionBox.Text);
Obviously, this won't work as IDAccount is an integer, not a string. The solution I mention above is
string filter = string.Empty;
Regex searchTerm = new Regex(Regex.Escape(AccountDescriptionBox.Text).Replace('\\', '.'), RegexOptions.IgnoreCase);
var accts = from acct in dataSet1.Accounts
let matches = searchTerm.Matches(acct.Description)
where matches.Count > 0
select acct.ID;
for (int i; i < accts.Count() - 1; i++)
{
filter += string.Format("IDAccount = {0} OR ",accts.ElementAt(i));
}
filter += string.Format("IDAccount = {0}",accts.Last());
dataGridView1.Filter = filter;
This works, but is cumbersome. I'd rather do it through bindings if there's a way.
Check out DataView class. It allows you to sort and filter records and also perform simple SQL-like manipulations.
I don't believe there is a way to do this directly with data bindings. I posted the solution as an edit in response to #CodeBlend's comments.

Is there a way to access the columns in a Dapper FastExpando via string or index?

I am pulling in a Dapper FastExpando object and want to be able to reference the column names dynamically at run time rather than at design/compile time. So I want to be able to do the following:
var testdata = conn.Query("select * from Ride Where RiderNum = 21457");
I want to be able to do the following:
foreach( var row in testdata) {
var Value = row["PropertyA"];
}
I understand that I can do:
var Value = row.PropertyA;
but I can't do that since the name of the property i'm going to need won't be known until runtime.
The answer from this SO Question doesn't work. I still get the same Target Invocation exception. So...
Is there any way to do what I want to do with a Dapper FastExpando?
Sure, it is actually way easier than that:
var sql = "select 1 A, 'two' B";
var row = (IDictionary<string, object>)connection.Query(sql).First();
row["A"].IsEqualTo(1);
row["B"].IsEqualTo("two");
Regarding the portion of the title "or index?" - I needed to access results by index since the column names being returned changed sometimes, so you can use a variation of Sam Saffron's answer like this:
var sql = "select 1, 'two'";
var row = (IDictionary<string, object>)connection.Query(sql).First();
row.Values.ElementAt(0).IsEqualTo(1);
row.Values.ElementAt(1).IsEqualTo("two");
There a simple way to access fields direct below sample
string strConexao = WebConfigurationManager.ConnectionStrings["connection"].ConnectionString;
conexaoBD = new SqlConnection(strConexao);
conexaoBD.Open();
var result = conexaoBD.Query("Select Field1,Field2 from Table").First();
//access field value result.Field1
//access field value result.Field2
if (result.Field1 == "abc"){ dosomething}

Categories

Resources