cancel
Showing results for 
Search instead for 
Did you mean: 

How to build lucene query with OR using search context?

anujs86
Champ in-the-making
Champ in-the-making
In Search Context there is a method addAttributeQuery(QName qname, String value).
This creates search query with AND.

Is there any way I can add OR query in search context?

Suppose I have one property test1:name and another attribute test2:name.
I want to search name property with respect to test1:name as well as test2:name.

I can do it by writing lucene query and get the results. But I have to do it via Search Context.

Let me know if its possible as i do not see any method in SearchContext.java to take OR query.
6 REPLIES 6

mitpatoliya
Star Collaborator
Star Collaborator
You need to use the SearchParameter object and SearchService if you are using JAVA.
Also for javascript you need to user the SearchService.

anujs86
Champ in-the-making
Champ in-the-making
Can you be bit more clear how can I use it in Search Context?

anujs86
Champ in-the-making
Champ in-the-making
In Search Context there is a method addAttributeQuery(QName qname, String value).
This creates search query with AND.

Is there any way I can add OR query in search context?

Suppose I have one property test1:name and another attribute test2:name.
I want to search name property with respect to test1:name as well as test2:name.

I can do it by writing lucene query and get the results. But I have to do it via Search Context.

Let me know if its possible as i do not see any method in SearchContext.java to take OR query.


Anyone has any idea??

abarisone
Star Contributor
Star Contributor
Hi,
look here for info about SearchService http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2Frm-searchsy...
You can define a query using SearchService.LANGUAGE_FTS_ALFRESCO and a template as descibed here http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2Frm-searchsy...

Regards,
Andrea

anujs86
Champ in-the-making
Champ in-the-making
Thanks Andrea.

I want information on SearchContext as it has already been used and I cannot change it at this point of time.
I want to know whether we can add OR query using SearchContext.

sliaw
Champ in-the-making
Champ in-the-making
'OR' condition is being called by default unless 'AND' condition is being called by force.

Check the svn code for SearchContext object at http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/web-client/source/jav...

   /**
    * @return Returns if AND is forced between text terms. False (OR terms) is the default.
    */
   public boolean getForceAndTerms()
   {
      return this.forceAndTerms;
   }