Apache SOLR sort order - magento

I'm using apache solr search in shop based on magento enterprise.
I have some hard problem, and I can't solve it by myself. if some who have solr expirience please help me;)
Solr search is pretty good and it works fine, but I have issue about sorting search results.
I can explain it by example:
We search product by query ex. "HP-118",
and we receive response with ex. 40 products.
In this order "HP-118 LaserJet", "HP-118 DescJet", "HP-118 box case", "Simple thing for HP-118", "Another simple thing for HP-118", "HP-118 BoxJet" etc...
And my problem is in last product in example.
I need to see products that have search query at the begining together..
ex. "HP-118 LaserJet", "HP-118 DescJet", "HP-118 box case","HP-118 BoxJet", "Simple thing for HP-118", "Another simple thing for HP-118"
Thanks for any help !

It all comes to score value (unless you explicitly set other sort order). To check why your results are returned in this order you can do few things:
Read http://wiki.apache.org/solr/SolrRelevancyFAQ
Add score to returned fields, so you can see difference etc. (and score to fl parameters)
Turn on the debug mode in responces (add &debugQuery=on parameter to request)
Study the debug, it will tell you why given result is scored with the value X
I hope that you will find the answer in the debug.
There are ways to boost specific fields, but to help with this you would need to specify more info.

Related

How to sort (and give weight) by Availability dates in SolR

i'm facing a big problem in my SolR DB.
My objects have a datetime field "Available_From" and a datetime field "Available_To".
We also have a "Ranking" field for the sorting.
I can search correctly with direct queries (eg. give me all the items that are available at the moment) but when i do a regular search i cannot find a way to show the items that result "available NOW" in the first places in the results, usually sorted by "Ranking" field.
How can i do this? Am I forced to write some java classes (the nearest thing i've found is there https://medium.com/#devchaitu18/sorting-based-on-a-custom-function-in-solr-c94ddae99a12) or is there a way to do with standard SolR queries?
Thanks in advance to everyone!
In your case you actually don't want sorting, since that indicates that you want one field to determine the returned sequence of documents.
Instead, use boosting - apply a very large boost to those that are available now, either through bq or boost, then apply a boost based on ranking. You'll have to tweak the weights given to each part based on how you want the search results to be presented.

how to get most popular results first in elastic-search

I'm learning elastic search,
I wanted to ask if there is any way to get most searched results first,
like:
by altering the documents and updating a value of em with scores,
using some kind of formula or something else
thanks community :)
You don't have that out of the box but you can indeed modify a document and increase the number of views when a user clicks on a result then use that field as part of the score (function_score might help for this).

Why Solr search is giving zero values in this case

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.
Below you can see an overview of my goal.
I'm using Magento CE 1.7.0.2 & Solr 4.6.0.
Here you can see my goal..
http://127.0.0.1:8055/solr/collection1/select?q="mens+jeans"&indent=true&defType=dismax&pf=fulltext&qs=2
In this case its giving exact products But if i'm searching with jeans mens means its giving zero products.
http://127.0.0.1:8055/solr/collection1/select?q="jeans+mens"&indent=true&defType=dismax&pf=fulltext&qs=2
But i want to get same products for the both cases...
Any Ideas ?
It depends on you have indexed your docs (like Denis wrote at the comment) or it also could depends on your default searching settings.
For example: If all your queries are executed as a phrase-search, so it could be the situation, that your text contains mens ... jeans but never jeans ...mens
You should use an tokenizer and try to use the same field-settings for index- and search-time.
Looking at you solr-webpage you, probably, can use this link: http://127.0.0.1:8055/solr/#/collection1/analysis There you can see, how solr handles the different kind of queries.
This "Analysis"-Feature helps to optimize the field-settings for index- and search-time.

Give advantage to search by phrase in sort SOLR

Search query which I send to SOLR is:
?q=iphone 4s&sort=sold desc
By default the search works great, but the problem appears when I want to
sort results by some field for eg. sold - No. of sold products.
SOLR finds all the results which have: (iphone 4s) or (iphone) or (4s)
So, when I apply sort by field 'sold' first result is: "iPhone 3GS..." which is problem.
I need the results by phrase ("iphone 4s") first and then the rest of the results - all sorted by sold.
So, the questions are:
Is it possible to have query like this, and how?
q=iphone 4s&sort={some algoritam for phrase results first} desc, sold desc
Or, can I perform this by setting up query analyzer and how?
At the moment this is solved by sending 2 requests to SOLR,
first with phrase "iphone 4s" and, if this returns 0 results,
I perform second request without the phrase - only: iphone 4s.
If sorting by score, id, field is not sufficient, Lucene lets you implement custom sorting mechanism by providing your own subclass of FieldComparatorSource abstract base class.
With in that custom-sort-logic, you can implement the way that realizes your requirements.
Example Java code:
If(modelNum1.equals(modelNum2)){
//return based on number of units sold.
}else{
//ALWAYS return a value such that the preferred model beats others.
}
DISCLAIMER: This may lead to maintenance problems as you will have to change the logic when a new phone model arrives.
Steps:
1) Sort object accepts FieldComparatorSource type instance during instantiation.
2) Extend the FieldComparatorSource
3) You've to load the required field information that participates in 'SORTING' using FieldCache within the FieldComparatorSource in setNextReader()
4) Override the FieldComparatorSource.newComparator() to return your custom FieldComparator.
5) In the method FieldComparator.compare(slot1DocId, slot2DocId), you may include your custom logic by accessing the corresponding field information, via loaded FieldCache, using the docIds passed in.
Incorporating Lucene code into Solr as a plug-in should not trouble you..
EDIT:
Can not use space in that function. Term is only without space.
As of Solr3.1, sorting can also be done on arbitrary function queries
(as in FunctionQuery) that produce a single value per document.
So, I will use function termfreq in sort
termfreq(field,term) returns the number of times the term appears in
the field for that document.
Search query will be
q=iphone 4s&sort=termfreq(product_name,"iphone 4s") desc, sold desc
Note: The function termfreq is active from Solr 4.0 version

Magento 1.3.x Quick Search problem

We have built a website http://www.goshopping.pk/ (sorry had to post the link as its important for this question).
The quick search is not working as it should. For example, search "Nokia" and you will get all sorts of results. Search "Dell" and you get the same results. However, searching exact matches like "nokia 6600" or "Intel Core 2 DUO" or "Dell Inspiron" works perfectly fine.
We have rebuilt the search index, emptied the cache etc but it has no effect. What are we missing?
Help appreciated. Thanks!
One quick tip I normally advise people is to remove the description from quick search results in Catalog > Manage Attributes > Attributes
Obviously the description contains all sorts of words and can dilute search results. See if that improves anything.
Also in Configuration > Catalog I normally change the Search Type to Fulltext for more accurate results.
Based on the suggestion from Adam, we were able to resolve this. Here is what we did if anyone needs future reference:
We had about 400 attributes defined and a lot of them were set to search in quick search by our client. What we did is we manually ran a query via phpmyadmin for table "eav_attribute" and updated ALL records to have is_searchable=0
We then manually edited the title and description record in eav_attribute table to is_searchable=1
Rebuilt the search index via Mage Admin and all was good.
Best,
K

Resources