protected void addImageMetaData(ref SolrSearchResults solr_results) { var ser = new JavaScriptSerializer(); //if (String.IsNullOrEmpty(base_uri) == false) // add in image metadata, not required for Solr indexing //{ foreach (IInqItem k in solr_results.Results) { if (k.GetType().IsSubclassOf(typeof(InqItemIIIFBase))) { // new logic here for IIIF images // k.ImageMetadata = new ImageMetadata { Identifier = file, Imagefile = file, Width = d[0], Height = d[1], DwtLevels = 0, Levels = 0, CompositingLayerCount = 0 }; } else { if (k.File != null) { if (!String.IsNullOrEmpty((ImageHelper.Jpeg2000NamespaceReplace)) && k.File.Contains(ImageHelper.Jpeg2000NamespaceReplace)) // see Jpeg2000NamespaceReplace for explanation { k.File = k.File.Replace(ImageHelper.Jpeg2000NamespaceReplace, ImageHelper.Jpeg2000Namespace); } if ((!JP2HelperBase.IsAudioOrVideo(k.File)) && (!String.IsNullOrEmpty(ImageHelper.ImageFilenameAppend))) { k.File = string.Format("{0}{1}", k.File, ImageHelper.ImageFilenameAppend); } if (k.File.Contains(ImageHelper.Jpeg2000Namespace)) // file is a jpeg2000 image { var md_str = _IJP2Helper.GetJpeg2000Metadata(k.File, false); md_str = md_str.Replace(@"\", @"\\"); var md = ser.Deserialize <ImageMetadata>(md_str); k.ImageMetadata = md; } else { var file = k.File; // most importantly we need the width and height of non-jpeg2000 images so can re-size them to thumbnails whilst retaining the aspect ratio var d = ImageHelper.GetImageDimensions(file); if ((file != null) && (file.Contains("'"))) // apostrophes in filenames, good at breaking JSON { file = file.Replace("'", @"\'"); } k.ImageMetadata = new ImageMetadata { Identifier = file, Imagefile = file, Width = d[0], Height = d[1], DwtLevels = 0, Levels = 0, CompositingLayerCount = 0 }; // k.ImageMetadata = ser.Deserialize<Jpeg2000Metadata>(String.Format("{{ 'identifier': '{0}', 'imagefile': '{0}', 'width': '{1}', 'height': '{2}', 'dwtLevels': '0', 'levels': '0', 'compositingLayerCount': '0' }}", file, d[0], d[1])); } } } } //} //else // throw new Exception("SolrRespository.addImageMetaData(): base_uri parameter empty"); // return r_list; }
public void SolrQueryBuilder() { var qb = container.Resolve<ISolrQueryBuilder>(); qb.Query = new Query(); var parameters = new List<QueryParameter> {new QueryParameter("price", "[500 TO 1000]")}; var qp = new QueryParameterCollection("q", parameters); qb.Query.AddQueryParameters(qp, ParameterJoin.AND); var results = new SolrSearchResults(qb); Console.WriteLine(results.TotalResults); }
public void Query() { var solrSearcher = new SolrSearcher("http://localhost:8983/solr/", Mode.ReadWrite); ISolrSearcher searcher = new SolrSearcherAdapter(solrSearcher); var updater = new SolrUpdater(solrSearcher); ISolrUpdater s = new SolrUpdaterAdapter(updater); ISolrQueryBuilder qb = new SolrQueryBuilder(searcher); qb.Query = new Query(); var parameters = new List<QueryParameter>(); parameters.Add(new QueryParameter("price", "[500 TO 1000]")); var qp = new QueryParameterCollection("q", parameters); qb.Query.AddQueryParameters(qp, ParameterJoin.AND); var results = new SolrSearchResults(qb); Console.WriteLine(results.TotalResults); }
public override TResult Execute <TResult>(SolrCompositeQuery compositeQuery) { if (EnumerableLinq.ShouldExecuteEnumerableLinqQuery(compositeQuery)) { return(EnumerableLinq.ExecuteEnumerableLinqQuery <TResult>(compositeQuery)); } if (typeof(TResult).IsGenericType && typeof(TResult).GetGenericTypeDefinition() == typeof(SearchResults <>)) { var resultType = typeof(TResult).GetGenericArguments()[0]; var solrQueryResults = this.Execute(compositeQuery, resultType); var type = typeof(SolrSearchResults <>).MakeGenericType(resultType); var methodInfo = this.GetType() .GetMethod("ApplyScalarMethods", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(typeof(TResult), resultType); var selectMethod = GetSelectMethod(compositeQuery); var instance = ReflectionUtility.CreateInstance(type, (object)this._context, (object)solrQueryResults, (object)selectMethod, (object)compositeQuery.ExecutionContexts, (object)compositeQuery.VirtualFieldProcessors); return((TResult)methodInfo.Invoke(this, new object[3] { compositeQuery, instance, solrQueryResults })); } compositeQuery.Methods.Add(new GetFacetsMethod()); var solrQueryResults1 = this.Execute(compositeQuery, typeof(TResult)); var selectMethod1 = GetSelectMethod(compositeQuery); var processedResults = new SolrSearchResults <TResult>(this._context, solrQueryResults1, selectMethod1, compositeQuery.ExecutionContexts, compositeQuery.VirtualFieldProcessors); return(this.ApplyScalarMethods <TResult, TResult>(compositeQuery, processedResults, solrQueryResults1)); }
private TResult ApplyScalarMethods <TResult, TDocument>(SolrCompositeQuery compositeQuery, SolrSearchResults <TDocument> processedResults, SolrQueryResults <Dictionary <string, object> > results) { var queryMethod = compositeQuery.Methods.First(); object obj; switch (queryMethod.MethodType) { case QueryMethodType.All: obj = true; break; case QueryMethodType.Any: obj = processedResults.Any() ? 1 : 0; break; case QueryMethodType.Count: obj = !compositeQuery.Methods.Any(i => { if (i.MethodType != QueryMethodType.Take) { return(i.MethodType == QueryMethodType.Skip); } return(true); }) ? processedResults.Count() : (object)results.Count(); break; case QueryMethodType.ElementAt: obj = !((ElementAtMethod)queryMethod).AllowDefaultValue ? processedResults.ElementAt(((ElementAtMethod)queryMethod).Index) : (object)processedResults.ElementAtOrDefault(((ElementAtMethod)queryMethod).Index); break; case QueryMethodType.First: obj = !((FirstMethod)queryMethod).AllowDefaultValue ? processedResults.First() : (object)processedResults.FirstOrDefault(); break; case QueryMethodType.Last: obj = !((LastMethod)queryMethod).AllowDefaultValue ? processedResults.Last() : (object)processedResults.LastOrDefault(); break; case QueryMethodType.Single: obj = !((SingleMethod)queryMethod).AllowDefaultValue ? processedResults.Single() : (object)processedResults.SingleOrDefault(); break; case QueryMethodType.GetResults: var searchHits = processedResults.GetSearchHits(); var facetResults = this.FormatFacetResults(processedResults.GetFacets(), compositeQuery.FacetQueries); obj = ReflectionUtility.CreateInstance(typeof(TResult), (object)searchHits, (object)processedResults.NumberFound, (object)facetResults); break; case QueryMethodType.GetFacets: obj = this.FormatFacetResults(processedResults.GetFacets(), compositeQuery.FacetQueries); break; default: throw new InvalidOperationException("Invalid query method"); } return((TResult)Convert.ChangeType(obj, typeof(TResult))); }
public SearchAjaxViewModel(SolrSearchResults searchResults) { SearchResults = searchResults; }