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 Stephen Weiss <sw...@stylesight.com> on 2009/09/08 00:18:47 UTC

Can solr return documents which don't match a query?

Hi everyone,

I have what's probably a loaded question about how Solr parses queries.

Basically, the client wants to restructure the way they handle  
permissions.  Instead of assigning specific permissions ids (as we've  
done up until this point), they want to structure permissions by  
adding a particular filter query depending on the products that the  
user has purchased.  In principle, it could save a lot of reindexing  
time because when products change, it simply changes the filter  
queries, instead of requiring reindexing of large portions of the  
documents in the index.

However, I'm hitting a snag...  Basically, here is the way we'd like  
to structure the queries:

Documents can have zero or more tags in a particular field assigned to  
them.  All permissions are essentially tied to the tags in this  
field.  For each product a user has purchased, there are a certain  
number of tags associated with it.  Users should be able to see all  
documents which match any of these tags, as well as all documents  
which don't match *any* tag associated with a product.  Basically,  
this means that users can see any documents which match their specific  
products, as well as any documents which aren't bound to any product  
in particular (documents which are essentially open to anyone).

Let's say that the following tags represent all the restricted tags in  
the system:

tag1
tag2
tag3
tag4

The current user is allowed access to documents with tags tag1 and  
tag2, and documents which have none of these tags.

So, by my own logic, I'd make the query:

((my_field:tag1) OR (my_field:tag2) OR (-my_field:tag1 AND - 
my_field:tag2 AND -my_field:tag3 AND -my_field:tag4))

Keep in mind that "my_field" can have other tags beyond tags 1-4 which  
essentially have no impact on permissions.

Obviously, I'm writing here because this query doesn't work... at  
all.  I see according to the wikis that, apparently, - or "NOT"  
*excludes* all documents which have the tag in question.  So this is  
just not the right syntax for what I'm doing.

What I can't seem to find is a syntax which says "return all documents  
which don't match this query", or perhaps more importantly, "return  
all documents which either match query1 or don't match query 2".  I  
tried using the "_query_" syntax but no luck there either.

Am I mistaken, or is there simply no way in SOLR to return the  
documents which didn't match the specified query?

If not, I fear there's very little potential for optimization  
here....  Reindexing all affected documents for a product every time a  
product's parameters change is becoming very cumbersome - it can take  
hours.  We'd really like to find a way to avoid having to do that.  If  
anyone can help figure out a way to actually do this I'd be very  
grateful.

Thanks!

--
Steve

Re: Can solr return documents which don't match a query?

Posted by Chantal Ackermann <ch...@btelligent.de>.
Or add a new tag: the "NO TAG" at index time and search for that. (If 
you have the possibility to reindex at least that one, first, time.) 
Would clear things up for developers/admins looking at the stuff in some 
months...

Chantal

Yonik Seeley schrieb:
>> "return all documents which either match query1 or don't match query 2"
> 
> query1 (*:* -query2)
> 
> -Yonik
> http://www.lucidimagination.com


Re: Can solr return documents which don't match a query?

Posted by Yonik Seeley <yo...@lucidimagination.com>.
> "return all documents which either match query1 or don't match query 2"

query1 (*:* -query2)

-Yonik
http://www.lucidimagination.com