Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an overload to the LuceneSearchQuery to provide a Lucene Filter #185

Open
Shazwazza opened this issue Sep 15, 2020 · 2 comments
Open

Comments

@Shazwazza
Copy link
Owner

Currently there is an overload specifically on the LuceneSearchQuery that allows passing in a Lucene Query instance to perform a search but it would also be nice to be able to provide a Lucene Filter. For example, this would mean that for Spatial searches we wouldn't have to manually execute the query: https://github.com/Shazwazza/Examine/blob/master/src/Examine.Test/Extensions/SpatialSearch.cs#L100

@dealloc
Copy link

dealloc commented Dec 21, 2022

I currently integrated spatial queries with this extension methods:

	/// <summary>
	/// Creates a query for results near the given <paramref name="latitude" />, <paramref name="longitude" /> in a radius of <paramref name="distance" />.
	/// </summary>
	/// <remarks>This requires an index of <see cref="Constants.Constants" /> to be present.</remarks>
	public static IBooleanOperation Location(this IQuery query, double latitude, double longitude, double distance)
	{
		if (query is not LuceneSearchQuery luceneQuery)
			throw new InvalidOperationException("Location queries are only supported on Lucene queries");

		var spatialContext = SpatialContext.Geo;
		var grid = new GeohashPrefixTree(spatialContext, 11); // 11 = sub-metre precision for geohash
		var strategy = new RecursivePrefixTreeStrategy(grid, Constants.LOCATION_INDEX_FIELD);

		var args = new SpatialArgs(SpatialOperation.Intersects, spatialContext.MakeCircle(longitude, latitude, DistanceUtils.Dist2Degrees(distance, DistanceUtils.EarthMeanRadiusKilometers)));
		var locationQuery = strategy.MakeQuery(args);

		return luceneQuery.LuceneQuery(locationQuery, BooleanOperation.And);
	}

I currently have the location field on the index as a constant, but it shouldn't be too hard to add a parameter for that, this way I can still treat them like normal Examine queries otherwise.

@nzdev
Copy link
Contributor

nzdev commented Aug 15, 2023

I've made a start on filtering and spatial. https://github.com/nzdev/Examine/tree/v4/feature/filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants