public Task <FacetedQueryResult> ExecuteFacetedQuery(string indexName, FacetQuery query, long?facetsEtag, long?existingResultEtag, OperationCancelToken token) { if (query.FacetSetupDoc != null) { FacetSetup facetSetup; using (_documentsContext.OpenReadTransaction()) { var facetSetupAsJson = _database.DocumentsStorage.Get(_documentsContext, query.FacetSetupDoc); if (facetSetupAsJson == null) { throw new DocumentDoesNotExistException(query.FacetSetupDoc); } try { facetSetup = JsonDeserializationServer.FacetSetup(facetSetupAsJson.Data); } catch (Exception e) { throw new DocumentParseException(query.FacetSetupDoc, typeof(FacetSetup), e); } facetsEtag = facetSetupAsJson.Etag; } query.Facets = facetSetup.Facets; } return(ExecuteFacetedQuery(indexName, query, facetsEtag.Value, existingResultEtag, token)); }
public virtual FacetedQueryResult GetFacets(List <Facet> facets, int start, int?pageSize) { var q = GetIndexQuery(false); var query = FacetQuery.Create(indexName, q, null, facets, start, pageSize); return(databaseCommands.GetFacets(query)); }
public virtual Task <FacetedQueryResult> GetFacetsAsync(List <Facet> facets, int start, int?pageSize, CancellationToken token = default(CancellationToken)) { var q = GetIndexQuery(); var query = FacetQuery.Create(indexName, q, null, facets, start, pageSize); return(asyncDatabaseCommands.GetFacetsAsync(query, token)); }
public List <FacetResult> FacetedQuery(FacetQuery facetQuery, DocumentsOperationContext context, Func <string, SpatialField> getSpatialField, CancellationToken token) { var results = FacetedQueryParser.Parse(context, facetQuery); var query = facetQuery.Query; var facetsByName = new Dictionary <string, Dictionary <string, FacetValue> >(); var baseQuery = GetLuceneQuery(context, query.Metadata, query.QueryParameters, _analyzer, _queryBuilderFactories); var returnedReaders = GetQueryMatchingDocuments(_searcher, baseQuery, _state); foreach (var result in results) { if (result.Value.Ranges == null || result.Value.Ranges.Count == 0) { HandleFacets(returnedReaders, result, facetsByName); continue; } HandleRangeFacets(result, returnedReaders); } UpdateFacetResults(results, query, facetsByName); CompleteFacetCalculationsStage(results); foreach (var readerFacetInfo in returnedReaders) { IntArraysPool.Instance.FreeArray(readerFacetInfo.Results.Array); } return(results.Values .Select(x => x.Result) .ToList()); }
public void RemoteDynamicFacetedSearchHonorsConditionalGet() { using (var store = GetDocumentStore()) { CreateCameraCostIndex(store); InsertCameraData(store, GetCameras(1)); var query = new FacetQuery { Facets = GetFacets(), Query = "FROM INDEX 'CameraCost' WHERE Manufacturer = 'canon'" }; var queryAsJson = JsonConvert.SerializeObject(query); string firstChangeVector; Assert.Equal(HttpStatusCode.OK, ConditionalGetHelper.PerformPost(store, "/queries", queryAsJson, null, out firstChangeVector)); //second request should give 304 not modified Assert.Equal(HttpStatusCode.NotModified, ConditionalGetHelper.PerformPost(store, "/queries", queryAsJson, firstChangeVector, out firstChangeVector)); //change index etag by inserting new doc InsertCameraData(store, GetCameras(1)); string secondChangeVector; //changing the index should give 200 OK Assert.Equal(HttpStatusCode.OK, ConditionalGetHelper.PerformPost(store, "/queries", queryAsJson, firstChangeVector, out secondChangeVector)); //next request should give 304 not modified Assert.Equal(HttpStatusCode.NotModified, ConditionalGetHelper.PerformPost(store, "/queries", queryAsJson, secondChangeVector, out secondChangeVector)); } }
public void FacetQuerySelectCountryAndSearchForStarbucks() { // Arrange var query = new FacetQuery("country").Search("starbucks"); // Assert AreEqualQueries("select=country&q=starbucks", query); }
public void FacetQuerySelectCountryAndSearchForStarbucks() { //Arrange var query = new FacetQuery("country").Search("starbucks"); //Assert AreEqualQueries("select=country&q=starbucks", query); }
public virtual FacetedQueryResult GetFacets(List <Facet> facets, int start, int?pageSize) { var q = GetIndexQuery(false); var query = FacetQuery.Create(q, null, facets, start, pageSize, Session.Conventions); var command = new GetFacetsCommand(_session.Conventions, _session.Context, query); _session.RequestExecutor.Execute(command, _session.Context); return(command.Result); }
public void CountBusinessesByCategory5KmAroundFactual() { // Arrange var query = new FacetQuery("category") .Within(new Circle(34.06018, -118.41835, 5000)); // Assert AreEqualQueries("select=category&geo={\"$circle\":{\"$center\":[34.06018,-118.41835],\"$meters\":5000}}", query); }
/// <inheritdoc /> public Lazy <Task <FacetedQueryResult> > GetFacetsLazyAsync(List <Facet> facets, int facetStart, int?facetPageSize, CancellationToken token = default(CancellationToken)) { var q = GetIndexQuery(); var query = FacetQuery.Create(q, null, facets, facetStart, facetPageSize, Conventions); var lazyFacetsOperation = new LazyFacetsOperation(Conventions, query); return(((AsyncDocumentSession)TheSession).AddLazyOperation <FacetedQueryResult>(lazyFacetsOperation, null, token)); }
/// <inheritdoc /> public Lazy <FacetedQueryResult> GetFacetsLazy(List <Facet> facets, int facetStart, int?facetPageSize) { var q = GetIndexQuery(); var query = FacetQuery.Create(q, null, facets, facetStart, facetPageSize, Conventions); var lazyFacetsOperation = new LazyFacetsOperation(Conventions, query); return(((DocumentSession)TheSession).AddLazyOperation(lazyFacetsOperation, (Action <FacetedQueryResult>)null)); }
public void CountBusinessesByCategory5KmAroundFactual() { //Arrange var query = new FacetQuery("category") .Within(new Circle(34.06018, -118.41835, 5000)); //Assert AreEqualQueries("select=category&geo={\"$circle\":{\"$center\":[34.06018,-118.41835],\"$meters\":5000}}", query); }
public GetFacetsOperation(FacetQuery query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } _query = query; }
public virtual Task <FacetedQueryResult> GetFacetsAsync(string facetSetupDoc, int start, int?pageSize, CancellationToken token = default(CancellationToken)) { var q = GetIndexQuery(); var query = FacetQuery.Create(indexName, q, facetSetupDoc, null, start, pageSize); // TODO iftah return(null); //return asyncDatabaseCommands.GetFacetsAsync(query, token); }
public virtual FacetedQueryResult GetFacets(string facetSetupDoc, int start, int?pageSize) { var q = GetIndexQuery(false); var query = FacetQuery.Create(indexName, q, facetSetupDoc, null, start, pageSize); // TODO iftah return(null); //return databaseCommands.GetFacets(query); }
public GetFacetsCommand(DocumentConventions conventions, JsonOperationContext context, FacetQuery query) { _conventions = conventions ?? throw new ArgumentNullException(nameof(conventions)); _query = query ?? throw new ArgumentNullException(nameof(query)); if (_query.WaitForNonStaleResultsTimeout.HasValue && _query.WaitForNonStaleResultsTimeout != TimeSpan.MaxValue) { Timeout = _query.WaitForNonStaleResultsTimeout.Value.Add(TimeSpan.FromSeconds(10)); // giving the server an opportunity to finish the response } }
public virtual async Task <FacetedQueryResult> GetFacetsAsync(List <Facet> facets, int start, int?pageSize, CancellationToken token = default(CancellationToken)) { var q = GetIndexQuery(); var query = FacetQuery.Create(q, null, facets, start, pageSize, Session.Conventions); var command = new GetFacetsCommand(_session.Conventions, _session.Context, query); await _session.RequestExecutor.ExecuteAsync(command, _session.Context, token).ConfigureAwait(false); return(command.Result); }
public void CountStarbucksInTheUSByCityAndState() { // Arrange var query = new FacetQuery("locality", "region") .Search("starbucks") .Field("country").Equal("US"); // Assert AreEqualQueries("select=locality,region&q=starbucks&filters={\"country\":{\"$eq\":\"US\"}}", query); }
/// <inheritdoc /> public async Task <FacetedQueryResult> GetFacetsAsync(string facetSetupDoc, int facetStart, int?facetPageSize, CancellationToken token = default(CancellationToken)) { var q = GetIndexQuery(); var query = FacetQuery.Create(q, facetSetupDoc, null, facetStart, facetPageSize, Conventions); var command = new GetFacetsCommand(Conventions, TheSession.Context, query); await TheSession.RequestExecutor.ExecuteAsync(command, TheSession.Context, token).ConfigureAwait(false); return(command.Result); }
public void CountStarbucksInTheUSByCityAndState() { //Arrange var query = new FacetQuery("locality", "region") .Search("starbucks") .Field("country").Equal("US"); //Assert AreEqualQueries("select=locality,region&q=starbucks&filters={\"country\":{\"$eq\":\"US\"}}", query); }
/// <inheritdoc /> public FacetedQueryResult GetFacets(List <Facet> facets, int facetStart, int?facetPageSize) { var q = GetIndexQuery(); var query = FacetQuery.Create(q, null, facets, facetStart, facetPageSize, Conventions); var command = new GetFacetsCommand(Conventions, TheSession.Context, query); TheSession.RequestExecutor.Execute(command, TheSession.Context); return(command.Result); }
private async Task FacetedQuery(DocumentsOperationContext context, string indexName, OperationCancelToken token) { var query = FacetQuery.Parse(HttpContext.Request.Query, GetStart(), GetPageSize(Database.Configuration.Core.MaxPageSize)); var existingResultEtag = GetLongFromHeaders("If-None-Match"); long?facetsEtag = null; if (query.FacetSetupDoc == null) { KeyValuePair <List <Facet>, long> facets; if (HttpContext.Request.Method == HttpMethod.Post.Method) { var json = await context.ParseArrayToMemoryAsync(RequestBodyStream(), "facets", BlittableJsonDocumentBuilder.UsageMode.None); facets = FacetedQueryParser.ParseFromJson(json); } else if (HttpContext.Request.Method == HttpMethod.Get.Method) { var f = GetStringQueryString("facets"); if (string.IsNullOrWhiteSpace(f)) { throw new InvalidOperationException("One of the required parameters (facetDoc or facets) was not specified."); } facets = await FacetedQueryParser.ParseFromStringAsync(f, context); } else { throw new NotSupportedException($"Unsupported HTTP method '{HttpContext.Request.Method}' for Faceted Query."); } facetsEtag = facets.Value; query.Facets = facets.Key; } var runner = new QueryRunner(Database, context); var result = await runner.ExecuteFacetedQuery(indexName, query, facetsEtag, existingResultEtag, token); if (result.NotModified) { HttpContext.Response.StatusCode = 304; return; } HttpContext.Response.Headers[Constants.MetadataEtagField] = result.ResultEtag.ToInvariantString(); using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteFacetedQueryResult(context, result); } }
public void TestFacetGeo() { //Arrange var facet = new FacetQuery("category_labels").Within(new Circle(Latitude, Longitude, Meters)); //Act var response = Factual.Fetch("global", facet); //Assert AssertReceivedOkResponse(response); dynamic json = JsonConvert.DeserializeObject(response); Assert.IsTrue(((ICollection <JToken>)json.response.data.category_labels).Count > 0); }
public override FacetedQueryResult GetFacets(List <Facet> facets, int start, int?pageSize) { var indexQuery = GetIndexQuery(false); var results = shardStrategy.ShardAccessStrategy.Apply(shardDbCommands, new ShardRequestData { IndexName = IndexQueried, EntityType = typeof(T), Query = indexQuery }, (commands, i) => { var query = FacetQuery.Create(IndexQueried, indexQuery, null, facets, start, pageSize); return(commands.GetFacets(query)); }); return(MergeFacets(results)); }
public override async Task <FacetedQueryResult> GetFacetsAsync(string facetSetupDoc, int start, int?pageSize, CancellationToken token = default(CancellationToken)) { var indexQuery = GetIndexQuery(true); var results = await shardStrategy.ShardAccessStrategy.ApplyAsync(asyncShardDbCommands, new ShardRequestData { IndexName = AsyncIndexQueried, EntityType = typeof(T), Query = indexQuery }, (commands, i) => { var query = FacetQuery.Create(AsyncIndexQueried, indexQuery, facetSetupDoc, null, start, pageSize); return(commands.GetFacetsAsync(query, token)); }).ConfigureAwait(false); return(MergeFacets(results)); }
public void TestFacet() { //Arrange var facet = new FacetQuery("region", "locality") .Search("Starbucks") .MaxValuesPerFacet(20) .MinCountPerFacetValue(100) .IncludeRowCount(); //Act var response = Factual.Fetch("global", facet); //Assert AssertReceivedOkResponse(response); dynamic json = JsonConvert.DeserializeObject(response); Assert.IsTrue(((int)json.response.total_row_count) > 0); }
public HowToPerformMultiFacetedSearch() { using (var store = new DocumentStore()) { using (var session = store.OpenSession()) { #region multi_facet_2 FacetQuery facetQuery1 = session.Query <Camera>() .ToFacetQuery("facets/CameraFacets1"); FacetQuery facetQuery2 = session.Query <Camera>() .ToFacetQuery("facets/CameraFacets2"); FacetResults[] results = session .Advanced .MultiFacetedSearch(facetQuery1, facetQuery2); FacetResults facetResults1 = results[0]; FacetResults facetResults2 = results[1]; #endregion } } }
public void TestFacetFilter() { //Arrange var facet = new FacetQuery("locality") .Field("region").In("MA", "VT", "NH"); facet.And ( facet.Or ( facet.Field("name").BeginsWith("Coffee"), facet.Field("name").BeginsWith("Star") ), facet.Field("locality").BeginsWith("w") ); //Act var response = Factual.Fetch("global", facet); //Assert AssertReceivedOkResponse(response); dynamic json = JsonConvert.DeserializeObject(response); Assert.IsTrue(((ICollection <JToken>)json.response.data.locality).Count > 0); }
private static unsafe uint CalculateQueryFieldsHash(FacetQuery query, JsonOperationContext context) { int size = 0; // ReSharper disable once LoopCanBeConvertedToQuery foreach (var s in query.FieldsToFetch) { size += s.Length; } var buffer = context.GetNativeTempBuffer(size * sizeof(char)); var destChars = (char *)buffer; var position = 0; foreach (var field in query.FieldsToFetch) { for (var i = 0; i < field.Length; i++) { destChars[position++] = field[i]; } } return(Hashing.XXHash32.Calculate(buffer, size)); }
public override Task <FacetedQueryResult> FacetedQuery(FacetQuery query, long facetSetupEtag, DocumentsOperationContext documentsContext, OperationCancelToken token) { throw new NotSupportedException($"Index with id {IndexId} is in-memory implementation of a faulty index", _e); }
public FacetedQueryResult GetFacets(FacetQuery query) { return(AsyncHelpers.RunSync(() => asyncServerClient.GetFacetsAsync(query))); }
public void TestFacetGeo() { //Arrange var facet = new FacetQuery("category").Within(new Circle(Latitude, Longitude, Meters)); //Act var response = Factual.Fetch("global", facet); //Assert AssertReceivedOkResponse(response); dynamic json = JsonConvert.DeserializeObject(response); Assert.IsTrue(((ICollection<JToken>)json.response.data.category).Count > 0); }
public void TestFacetFilter() { //Arrange var facet = new FacetQuery("locality") .Field("region").In("MA", "VT", "NH"); facet.And ( facet.Or ( facet.Field("name").BeginsWith("Coffee"), facet.Field("name").BeginsWith("Star") ), facet.Field("locality").BeginsWith("w") ); //Act var response = Factual.Fetch("global", facet); //Assert AssertReceivedOkResponse(response); dynamic json = JsonConvert.DeserializeObject(response); Assert.IsTrue(((ICollection<JToken>)json.response.data.locality).Count > 0); }
public static void WriteFacetQuery(this BlittableJsonTextWriter writer, JsonOperationContext context, FacetQuery query) { var djv = (DynamicJsonValue)TypeConverter.ToBlittableSupportedType(query); var json = context.ReadObject(djv, "facet-query"); writer.WriteObject(json); }
public static void WriteFacetQuery(this BlittableJsonTextWriter writer, DocumentConventions conventions, JsonOperationContext context, FacetQuery query) { writer.WriteObject(EntityToBlittable.ConvertEntityToBlittable(query, conventions, context)); }