I'm trying to implement a text search option using the Lucene-based full-text search engine on my NHibernate-based MVC project (NHibernate.Search). All the documentation I've seen on how to do this suggests I need to look at specific columns for values, something like:
var query = "Title:Ford";
using (var search = NHibernate.Search.Search.CreateFullTextSession(s))
{
using (var transaction = s.BeginTransaction())
{
var carSearchResults = search.CreateFullTextQuery(query)
.SetMaxResults(5)
.List();
foreach(var car in carSearchResults)
{
Console.WriteLine(car.Title);
}
transaction.Commit();
}
}
I would rather look at all full-text indexed columns for the search string, like you can do in SQL with a wildcard on the FREETEXT
function... so I could do something like:
var query = "Ford";
using (var search = NHibernate.Search.Search.CreateFullTextSession(s))
{
using (var transaction = s.BeginTransaction())
{
var carSearchResults = search.CreateFullTextQuery(query)
.SetMaxResults(5)
.List();
foreach(var car in carSearchResults)
{
Console.WriteLine(car.Title);
}
transaction.Commit();
}
}
... and this would examine all full-text indexed properties for "Ford", and return all hits. Is there a comparable function/ method/ syntax for this using the NHibernate-based search engine?
Take a look at How to incorporate multiple fields in QueryParser?
Short answer, change:
var query = "Title:Ford";
to:
var query = "Title:Ford OR Name:Ford OR Field1:Ford OR Field2:Ford"; // etc for all fields
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.