Umbraco search engine duplicate bug - search-engine

Hi here the scenario i created a SITE1 where in the blog it has an examine search engine and it is working correctly. now I have to copy my whole page to duplicate it for my new demo SITE2 then I test my search engine and it picked the searched item on the page it self "AND IT ALSO PICKED THE ITEM ON THE SITE1!" :/ that's bad issue..
Any idea how to avoid to picked search item on the other site or content??
Here is my search code:
#{
string searchTerm = Request.QueryString["search"];
var searcher = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"];
var searchCriteria = searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.And);
var query = searchCriteria.GroupedOr(new string[] { "nodeName", "addblogImage", "blogTitle", "datePublished", "blogCategory", "blogAuthor", "blogbodyText", "blogreadMore" }, searchTerm).Compile();
var searchResults = searcher.Search(query);
}
#{
try {
if (searchResults.Any()){
<div class="items-row cols-3 row-0 row-fluid clearfix clean-list background-white">
<div class="span4 post padding">
#foreach (var result in searchResults){
var node = Umbraco.Content(result.Fields["id"]);
<div class="item column-1" itemprop="blogPost" style="margin:0">
#if(node.HasValue("addblogImage")){
var blogImg = Umbraco.TypedMedia(node.GetPropertyValue<string>("addblogImage"));
<img src="#blogImg.Url" alt="" width="898" height="597">
}

Sounds like both sites use the same search index.
Make sure in ExamineIndex.config the indexers are using a different IndexPath
For more useful Examine documentation, check out: http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine

Related

how to concatinate two string from single column in mvc razor

I have a database called news and have a column called description, I have two take the Last two entries from table (description column) and display the result as a single string string , ie, want to append the data in the Second last column to the last data. But I am not able to append the text,and deleted the code.
controller
public ActionResult Index()
{
var news = db.News.OrderByDescending(u => u.Id).FirstOrDefault();
return View(news);
}
view
#model Project.Models.News
<a href="#Url.Action("NewsInnerPage", "News")">
<marquee>
<p>
#Html.Raw(Model.Description)
</p>
</marquee>
</a>
sql column
I want to get the value from table last two entries as a single string . can anyone please help me to write the code . how can i append string ???
var news = db.News.OrderByDescending(u => u.Id).Take(2).ToList();
var concatenatedNews = new News {
Description = news[0].Description + news[1].Description
};
or you could do it all in one line
var news = new News { Description = string.Join("", news.OrderByDescending(u => u.Id).Take(2).Select(u => u.Description)) };

AngularJS and jqueryUI apply new index of list elements

I'm currently finishing a feature with list reordering and I'm stuck with a probably very simple thing, but I'm really sorry that I can't figure out how to solve it .... ( possibly my brain just ignores this logic :) )
The purpose is simple :
I have a list of items with a "position" data (different from $index).
I drag and drop items to change their order.
When the drag stops, all items in the list should have a new position, that'll be updated with a $resource object.
For example, after dragging I have this:
$index elem.position
0 2
1 1
2 3
should automatically change position 2->1, 1->2 and 3->3.
The problem :
With angularUI I can have the current item index but not the others in the list. So I can't change the whole list index after stopping the drag. And it's frustrating because on view, I can catch easily $index but not in controller.
Code :
in controller.js
$scope.updateSortable = {
stop: function(e, ui) {
for (var i=0; i<$scope.list.length; i++) {
var elem = $scope.list[i];
// here's don't know how to update elem.position
//elem.position = ui.item.index; // bad one, I know :)
//elem.$update();
}
},
placeholder: "xp-hightlight",
axis: 'y'
};
in html page :
<div ng-repeat="el in list">
<div>
<span class="position" ng-bind="el.position"></span>
</div>
</div>
The json items look like that :
{ id: 47, description: "my text in the list", position: 1}
Would this work for you, or do you have to have the position variable set?
<div ng-repeat="el in list">
<div>
<span class="position">{{$index + 1}}</span>
</div>
</div>
I added this to your controller 'testCtrl'. You can update the position element within the callback of this watch:
var _list;
$scope.$watch(function() {
return JSON.stringify($scope.items)
},function(_l) {
if(typeof _l !== 'undefined') {
_list = JSON.parse(_l);
console.log(_list)
}
});
I just solved the issue, and thanks to koolunix I managed the update of position directly inside the controller with this plunkr :
http://plnkr.co/edit/kDkNLSjoHbnaumk2uaOF?p=preview
The main fact was just to manage the position with the loop in list items.
elem.position=i+1;

Aspx to Razor Select List MVC5

I have converted my MVC3 application to MVC5, I had to change all views to razor. Having a challenge with a select list:
In ASPX view that works I am using the following:
<select id="Profession" name="Profession" style="width: 235px; background-color: #FFFFCC;">
<% List<string> allProfessions = ViewBag.AllProfessions;
string selectedProfession;
if (Model != null && !String.IsNullOrEmpty(Model.Profession))
selectedProfession = Model.Profession;
else
selectedProfession = allProfessions[0];
foreach (var aProfession in allProfessions)
{
string selectedTextMark = aProfession == selectedProfession ? " selected=\"selected\"" : String.Empty;
Response.Write(string.Format("<option value=\"{0}\" {1}>{2}</option>", aProfession, selectedTextMark, aProfession));
}%>
</select>
In Razor I am using:
<select id="Profession" name="Profession" style="width: 235px; background-color: #FFFFCC;">
#{List<string> allProfessions = ViewBag.AllProfessions;
string selectedProfession;}
#{if (Model != null && !String.IsNullOrEmpty(Model.Profession))
{selectedProfession = Model.Profession;}
else {selectedProfession = allProfessions[0];}
}
#foreach (var aProfession in allProfessions)
{
string selectedTextMark = aProfession == selectedProfession ?
"selected=\"selected\"" : String.Empty;
Response.Write(string.Format("<option value=\"{0}\" {1}>{2}</option>",
aProfession, selectedTextMark, aProfession));
}
</select>
The list shows up at the top of the page, I can't figure out where is the problem. Would appreciate your assistance.
Don't create your dropdown manually like that. Just use:
#Html.DropDownListFor(m => m.Profession, ViewBag.AllProfessions, new { style = "..." })
UPDATE
I tried your solution but got this error: Extension method cannot by dynamically dispatched
And, that's why I despise ViewBag. I apologize, as my answer was a little generic. Html.DropDownList requires the list of options parameter to be an IEnumerable<SelectListItem>. Since ViewBag is a dynamic, the types of its members cannot be ascertained, so you must cast explicitly:
(IEnumerable<SelectListItem>)ViewBag.AllProfessions
However, your AllProfessions is a simple array, so that cast won't work when the value gets inserted at run-time, but that can be easily fixed by casting it to a List<string> and then converting the items with a Select:
((List<string>)ViewBag.AllProfessions).Select(m => new SelectListItem { Value = m, Text = m })
There again, you see why dynamics are not that great, as that syntax is rather awful. The way you should be handling this type of stuff is to use your model or, preferably, view model to do what it should do: hold domain logic. Add a property to hold your list of profession choices:
public IEnumerable<SelectListItem> ProfessionChoices { get; set; }
And then, in your controller action, populate this list before rendering the view:
var model = new YourViewModel();
...
model.ProfessionChoices = repository.GetAllProfessions().Select(m => new SelectListItem { Value = m.Name, Text = m.Name });
return View(model);
repository.GetAllProfessions() is shorthand for whatever you're using as the source of your list of professions, and the Name property is shorthand for how you get at the text value of the profession: you'll need to change that appropriately to match your scenario.
Then in your view, you just need to do:
#Html.DropDownListFor(m => m.Profession, Model.ProfessionChoices)
Given that you don't have this infrastructure already set up, it may seem like a lot to do just for a drop down list, and that's a reasonable thing to think. However, working in this way will keep your view lean, make maintenance tons easier, and best of all, keep everything strongly-typed so that if there's an issue, you find out at compile-time instead of run-time.
I believe it's happening because of the Response.Write. Try this:
#Html.Raw(string.Format("<option value=\"{0}\" {1}>{2}</option>", aProfession,
selectedTextMark, aProfession))

Display index of list item using jQuery

I have an unordered list like so:
<ul class="foo">
<li id="asdf">
<span class="indexnumber"></span>
<span class="description">whatever</span>
</li>
<li id="asdfasdf">
<span class="indexnumber"></span>
<span class="description">whatever</span>
</li>
</ul>
I want to display the index number of the list item in the indexnumber span (i.e., the first item will display 1, the second will display 2, and so on). My users will have the ability to sort the list items (using jquery ui sortable). I would like to be able to show my users a number in the list item that indicates where the list item is (and the value can change as the user re-orders the list).
How can I simply display the index position in the array using jquery? Alternately, is there an easy way to do this with the sortable events (i.e., once the list is sorted, increment or decrement the indexnumbers in all other list items as appropriate)?
I guess you could add the DOM elements to an array using something like
var arr = jQuery.makeArray(document.getElementsByTagName("span"));
Then get their index using jQuery.inArray( value, array ) which returns an int.
Not very pretty though
I ended up doing the following:
$(function() {
$(".foo").sortable({
stop: function(event, ui) {
var itemID = $(ui.item).attr("id");
var items = $("li#" + itemID).parent(".foo").children();
var updateditems = new Array();
for (var i = 0; i <= items.length - 1; i++) {
var singleitemID = $(items[i]).attr("id");
var loc = i + 1;
$("#" + singleitemID).text(loc);
updateditems.push([singleitemID, loc]);
}
}
});
});
index_list = function() {
$(".foo li").each(function(i){
$(this).find(".indexNumber").html((i+1));
});
}
you can call this function on document ready and on the change attribute of the sortable object

How to self-redirect and changing a parameter in asp.net mvc?

If my urls looks like:
www.mysite.com/1/home
www.mysite.com/1/other-action
www.mysite.com/1/another-action/?value=a
how can I switch the 1 parameter while invoking the same action with the same parameters and querystring values?
For example if I'm currently browsing
www.mysite.com/1/another-action/?value=a
I would like to obtain the necessary links to switch to
www.mysite.com/2/another-action/?value=a
.
.
www.mysite.com/x/another-action/?value=a
Url.Action seems not to help...
The general idea is clone the current RouteValueDictionary, change one value, and then build a new action link based on the new RouteValueDictionary. Here's an example. But you'd probably want to do this in a URL helper, rather than directly in the view:
<% var foo = new RouteValueDictionary();
foreach (var value in ViewContext.RouteData.Values)
{
foo.Add(value.Key, value.Value);
}
foo["id"] = 2;
var newUrl = Url.Action(foo["action"].ToString(), foo); %>
I would propose small optimization to Craig's answer:
<% var foo = new RouteValueDictionary(ViewContext.RouteData.Values);
foo["id"] = 2;
var newUrl = Url.Action(foo["action"].ToString(), foo); %>

Resources