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.
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();
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.
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
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.
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;
}
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.
You mentioned 'products', do you know if you have some package
installed that manages products, like Merchello, Tea Commerce, etc?
Are you logging into the backoffice as admin, or another (less privileged) user?
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.
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
My Code :
Have you tried using 'republish entire site' under the content tab in Umbraco?
Yes, I've already try that but no luck :(
Jin
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
Hi Jonny,
There is no Examine Management in my Developer Section
Jin
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
Jin,
You should have examine management in developer section. If not then take a look at your dashboard config file see config\dashboard.config
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.
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
Jin
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
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.
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 :
Here is the ConstructExamineQuery code :
Hope it will help,
Thanks
Jin
Any help?
thanks in advance
Jin
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.
You mentioned 'products', do you know if you have some package installed that manages products, like Merchello, Tea Commerce, etc?
Are you logging into the backoffice as admin, or another (less privileged) user?
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
Hi Louis,
Thanks for you response.
Can I try first in my local machine?
Thanks much appreciated,
Jin
Hi All,
Am I missing something after Umbraco Upgrade???
Thanks
Hello, any helps?
Thanks,
Jin
is working on a reply...