Getting when executing a Linq to Sitecore query

I ran into an interesting Linq issue for Sitecore. I have a case where I have a people directory and a location directory that are all stored in Sitecore. I am trying to write a search function that will allow me to search for people nearby. Adding wrinkles to this is the fact that people can be associated with several locations.

So far, the approach has been to find nearby locations, get their ID, and then find all the people that are associated with those locations.

It looks something like this:

var locations = GetNearbyLocations(lat, long, radius) // returns a list of short ID 

var searchPredicate = PredicateBuilder.True<SearchResultItem>();
var locationsPredicate = PredicateBuilder.False<SearchResultItem>();

foreach (var location in locations)
{
    locationPredicate = locationPredicate.Or(x => x["location"] == location);
}

searchPredicate = searchPredicate.And(locationPredicate);
searchPredicate = searchPredicate.And(sri => sri.TemplateId == personTemplateId);

using (var context = index.CreateSearchContext())
{
    var peopleReults = context.GetQueryable<SearchResultItem>.Where(locationPredicate).GetResults();
}

      

This works well if it GetNearbyLocations

returns a relatively small set of locations. Once we get over 150 or so, the call GetQuerable

will result in a stack overflow.

+3


source to share


2 answers


You can probably use an array of locations and do a.

 locationPredicate.And(x=>locations.Contains(x["location"]));

      



If you get a big bold error from this post, print out some lambda expressions that you can use instead.

0


source


Lucene can only handle 1024 sentences at a time.

There is a Sitecore parameter called ContentSearch.LuceneQueryClauseCount that should force Lucene to accept any number of clauses you define in the setup, but doesn't seem to work. Changing the value of this parameter doesn't seem to do anything during the search operation. There is one way to get this setting to read and make Lucene accept more than 1024 OR clauses at a time. Increase the value of this parameter and run this line of code before searching:



BooleanQuery.MaxClauseCount = int.Parse(Sitecore.Configuration.Settings.GetSetting("ContentSearch.LuceneQueryClauseCount"));

      

This allows you to submit a request with more than 1024 suggestions, however Lucene will still throw a StackOverflowException at some point. To get around the Lucene limitation, you have to split the number of OR clauses in increments of 1024 and run multiple queries with a subset of the OR clauses each time.

0


source







All Articles