I'm currently working on implementing a search feature in my Umbraco project, and I'm looking for guidance on how to perform a search query that returns all results containing a specified string.
So for example,
If i search for "Gre" I want all of the products that has "Green" in their title
but also a product that contains "Great"
I would appreciate any help or advice on constructing the search query to achieve the desired functionality.
Is it just a section of Products you are searching, and in your example you show a search where the matches 'start with' the search term.. but you say it should use the logic contains - what I'm saying is should you Gre search also match the Ogre 2000 product?
Umbraco comes with Examine Search built in, which is a friendly syntax around a Lucene search index - this is great for analysing and searching key terms within a lot of text, but is less great for specific 'like' or 'contains' queries that you would typically make to a database.
If your search is a complex one and involves for searching within the descriptions of the products for the best matching text, then Examine will b e super useful!
But if you only want to match on the 'name' of the product and you want functionality like contains or starts with only then querying the Umbraco Published Cache would probably be sufficient.
var productsSection = Umbraco.ContentAtRoot().FirstOrDefault().Children<ProductSection>().FirstOrDefault();
var products = productsSection.Children<Product>("f=>f.ProductTitle.StartsWith(searchTerm));
or
var products = productsSection.Children<Product>("f=>f.ProductTitle.Contains(searchTerm));
but it just depends on what you are trying to do in terms of complexity of search options and how many products... 70 or 7 million etc
umbraco search query
Hello Umbraco community,
I'm currently working on implementing a search feature in my Umbraco project, and I'm looking for guidance on how to perform a search query that returns all results containing a specified string.
So for example,
If i search for "Gre" I want all of the products that has "Green" in their title but also a product that contains "Great"
I would appreciate any help or advice on constructing the search query to achieve the desired functionality.
Best regards, Max
Hi Max
Is it just a section of Products you are searching, and in your example you show a search where the matches 'start with' the search term.. but you say it should use the logic contains - what I'm saying is should you Gre search also match the Ogre 2000 product?
Umbraco comes with Examine Search built in, which is a friendly syntax around a Lucene search index - this is great for analysing and searching key terms within a lot of text, but is less great for specific 'like' or 'contains' queries that you would typically make to a database.
If your search is a complex one and involves for searching within the descriptions of the products for the best matching text, then Examine will b e super useful!
It also has Wildcard search support and Fuzziness to match similar spellings etc, you can read more here: https://shazwazza.github.io/Examine/articles/searching.html#wildcards
But if you only want to match on the 'name' of the product and you want functionality like contains or starts with only then querying the Umbraco Published Cache would probably be sufficient.
or
but it just depends on what you are trying to do in terms of complexity of search options and how many products... 70 or 7 million etc
regards
Marc
is working on a reply...