You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by solr-user <so...@hotmail.com> on 2010/08/04 19:28:46 UTC

can't use strdist as functionquery?

I want to sort my results by how closely a given resultset field matches a
given string.

For example, say I am searching for a given product, and the product can be
found in many cities including "seattle".  I want to sort the results so
that results from city of "seattle" are at the top, and all other results
below that

I thought that I could do so by using strdist as a functionquery (I am using
solr 1.4 so I cant directly sort on strdist) but am having problems with the
syntax of the query because functionqueries require double quotes and so
does strdist.

My current query, which fails with an NPE, looks something like this:

http://localhost:8080/solr/select?q=(product:"foo")
_val_:"strdist("seattle",city,edit)"&sort=score%20asc&fl=product, city,
score

I have tried various types of URL encoding (ie using %22 instead of double
quotes in the strdist function), but no success.

Any ideas??  Is there a better way to accomplish this sorting??

-- 
View this message in context: http://lucene.472066.n3.nabble.com/can-t-use-strdist-as-functionquery-tp1023390p1023390.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: can't use strdist in sorting either?

Posted by solr-user <so...@hotmail.com>.
issue resolved

I should have read the documentation with more care; "Calculate the distance
between two strings"

my city field was a tokenized text field so changing it to string type got
things working

sorry all
-- 
View this message in context: http://lucene.472066.n3.nabble.com/can-t-use-strdist-as-functionquery-tp1023390p1058059.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: can't use strdist in sorting either?

Posted by solr-user <so...@hotmail.com>.
finally figured out that I can simply escape the quotation marks in the query
URL using backslashes to use strdist as a functionquery (sorry all, that
should have been a no-brainer)

http://10.0.11.54:8994/solr/select?q=(*:*)^0%20_val_:"strdist(\"phoenix\",city,edit)"&fl=score,*&sort=score%20desc

however, sorting by the score in this query doesnt work (ie same problem as
when sorting by strdist function - results dont change when I go from asc to
desc or vice-versa).

-- 
View this message in context: http://lucene.472066.n3.nabble.com/can-t-use-strdist-as-functionquery-tp1023390p1057056.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: can't use strdist in sortiing either?

Posted by solr-user <so...@hotmail.com>.
forgot to mention:

1. yes, I upgraded to a version that allows sorting by Functions (thx Grant
for the work done on this feature, very cool)

2. when I try to sort by strdist, it doesnt seem to do any sorting; I get
the same results if I sort asc or desc, if I change the static string value,
if I change the third argument, etc.
-- 
View this message in context: http://lucene.472066.n3.nabble.com/can-t-use-strdist-as-functionquery-tp1023390p1032231.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: can't use strdist in sortiing either?

Posted by solr-user <so...@hotmail.com>.
I tried I also noticed that I am unable to sort by the strdist function:

http://localhost:8080/solr/select?q=*:*&sort=strdist("seattle",city,edit)%20desc

Am I using the strdist incorrectly?

The version of Solr I am using is $Id: CHANGES.txt 903398 2010-01-26
20:21:09Z hossman $

I know it isnt the latest version, but I am constrained by needing to keep
to a minimum the number of changes between our current version and the
version that accomplishes the task mentioned previously (essentially a
binary sort that separates results where the city matches a given criteria
from those that dont).

Appreciate any help or advice someone can offer on this
-- 
View this message in context: http://lucene.472066.n3.nabble.com/can-t-use-strdist-as-functionquery-tp1023390p1032200.html
Sent from the Solr - User mailing list archive at Nabble.com.