Currently I am writing a query by using LINQ for Sitecore search content. Having a strange is that I cannot search content with keyword 'with'. Everyone have idea for this ?
using (var searchContext = index.CreateSearchContext())
{
var result = searchContext.GetQueryable<SearchResultItem>()
.Where(w =>
w.Content.Contains(searchText)
);
}
The result is empty, I also have try with operator 'like' (w.Content.Lile) but result empty.
I'm not familiar with Lucene.net / sitecore, but it's possible that "with" is a stopword and Lucene removes it when indexing documents. Try including some other keywords in your query to see if you get results. See What is the default list of stopwords used in Lucene's StopFilter? for more details on stopwords.
The code looks fine, the only thing I could see causing an issue would be a case issue. Try this instead:
x.Content.ToUpper().Contains(searchText.ToUpper())
Also, not sure about the Lucene.Net implementation, but this looks like simple Linq-SQL or EF to me, and the .Contains() method is executed locally, not remotely.
Related
I am trying to create one query in the Kibana search bar to retrieve some specific documents.
The goal is to get the documents that either have the field "myDate" before 2019-10-08 or "myDate" does not exist.
I have documents that meet one or the other condition.
I started by creating this query :
myDate:<=2019-10-08 OR NOT _exists_:myDate
But no documents were returned.
Since it did not work, I tried some other ways i found online :
myDate:<=2019-10-08 OR NOT (_exists_:myDate)
myDate:<=2019-10-08 OR !(_exists_:myDate)
myDate:<=2019-10-08 OR NOT (myDate:*)
But still, no results.
When I use either "part" of the "OR" condition, it works perfectly : I get either the documents who have myDate<=2019-10-08 or the ones that do not have a "myDate" field filled.
But when I try with both conditions, I get no document.
I have to use only the search bar to find these documents, neither an elasticsearch rest query nor by using kibana filters.
Thank you for your help :)
Below query works. Use Inspect button in kibana to see what query is actually being fired and make sure you are using correct index pattern as well.
(myDate:<=2019-12-31) OR (NOT _exists_:myDate)
Take a look at Query DSL documentation for Boolean operators for more better understanding with different use cases
I've been using boolquerybuilder. The results are fine.
Whats the purpose of using BoolFilterBuilder and FilteredQueryBuilder.
can i use them instead of boolquerybuilder?
Since version 2.0 Filtered Query is removed.
Use the bool query instead with a must clause for the query and a filter clause for the filter
see here
by
I have two users with name 'Alex' and 'Andrei'. When i write query like 'A', I get 0 results. I have to search with the full name and matching capitalization to get a result.
I want for example just query for 'e' end receive 2 records.
Session s = session.getCurrentSession();
FullTextSession fullTextSession = Search.getFullTextSession(s);
QueryBuilder qb = fullTextSession.getSearchFactory()
.buildQueryBuilder().forEntity(User.class).get();
org.apache.lucene.search.Query q = qb
.keyword().onFields("name")
.matching(query)
.createQuery();
org.hibernate.Query hibQuery =
fullTextSession.createFullTextQuery(q, User.class);
List<User> results = hibQuery.list();
You are not showing how you index the first names. This is as well important. For example if you store index them un-analyzed, you need to take indeed capitalization into account. Also as mentioned in the comment, you need to look at the right analyzer. You case would only work if you were to use wildcard queries.
On a tangent, I don't know how close your example is to your actual usecase, but searching for a single character is probably not a typical free-text search use-case.
This particular behavior reminds me one error I got once.
'A' is a stop word (in English language) used by the standard analyzer of Hibernate Search, so you have to precise a custom analyser without this stop word.
These Links could help you
To use a custom analyzer: https://docs.jboss.org/hibernate/search/3.1/reference/en/html/search-mapping.html
To understand what I mean with 'a' like a stop word: Getting error on a specific query
I'm trying to get results of a facet query using solrj, but it seems it doesn't matter whether I add the facet query or not. I get the same document list anyway.
So this query returns the same document list...
query.setQuery(searchString);
query.setFacet(true);
query.addFacetField("CATNAME_STR");
query.addFacetQuery("CATNAME_STR:" + facetName);
...with this query
query.setQuery(searchString);
query.setFacet(true);
query.addFacetField("CATNAME_STR");
Only difference is I can get number of documents that matches the facet query with response.getFacetQuery();
I was expecting it to work like
http://localhost:8983/solr/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on&facet=on&facet.field=CATNAME_STR&fq=CATNAME_STR:Erasmus
Any ideas?
Thanks.
By the way I'm using Solr Version 3.1.0 and solr-core-3.1.0
As it turns out fq=CATNAME_STR:Erasmus does not mean query.addFacetQuery("CATNAME_STR:Erasmus") but instead query.addFilterQuery("CATNAME_STR:Erasmus")
Hi Experts
I have a special question About dynamic Linq to Sql.
Consider we want to search in a table according two fields*(LetterNo(string) and LetterDate(Datetime))*
.OK the problem is user can enter on of that fields or even both.
I searched in the internet and found "Linq.Dynamic" library in ScottGu weblog.but in that library if we want to use SqlParameter in exported command we should use #0 and param for that.problem is I don't know how many fields user entered.
I want use one query for that and no external tool like "Linq Kit PredicateBuilder".
If I create my query string Manually(and execute using ExecuteCommand) then I will abdicate SqlParameter and risk of Sql Injenction growing up.
How Can do that?
thanks
I suspect you are wanting to do something like the following:
IQueryable<Letter> query = context.Letters;
if (!string.IsNullOrEmpty(LetterNo))
query = query.Where(letter => letter.LetterNo == LetterNo);
If (LetterDate.HasValue)
query = query.Where(letter => letter.LetterDate == LetterDate);
When you execute query, it will combine the necessary expressions and issue a single query to the database based on the user's input.