cancel
Showing results for 
Search instead for 
Did you mean: 

Finding Content that has custom aspects

unknown-user
Champ on-the-rise
Champ on-the-rise
I am writing a web script to retrieve content by a custom set of aspects that I have added.  I am finding that the query is not returning what I am expecting.  Below is the code that I have used.  I will admit, I am shaky on the paramDefs being necessary or correct.  Input would be appreciated.

DynamicNamespacePrefixResolver namespacePrefixResolver = new DynamicNamespacePrefixResolver(
            null);
      namespacePrefixResolver.registerNamespace("custom", "custom.model");

      QueryParameterDefinition[] paramDefs = new QueryParameterDefinition[3];
      QueryParameterDefImpl productParamDef = new QueryParameterDefImpl(QName
            .createQName("customSmiley TongueroductIdenifier", services.getNamespaceService()),
            (DataTypeDefinition) null, true, getProductId());
      QueryParameterDefImpl sampleParamDef = new QueryParameterDefImpl(QName
            .createQName("custom:sample", services.getNamespaceService()),
            (DataTypeDefinition) null, true, Boolean.toString(getSample()));
      QueryParameterDefImpl typeParamDef = new QueryParameterDefImpl(QName
            .createQName("customSmiley Tonguerimary", services.getNamespaceService()),
            (DataTypeDefinition) null, true, Boolean.toString(getPrimary()));
      paramDefs[0] = productParamDef;
      paramDefs[1] = sampleParamDef;
      paramDefs[2] = typeParamDef;
      
      ResultSet results = null;
      NodeRef nodeRef = null;
      try {
         
         results = services.getSearchService().query(
               rootNodeRef.getStoreRef(), "lucene",
               "@custom\\Smiley TongueroductIdentifier:'" + getProductId() +
               "' AND @custom\\:sample:'" + getSample() +
               "' AND @custom\\Smiley Tonguerimary:'" + getPrimary() + "'",
               paramDefs);
         if(results.length() > 0) {
            nodeRef = results.getNodeRef(0);
         }
      } finally {
         if (results != null) {
            results.close();
         }
      }
      return nodeRef;



Thank you in advance.
2 REPLIES 2

invictus9
Champ in-the-making
Champ in-the-making
You are constructing a query string on the fly. Personally, I have found that to be an error magnet, and I like to have a look at the constructed string to see if it is what I wanted it to be. You could either log the value or turn on logging for Lucene, so you could see what the search query looks like.

Part of the reason I suggest this is that your parameters may need to be properly escaped so that any metacharacters do not interfere with the parsing of the query string.

unknown-user
Champ on-the-rise
Champ on-the-rise
do you have an alternative way of achieving what I am trying to accomplish.  Suggestions are welcome.