I was wondering if there is a way in Umbraco, when searching through content, to return only the objects that contain the full search string?
For example if I am searching for 'people management', I want to return only content that contains 'people management' next to each other, exactly like in my search.
I don't want content that has 'people' in one sentence and 'management' in another one.
I am guessing this is for search on umbraco front end of the site not in the umbraco backoffice?
In examine you can do phrase query i think you would have do it with raw lucene query so
+content:"people mangement"
You can set up examine to use And operator instead of OR but i think that would match if you had people and mangement on different lines. Phrase would do exactly what you want but you need to do raw query.
ExamineManager.Instance.TryGetIndex(Umbraco.Core.Constants.UmbracoIndexes.ExternalIndexName, out var index);
var searcher = index.GetSearcher();
var query = searcher.CreateQuery("content").Field("excludeFromSearch", "0");
query.And().NativeQuery("+content:\"people mangement\"");
This is assuming the field you want to search over is called content, you will need to replace that with whatever field you want to search over.
Search Results
Hi all,
I was wondering if there is a way in Umbraco, when searching through content, to return only the objects that contain the full search string?
For example if I am searching for 'people management', I want to return only content that contains 'people management' next to each other, exactly like in my search.
I don't want content that has 'people' in one sentence and 'management' in another one.
Thank you.
Raluca,
I am guessing this is for search on umbraco front end of the site not in the umbraco backoffice?
In examine you can do phrase query i think you would have do it with raw lucene query so
You can set up examine to use And operator instead of OR but i think that would match if you had people and mangement on different lines. Phrase would do exactly what you want but you need to do raw query.
This is assuming the field you want to search over is called content, you will need to replace that with whatever field you want to search over.
Regards
Ismial
is working on a reply...