예제 #1
0
        public override SolrSearchResults Search(SearchQuery query, List <KeyValuePair <string, string> > facets, List <FacetRange> facet_ranges)
        {
            // string solr_term = (ids.Count > 0) ? String.Format("{0}:^", _solrIdField) : makeSolrTerm(term, ids);
            string solr_term = makeSolrTerm(query.Term, query.IDs);

            var solr    = ServiceLocator.Current.GetInstance <ISolrOperations <InqItemXml> >();
            var results = solr.Query(new SolrQuery(solr_term), new QueryOptions {
                Rows = query.Rows, Start = query.RowStart
            });

            var inqItems = new List <IInqItem>(results);
            // old: addImageMetaData(ref inqItems);

            var sr = new SolrSearchResults(inqItems)
            {
                Collapsing     = results.Collapsing,
                FacetDates     = results.FacetDates,
                FacetFields    = results.FacetFields,
                FacetQueries   = results.FacetQueries,
                Header         = results.Header,
                Highlights     = results.Highlights,
                MaxScore       = results.MaxScore,
                NumFound       = results.NumFound,
                SpellChecking  = results.SpellChecking,
                Stats          = results.Stats,
                SimilarResults = results.SimilarResults.ToDictionary(kvp => kvp.Key, kvp => new List <IInqItem>(kvp.Value))
            };

            return(sr);
        }
예제 #2
0
        protected SolrSearchResults makeSolrSearchResults(SolrQueryResults <InqItemBodIIIF> results, List <KeyValuePair <string, string> > facets, List <FacetRange> facet_ranges)
        //protected SolrSearchResults makeSolrSearchResults(SolrQueryResults<InqItemArmNode> results, List<KeyValuePair<string, string>> facets, List<FacetRange> facet_ranges)
        // protected SolrSearchResults makeSolrSearchResults(SolrQueryResults<InqItemBase> results, List<KeyValuePair<string, string>> facets, List<FacetRange> facet_ranges)
        {
            var inqItems = new List <IInqItem>(results);
            // old: addImageMetaData(ref inqItems);

            // need to replace the possibly very un-user-friendly database facet field names with more user friendly ones
            var facets_display = new Dictionary <string, ICollection <KeyValuePair <string, int> > >();

            foreach (KeyValuePair <string, ICollection <KeyValuePair <string, int> > > kvp in results.FacetFields)
            {
                foreach (KeyValuePair <string, string> f in facets)
                {
                    if (kvp.Key == f.Key)
                    {
                        facets_display.Add(String.Format("{0}^{1}", f.Key, f.Value), kvp.Value);
                        break;
                    }
                }
            }

            // same for facet ranges
            var facet_ranges_display = new Dictionary <string, int>();

            foreach (KeyValuePair <string, int> kvp in results.FacetQueries)
            {
                foreach (FacetRange fr in facet_ranges)
                {
                    // in format "DateEndYear:[1901 TO *]"
                    var s = kvp.Key.Split(new[] { ":[" }, StringSplitOptions.RemoveEmptyEntries);

                    if (s[0] == fr.Field)
                    {
                        facet_ranges_display.Add(String.Format("{0}^{1}{2}{3}", fr.Field, fr.DisplayName, ":[", s[1]), kvp.Value);
                        break;
                    }
                }
            }

            // hyperlink links in fields as appropriate
            if ((inqItems.Count > 0) && (HyperlinkFields.Count > 0))
            {
                System.Type inq_t = inqItems[0].GetType();

                foreach (KeyValuePair <string, bool> field in HyperlinkFields)
                {
                    var p = inq_t.GetProperty(field.Key);
                    if (p != null)
                    {
                        foreach (IInqItem item in inqItems)
                        {
                            /* p.SetValue(item, "http://www.cnn.com/ This is a test http://www.bbc.co.uk , and this is another link http://moo.com/ this is some more text www.moo.com , ultimate link http://moo.com/ and more text.", null);
                             * if (p.Name == "Description")
                             *  p.SetValue(item, "^start|http://www.bbc.co.uk^ This is a test. This sentence has a ^hyper link 1 title|http://www.bbc.co.uk^. This sentence does not. This sentence does ^|http://www.bbc.co.uk^, this is the final link ^final link|http://www.bbc.co.uk^ and that's it. ^|http://www.bbc.co.uk^", null);
                             */
                            string hyp_text;
                            var    text = (string)p.GetValue(item, null);

                            if (field.Value)
                            {
                                hyp_text = MarkupCodedHyperlinks(text);
                            }
                            else
                            {
                                hyp_text = MarkupNakedHyperlinks(text);
                            }

                            p.SetValue(item, hyp_text, null);
                        }
                    }
                }
            }

            var sr = new SolrSearchResults(inqItems)
            {
                Collapsing     = results.Collapsing,
                FacetDates     = results.FacetDates,
                Header         = results.Header,
                Highlights     = results.Highlights,
                MaxScore       = results.MaxScore,
                NumFound       = results.NumFound,
                SpellChecking  = results.SpellChecking,
                Stats          = results.Stats,
                SimilarResults = results.SimilarResults.ToDictionary(kvp => kvp.Key, kvp => new List <IInqItem>(kvp.Value)),
                FacetFields    = facets_display,
                FacetQueries   = facet_ranges_display
            };

            return(sr);
        }