Reputation: 425
I am not getting any result by using term query in Sitecore. I am not sure if am doing something wrong. Below are my config setting.
<demo type="scSearchContrib.Crawler.Crawlers.AdvancedDatabaseCrawler,scSearchContrib.Crawler">
<Database>web</Database>
<Root>/sitecore/content/rootPath</Root>
<IndexAllFields>true</IndexAllFields>
<include hint="list:IncludeTemplate">
<uniqueTemplateToken1>
{2BCE925C-6ED5-4F76-99D6-BF928A62819B}
</uniqueTemplateToken1>
</include>
<include hint="list:IncludeField">
<fieldId>{7D55A5C3-CAF5-4570-AA7B-1240836BEE8D}</fieldId>
</include>
<fieldTypes hint="raw:AddFieldTypes">
<fieldType name="Multi-Line Text" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" />
</fieldTypes>
</demo>
And this is my code where "Description" is my filed name and same filed name I already defined in config. Every time I am getting "0" result.
using (IndexSearchContext sc = SearchManager.GetIndex("demo").CreateSearchContext())
{
TermQuery createdByAdminQuery = new TermQuery(new Term("Description", "Lorem"));
BooleanQuery query = new BooleanQuery();
query.Add(createdByAdminQuery, BooleanClause.Occur.MUST);
query.SetMinimumNumberShouldMatch(1);
TopDocs topDocs = sc.Searcher.Search(query, int.MaxValue);
SearchHits searchHits = new SearchHits(topDocs,sc.Searcher.GetIndexReader());
return searchHits.FetchResults(0, int.MaxValue).Select(r => r.GetObject<Item>()).ToList();
}
Please help me if I am doing something wrong.
Upvotes: 0
Views: 851
Reputation: 425
Thanks for your help .
Finally I got solution for this issue . The issue was in using term query . The way where I used Term query was not correct. Below are the correct way:
using (IndexSearchContext sc = SearchManager.GetIndex("demo").CreateSearchContext())
{
Term term = new Term("description", "tutu");
Query query1 = new TermQuery(term);
SearchHits searchHits = sc.Search(query1, int.MaxValue);
sc.Searcher.GetIndexReader());
return searchHits
.FetchResults(0, int.MaxValue)
.Select(r => r.GetObject<Item>()).ToList();
}
It will work .
Upvotes: 1
Reputation: 5860
In this case, the only obvious thing you should change is your search term. "Lorem" to "lorem". Long story short, when your documents get indexed and tokenized, they are stored in lower-case in your index. This is specific to the Sitecore implementation, not something Lucene does on its own.
I had the same issue as you (or at least I believe so) here: TermQuery not returning on a known search term, but WildcardQuery does
Upvotes: 3