Sitecore Search Lucene Ranking - sitecore

How can I set the priority of fields when I'm searching with Lucene .Net
For example i have :
Item 1
field 1 =contain "search text"
field 2 ="bla bla"
Item 2
field 1 = "loren ipsun"
field 2 = contain "search text"
What should I do to have on results, top item : item 1 first from list, item 2 second one,etc.

I think I understand your question. You want to have hits on a specific field boosted more then on another field and for this you can use the BoostFactor. You can boost the Query that you are using to search in Field one. For example if you use a Query qryName = queryParser.parse(keyword) you can do the following:
qryName.SetBoost(1000f);
This will boost hits on the specific part of your search that your specified in that query. You should therefor use 2 Query's for both fields and boost the first Query in which you search field 1.
You can vary in the boostfactor untill is suits your needs.
Hope this helps ;)

Related

Sharepoint2013 list item filter

My requirement is I have to submit records into a list/lib with attachments and that record can be tag to category field they can be multiple for a single item.
i.e. An item A can be tag to tag to category X or can be cat X,Y(multiple category can be)
My requirement it user can also filter these record in list/lib on the basis of category tagged.
i.e. if an item A is tagged with cat X,Y it should be show in both cat when we filter.
What approach i should i use in Sharepoint 2013?
you can use the taxonomy to achieve this behaviour. Generate Term sets and terms in it and use them to tag your List Item.
You didnt provide the details about how you are searching the data? by your code or the OOTB sharepoint search ?
Thanks

Designing a Sitecore tree to store more than 1Mn items

I have 300+ "Category" (Can go into 4 sub levels) items and 1Mn+ "Product Items" to be stored in the Sitecore database.
I am designing the Sitecore content tree.
I am considering two options,
Option1 - Model as "Category" --> Sub category .... --> "Product Items"
Option 2 - Model "Category" tree separately and have "Product Items" separately. (Home -> Categories -> cat 1...) and (Home -> Product Items -> All Product Items)
According to my experience if I go for option 1, it will be painfully slow if I need to modify the category items and publish. (Even with some enhancements)
Option 2 does not create a well balanced tree, but the category nodes will be much faster to edit.
Please help me to sort out this. I am using Sitecore 7.
You are more or less going to have to come up with a solution for storing your in a separate section of the content tree. I would most definitely not advise you to place a million+ product items sitting directly under the individual category items. For a number of reasons, including:
Performance, as you say. Changes to categories will happen often, to "follow the market", for "seo reasons". Also "campaign categories" (like "Summer Sale 2014") is bound to pop up from time to time
The nature of a category/product relationship is very rarely 1 to 1. Meaning the same product can and will exist in multiple categories (think: Duracell batteries existing in both "Electrical", "Batteries - Non-rechargeable" and "Camera Accessories" categories)
Since you're on Sitecore 7, the built-in solution for your product repository is to put all the products into an Item Bucket. Then you have two (obvious) choices for Building the product/category relationship:
On "Product", set up a Multilist field named "Categories", and add the ID of each Category item the product belongs to
On "Category", set up a search field to select products from your Item Bucket
It really depends on how this product hierarchy is going to be managed, which of the above fits best.
Information on Item Buckets here: http://sdn.sitecore.net/Reference/Sitecore%207/Developers%20Guide%20to%20Item%20Buckets%20and%20Search.aspx
Solution 1 is still the best one in my opinion.
It always better to create a comprehensive and logical store as "bath and shower articles in the bathroom category" than having products in both categories and no categories.
The global benefit having categories for products is for indexing (as for human, as for your website, as for search engine )
With some CMS like Magento , you easily manage 1M products with categories, and you can edit , move categories as you want, so to finish my answer , yes answer1 is the most suitable answer to me :)
Edit : Sorry i didn t see you re already using sitecore

how to match a field name with another field name

I have two fields that run throughout a website that I would like to match so that when a user inputs a value either of the fields, it will match the other field. I'm using Sitecore Rocks and am trying to use a query to do this.
select ##h1#, ##Title#
from /sitecore/Content/Home//*[##h1# !="##Title#"];
update set ##h1# = ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
What am I missing here?
This article talks about tapping in to the item:saving event which allows you to compare the fields values of the item before and after the changes:
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Intercepting-Item-Updates-with-Sitecore.aspx
Using this, you can determine which field has been amended, then change the other to match.
I've had to do something similar to this when a new field was added, and we wanted to set the initial value equal to an existing field. It may be a bug in Sitecore Rocks, but I found it would only update a field when a static value was part of the query.
When I ran ##h1# = ##Title#, the query analyzer would return the correct number of items updated, but no values were actually updated. However, ##h1# = '<id>' worked perfectly. After trying a number of things, I found this did what I wanted.
update set ##h1# = '' + ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
I hope that helps.

using two xpathselectors on the same page

I have a spider where the scraped items are 3: brand, model and price from the same page.
Brands and models are using the same sel.xpath, later extracted and differentiated by .re in loop. However, price item is using different xpath. How can I use or combine two XPathSelectors in the spider?
Examples:
for brand and model:
titles = sel.xpath('//table[#border="0"]//td[#class="compact"]')
for prices:
prices = sel.xpath('//table[#border="0"]//td[#class="cl-price-cont"]//span[4]')
Tested and exported individually by xpath. My problem is the combining these 2 to construct the proper loop.
Any suggestions?
Thanks!
Provided you can differentiate all 3 kind of items (brand, model, price) later, you can try using XPath union (|) to bundle both XPath queries into one selector :
//table[#border="0"]//td[#class="compact"]
|
//table[#border="0"]//td[#class="cl-price-cont"]//span[4]
UPDATE :
Responding your comment, above meant to be single XPath string. I'm not using python, but I think it should be about like this :
sel.xpath('//table[#border="0"]//td[#class="compact"] | //table[#border="0"]//td[#class="cl-price-cont"]//span[4]')
I believe you are having trouble associating the price with the make/model because both xpaths give you a list of all numbers, correct? Instead, what you want to do is build an xpath that will get you each row of the table. Then, in your loop, you can do further xpath queries to pull out the make/model/price.
rows = sel.xpath('//table[#border="0"]/tr') # Get all the rows
for row in rows:
make_model = row.xpath('//td[#class="compact"]/text()').extract()
# set make and model here using your regex. something like:
(make,model) = re("^(.+?)\s(.+?)$", make_model).groups()
price = row.xpath('//td[#class="cl-price-cont"]//span[4]/text()').extract()
# do something with the make/model/price.
This way, you know that in each iteration of the loop, the make/model/price you're getting all go together.

Django-haystack - highlighting NgramField

I'm trying use highlighting:
self.results = self.results.highlight()
print self.results[0].highlighted['heading'][0]
And this is working perfect if field heading is CharField in search index.
But I need set field heading to NgramField (because I need search start with one letter), and I have issue:
query: old buildings
result: What are old oldbuildings?
What can I do?
Thanks!