Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jin Botol 134 posts 287 karma points
    Jul 31, 2018 @ 09:50
    Jin Botol
    0

    ExamineSearch cache?

    Hi,

    I'm new in Umbraco and have a problem with this existing site.

    In the previous version 7.5.6 the page is working perfectly, showing all products but after I update it to 7.11.1, the page is not working anymore, the results is still the same, even if I add/delete products.

    any ideas for this?

    thanks

    Jin

  • Jin Botol 134 posts 287 karma points
    Jul 31, 2018 @ 09:54
    Jin Botol
    0

    My Code :

    var machineName = Environment.MachineName;
    string indexPath = string.Format($"~/App_Data/TEMP/ExamineIndexes/{machineName}/External/Index");
    var indexDirectory = FSDirectory.Open(new DirectoryInfo(HttpContext.Current.Server.MapPath(indexPath)));
    var searcher = new IndexSearcher(indexDirectory, true);
    var masterQuery = new BooleanQuery();
    
    var searchTimer = new Stopwatch();
    searchTimer.Start();
    
    TopDocs resp = searcher.Search(masterQuery, null, searcher.MaxDoc());
    Debug.WriteLine(resp.TotalHits); // results are still the same even if I add/delete products,
    
    searchTimer.Stop();
    
  • Harry Spyrou 212 posts 604 karma points
    Jul 31, 2018 @ 11:06
    Harry Spyrou
    0

    Have you tried using 'republish entire site' under the content tab in Umbraco?

  • Jin Botol 134 posts 287 karma points
    Jul 31, 2018 @ 13:30
    Jin Botol
    0

    Yes, I've already try that but no luck :(

    Jin

  • Jonny Flanagan 34 posts 163 karma points
    Jul 31, 2018 @ 11:39
    Jonny Flanagan
    0

    Hi Jin, If a republish doesnt work try to rebuild your Index.

    Go to Developer Section > Examine Management > Indexers > {Select your Index} > Index info & tools > Rebuild Index

    Jonny

  • Jin Botol 134 posts 287 karma points
    Aug 01, 2018 @ 01:58
    Jin Botol
    0

    Hi Jonny,

    There is no Examine Management in my Developer Section

    Jin

  • Jin Botol 134 posts 287 karma points
    Aug 02, 2018 @ 09:20
    Jin Botol
    0

    Any ideas about this?

    I badly need help, after Updating to latest version of Umbraco which is 7.11.1, the old codes is not properly working.

    Jin

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 02, 2018 @ 09:31
    Ismail Mayat
    0

    Jin,

    You should have examine management in developer section. If not then take a look at your dashboard config file see config\dashboard.config

     <section alias="Examine">
    <areas>
      <area>developer</area>
    </areas>
    

    something like this, apologies its stripping xml out in editor but you should have this. if not then add it and refresh the backoffice you will then be able to see how many documents etc you have in your index.

  • Jin Botol 134 posts 287 karma points
    Aug 03, 2018 @ 01:53
    Jin Botol
    0

    Hi Ismail,

    Thanks for your response.

    Sorry, I am very newbie in Umbraco and this project is existing with the first developer, and now I am facing this problem after upgrade.

    This is what I found in config/dashboard.config

      <section alias="StartupDeveloperDashboardSection">
        <areas>
          <area>developer</area>
        </areas>
        <tab caption="Get Started">
          <control showOnce="true" addPanel="true" panelCaption="">
            views/dashboard/developer/developerdashboardvideos.html
          </control>
        </tab>
        <tab caption="Examine Management">
          <control>
            views/dashboard/developer/examinemanagement.html
          </control>
        </tab>
      </section>
    

    Jin

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 03, 2018 @ 08:13
    Ismail Mayat
    0

    Looking at your config you should see examine mangement section. You need to click on developer section in umbraco this will take you to examine management section see attached image

    enter image description here

    Also in your code you are using raw lucene maybe it is becuase you are just starting with Umbraco, however Umbraco has Examine this is an abstraction around lucene.net and it has fluent api you can use to index and search. See https://our.umbraco.com/Documentation/Reference/Searching/Examine/ for more information.

  • Jin Botol 134 posts 287 karma points
    Aug 08, 2018 @ 02:44
    Jin Botol
    0

    Hi,

    Sorry I was unable to reply,

    I already Rebuild but still no luck,

    Is this bugs cause the Umbraco Updates? Because when I tried @Model.Content.Children.Count() it display 53 the number of product published, but when I use the current code, it display 79 which is the old one.

    This is the whole code :

    public List<Product> Complex(SearchViewModel model)
            {
                var PromotionLogoIs = "promotion";
                string hoverInfo = null;
                var hasPromotion = false;
    
                var allTimer = new Stopwatch();
                allTimer.Start();
                var context = new BackendContext();
                if (model == null)
                {
                    throw new NullReferenceException("The search model is null");
                }
    
                var machineName = Environment.MachineName;
                string indexPath = string.Format($"~/App_Data/TEMP/ExamineIndexes/{machineName}/External/Index");
    
                var indexDirectory = FSDirectory.Open(new DirectoryInfo(HttpContext.Current.Server.MapPath(indexPath)));
    
                var searcher = new IndexSearcher(indexDirectory, true);
                var masterQuery = new BooleanQuery();
    
                var m = Membership.GetUser();
                List<KeyValuePair<int, string>> favourites = null;
                if (m != null)
                {
                    favourites = context.Favourites.GetFavouritesByMember(m.ProviderUserKey.ToString()).Select(x => new KeyValuePair<int, string>(x.Id, x.ContentId.ToString())).ToList();
                }
                var queryTimer = new Stopwatch();
                queryTimer.Start();
    
                #region Spatial Query
                //if no result can be found just get sydney instead
                var location = new Logic.Models.Location()
                {
                    Latitude = -33.8703813f,
                    Longitude = 151.2068874f
                };
    
                //spatial calculations are done in miles. 'murica!
                var kmsToMiles = 0.621371192;
                var radius = GetMaxDistance() * kmsToMiles;
    
                //i am declaring these up here because i need the distFilter accessible when ordering the results - only when a location is searched
                //they dont have constructors with no args so even though this defaults to sydney these values will never be used unless the searched value is not found in database
                var builder = new CartesianPolyFilterBuilder("LocationTierPrefix_");
                var boundingArea = builder.GetBoundingArea(location.Latitude, location.Longitude, radius);
    
                var distFilter = new LatLongDistanceFilter(boundingArea,
                        radius,
                        location.Latitude,
                        location.Longitude,
                        "codedlat",
                        "codedlng");
    
    
                if (!string.IsNullOrEmpty(model.Location))
                {
                    //try to geocode the search query based on region, postcode or suburb stored in the database
                    var searchedLocation = context.Locations.GetLocation(model.Location);
    
                    if (searchedLocation != null)
                    {
                        location = searchedLocation;
                    }
    
                    builder = new CartesianPolyFilterBuilder("LocationTierPrefix_");
                    boundingArea = builder.GetBoundingArea(location.Latitude, location.Longitude, radius);
    
                    distFilter = new LatLongDistanceFilter(boundingArea,
                            radius,
                            location.Latitude,
                            location.Longitude,
                            "codedlat",
                            "codedlng");
    
                    var subQuery = new BooleanQuery();
                    subQuery.Add(new ConstantScoreQuery(distFilter), BooleanClause.Occur.SHOULD);
    
    
                    for (int i = 0; i < 10; i++)
                    {
                        subQuery.Add(new ConstantScoreQuery(new LatLongDistanceFilter(boundingArea,
                                radius,
                                location.Latitude,
                                location.Longitude,
                                $"codedlat{i}",
                                $"codedlng{i}")), BooleanClause.Occur.SHOULD);
                    }
    
                    masterQuery.Add(subQuery, BooleanClause.Occur.MUST);
                }
    
                #endregion
    
                #region Range Calculations
    
                //price calculations
                long minPrice = 0;
                long maxPrice = Int32.MaxValue;
                var min = 0;
                var max = Int32.MaxValue;
    
                if (model.MinPrice != 0)
                {
                    minPrice = model.MinPrice;
                }
                if (model.MaxPrice != 0)
                {
                    maxPrice = model.MaxPrice;
                }
    
                var priceQuery = NumericRangeQuery.NewLongRange("longPrice", minPrice, maxPrice, true, true);
                masterQuery.Add(priceQuery, BooleanClause.Occur.MUST);
    
                var widthQuery = ConstructIntRangeQuery("intBlockW", 0, model.MinWidth, model.MaxWidth);
                masterQuery.Add(widthQuery, BooleanClause.Occur.MUST);
    
                var lengthQuery = ConstructIntRangeQuery("intBlockL", 0, model.MinLength, model.MaxLength);
                masterQuery.Add(lengthQuery, BooleanClause.Occur.MUST);
    
                var sizeQuery = ConstructIntRangeQuery("intHouseSize", 0, model.MinSize, model.MaxSize);
                masterQuery.Add(sizeQuery, BooleanClause.Occur.MUST);
    
                if (model.Bed.Contains("+"))
                {
                    var beds = Convert.ToInt32(model.Bed.Replace("+", string.Empty));
                    var bedQuery = ConstructIntRangeQuery("intBeds", 0, beds, 0);
                    masterQuery.Add(bedQuery, BooleanClause.Occur.MUST);
                }
                else
                {
                    var bed = string.IsNullOrEmpty(model.Bed) ? 0 : Convert.ToInt32(model.Bed);
                    var bedQuery = ConstructIntRangeQuery("intBeds", 0, bed, bed);
                    masterQuery.Add(bedQuery, BooleanClause.Occur.MUST);
                }
    
                if (model.Bath.Contains("+"))
                {
                    var baths = Convert.ToInt32(model.Bath.Replace("+", string.Empty));
                    var bathQuery = ConstructIntRangeQuery("intBaths", 0, baths, 0);
                    masterQuery.Add(bathQuery, BooleanClause.Occur.MUST);
                }
                else
                {
                    var bath = string.IsNullOrEmpty(model.Bath) ? 0 : Convert.ToInt32(model.Bath);
                    var bathQuery = ConstructIntRangeQuery("intBaths", 0, bath, bath);
                    masterQuery.Add(bathQuery, BooleanClause.Occur.MUST);
                }
    
                if (model.Park.Contains("+"))
                {
                    var parks = Convert.ToInt32(model.Park.Replace("+", string.Empty));
                    var parkQuery = ConstructIntRangeQuery("intParks", 0, parks, 0);
                    masterQuery.Add(parkQuery, BooleanClause.Occur.MUST);
                }
                else
                {
                    var park = string.IsNullOrEmpty(model.Park) ? 0 : Convert.ToInt32(model.Park);
                    var parkQuery = ConstructIntRangeQuery("intParks", 0, park, park);
                    masterQuery.Add(parkQuery, BooleanClause.Occur.MUST);
                }
    
                #endregion
    
                #region Examine Raw Query
    
                var query = ConstructExamineQuery(model, favourites);
    
                masterQuery.Add(query, BooleanClause.Occur.MUST);
    
                #endregion
                queryTimer.Stop();
    
                var searchTimer = new Stopwatch();
                searchTimer.Start();
    
                TopDocs resp = searcher.Search(masterQuery, null, searcher.MaxDoc());
                Debug.WriteLine(resp.TotalHits);
    
                searchTimer.Stop();
    
                //parse results into nice friendly json
                var products = new List<Product>();
    
                var parseTimer = new Stopwatch();
                parseTimer.Start();
                foreach (var scoreDoc in resp.ScoreDocs)
                {
    
                    var distance = distFilter.GetDistance(scoreDoc.doc);
                    var document = searcher.Doc(scoreDoc.doc);
                    List<MetaLabel> productBuilderObj = new List<MetaLabel>();
    
                    string builderLogo = null;
    
                    if (!string.IsNullOrEmpty(document.Get("builder")))
                    {
                        var productBuilder = JsonConvert.DeserializeObject<List<MetaLabel>>(document.Get("builder"),
                            new JsonSerializerSettings()
                            {
                                Error = (sender, args) =>
                                {
                                    var currentError = args.ErrorContext.Error.Message;
                                    args.ErrorContext.Handled = true;
                                }
                            });
    
                        if (productBuilder != null)
                        {
                            productBuilderObj = productBuilder;
                            builderLogo = Umbraco.TypedMedia(Umbraco.TypedContent(productBuilder.First().Key).GetPropertyValue<string>("image")).Url;
                        }
                    }
    
                    var product = new Product()
                    {
                        Name = document.Get("title"),
                        ContentId = Convert.ToInt32(document.Get("id")),
                        Promotion = hasPromotion, //new, order,
                        Address = document.Get("address"),
                        Baths = Convert.ToInt32(document.Get("bathrooms")),
                        Beds = Convert.ToInt32(document.Get("bedrooms")),
                        Parks = Convert.ToInt32(document.Get("garage")),
                        Price = Convert.ToInt32(document.Get("price")),
                        HouseSqMeter = document.Get("houseSquareMeter"),
                        ImgLogo = document.Get("logo").UmbracoMediaPath().Resize(80, 80).Crop(true),
                        Images = document.Get("images").MediaUrlList().ResizeMany(329, 200).Crop(true),
                        ImageList = document.Get("images").MediaUrlList(),
                        Distance = distance,
                        Coverage = Convert.ToDouble(document.Get("distanceCoverage")) * kmsToMiles,
                        Relevance = scoreDoc.score,
                        Builder = builderLogo,
                        PromotionLogo = PromotionLogoIs,// Image
                        HoverInfo = hoverInfo,
                        ProductType = document.Get("productType"),
                        BuilderComp = productBuilderObj.First().Label
                    };
                    if (favourites == null)
                    {
                        product.Saved = false;
                    }
                    else
                    {
                        var saved = favourites.FirstOrDefault(x => x.Value == product.ContentId.ToString());
                        product.Saved = saved.Key != 0;
                        product.SavedId = (saved.Key != 0 ? saved.Key.ToString() : string.Empty);
                    }
    
                    product.Url = Umbraco.Content(product.ContentId).Url ?? string.Empty;
    
    
                    if (distance <= product.Coverage)
                        products.Add(product);
                }
                parseTimer.Stop();
    
                allTimer.Stop();
    
                var message = $"Total time: {allTimer.ElapsedMilliseconds}ms. " +
                              $"Query time: {queryTimer.ElapsedMilliseconds}ms. " +
                              $"Search time: {searchTimer.ElapsedMilliseconds}ms. " +
                              $"Parsing Time: {parseTimer.ElapsedMilliseconds}ms. " +
                              $"Query executed: {masterQuery}";
                HttpContext.Current.Response.AppendHeader("Search Timings", message);
                return products;
            }
    

    Here is the ConstructExamineQuery code :

    private Query ConstructExamineQuery(SearchViewModel model, List<KeyValuePair<int, string>> favourites)
    {
        var exSearch = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
        var exQuery = exSearch.CreateSearchCriteria();
    
        //construct examine query
        exQuery.NodeTypeAlias("Product").And().Field("productType", model.Type).And();
    
        if (!string.IsNullOrEmpty(model.Storeys))
        {
            exQuery.Field("storeys", model.Storeys).And();
        }
    
        //limit results to users favourites
        var m = Membership.GetUser();
        if (favourites != null && favourites.Any() && model.FavouritesOnly)
        {
            exQuery.GroupedOr(new string[] { "id" }, favourites.Select(x => x.Value).ToArray()).And();
        }
    
        var qp = new QueryParser("nodeTypeAlias", new StandardAnalyzer());
    
        var exQueryString = exQuery.ToString();
    
        //this is removing the extra text generated by examine to just grab out the lucene query
        var indexOfQuery = exQueryString.IndexOf("LuceneQuery:") + "LuceneQuery:".Length;
    
        var parsedString = exQueryString.Substring(indexOfQuery).TrimEnd('}');
    
        var query = new BooleanQuery();
        query.Add(qp.Parse(parsedString), BooleanClause.Occur.SHOULD);
    
        if (model.Params != null)
        {
            foreach (var item in model.Params.Where(x => x.Value.Any()))
            {
                var subQuery = new BooleanQuery();
    
                foreach (var value in item.Value)
                {
                    subQuery.Add(new TermQuery(new Term($"_{item.Key}", value)), BooleanClause.Occur.MUST);
                }
    
                query.Add(subQuery, BooleanClause.Occur.MUST);
            }
        }
    
        return query;
    }
    

    Hope it will help,

    Thanks

    Jin

  • Jin Botol 134 posts 287 karma points
    Aug 09, 2018 @ 06:12
    Jin Botol
    0

    Any help?

    thanks in advance

    Jin

  • Louis Ferreira 69 posts 266 karma points
    Aug 09, 2018 @ 07:06
    Louis Ferreira
    0

    Hi Jin,

    Let's try to get to the bottom of your problem.... first a few questions to get a better understanding of your project set up.

    1. You mentioned 'products', do you know if you have some package installed that manages products, like Merchello, Tea Commerce, etc?

    2. Are you logging into the backoffice as admin, or another (less privileged) user?

    3. Can you explain the process of how you did the 'upgrade'? Maybe you left out some critical files that the backoffice needs to display the Examine Indexes. E.g. If you only did a 'binary' file update, then maybe there are some newer UI files that the backoffice have calling the new binaries.

    Lastly, try to delete everything from /App_Data/TEMP/ directory and restart the app pool. This will force a rebuild of the indexes.

    Louis

  • Jin Botol 134 posts 287 karma points
    Aug 09, 2018 @ 10:03
    Jin Botol
    0

    Hi Louis,

    Thanks for you response.

    1. I don't think so, I only know is the Examine & Lucene.Net
    2. Yes, I'm logged in as Administrator.
    3. I am Upgrading UmbracoCms via NuGet.

    Can I try first in my local machine?

    Thanks much appreciated,

    Jin

  • Jin Botol 134 posts 287 karma points
    Aug 11, 2018 @ 02:10
    Jin Botol
    0

    Hi All,

    Am I missing something after Umbraco Upgrade???

    Thanks

  • Jin Botol 134 posts 287 karma points
    Aug 21, 2018 @ 06:23
    Jin Botol
    0

    Hello, any helps?

    Thanks,

    Jin

Please Sign in or register to post replies

Write your reply to:

Draft