private IEnumerable <SearchEngineResult> PerformQuery(ICollection <SearchEngineResult> list, Query queryOrig, int max) { //Query isValidPlaceQuery = new TermQuery(new Term(ItemNotUserDeleted, true.ToString())); var query = new BooleanQuery(); query.Add(queryOrig, BooleanClause.Occur.MUST); //query.Add(isPublishedQuery, BooleanClause.Occur.MUST); IndexSearcher searcher = Searcher; TopDocs hits = searcher.Search(query, max); int length = hits.scoreDocs.Length; int resultsAdded = 0; float minScore = _settings.MinimumScore; float scoreNorm = 1.0f / hits.GetMaxScore(); for (int i = 0; i < length && resultsAdded < max; i++) { float score = hits.scoreDocs[i].score * scoreNorm; SearchEngineResult result = CreateSearchResult(searcher.Doc(hits.scoreDocs[i].doc), score); //if (idToFilter != result.EntryId && result.Score > minScore) //{ list.Add(result); resultsAdded++; //} } return(list); }
protected virtual SearchEngineResult CreateSearchResult(Document doc, float score) { var result = new SearchEngineResult { ID = doc.Get("Key"), Title = doc.Get("Title"), Url = doc.Get("Url"), TypeID = byte.Parse(doc.Get("Type")), Excerpt = doc.Get("Excerpt"), Score = score }; //-- This is out here incase later we accommodate areas that belong to more than one country byte countryID = 0; if (byte.TryParse(doc.Get("Country"), out countryID)) { result.CountryID = countryID; result.Flag = cf.Caching.AppLookups.CountryFlag(result.CountryID); } return(result); }
//[WebGet(UriTemplate = "refresh")] //public Message RefreshIndex() //{ // if (!CfIdentity.IsAuthenticated) // { // return ReturnAsJson(new List<object>() { new { Excerpt = "Refresh Failed - Not authenticated", Score = "0" } }); // } // return RefreshIndexInternal(); //} /// <summary> /// So we can control authorization to refresh index /// </summary> //private Message RefreshIndexInternal() //{ // try // { // AppLookups.RefreshCacheIndex(); // var siteSearchEngine = Global.SiteSearchEngine; // siteSearchEngine.Dispose(); // siteSearchEngine = null; // siteSearchEngine = new LuceneCfSearchEngineService(); // new LuceneCfIndexingService(siteSearchEngine).RebuildIndex(); // var successResult = new { Title = "Success", Score = float.Parse(siteSearchEngine.GetTotalIndexedEntryCount().ToString()) }; // return ReturnAsJson(new List<object>() { successResult }); // } // catch (Exception ex) // { // CfTracer.Error(ex); // var failedResult = new { Title = "Failed", Excerpt = ex.Message }; // return ReturnAsJson(new List<object>() { failedResult }); // } //} private Message HandelSearchException(Exception ex) { CfTracer.Error(ex); //RefreshIndex(); var rebuildingResult = new SearchEngineResult() { Title = "Search service refreshing", CountryID = 10, Excerpt = "Try search again in a few seconds", Url = "#" }; return ReturnAsJson(new List<SearchEngineResult>() { rebuildingResult }); }
protected virtual SearchEngineResult CreateSearchResult(Document doc, float score) { var result = new SearchEngineResult { ID = doc.Get("Key"), Title = doc.Get("Title"), Url = doc.Get("Url"), TypeID = byte.Parse(doc.Get("Type")), Excerpt = doc.Get("Excerpt"), Score = score }; //-- This is out here incase later we accommodate areas that belong to more than one country byte countryID = 0; if (byte.TryParse(doc.Get("Country"), out countryID)) { result.CountryID = countryID; result.Flag = cf.Caching.AppLookups.CountryFlag(result.CountryID); } return result; }