Hi,

Glad you like it ;)

Not sure what you mean by 'customize queries'. If you mean adding properties
of POJOs to the search traversal, just annotate them as shown below for
'Toy'.

OTOH, if you mean ditching the Lucene query syntax, and making queries more
googlish, I'm not yet sure of proper way to do this. The problem is that
Lucene ORs all of the search terms instead of ANDing them. Usually, users
add more search terms in order to narrow a search, not widen it. I posted a
question about this to the Compass forum. No response yet.

I created a (very) quick-and-dirty JavaScript fragment that ANDs everything
before submitting. I did this because I needed it for a demo. I wasn't going
to publish this because it's such an evil hack, but until someone figures
out the right way to do this:

<%@ include file="/common/taglibs.jsp"%>
<html>
  <head>
    <title>Search</title>
    <script type="text/javascript">
      function fixQuery()
      {
        var displayEle = document.getElementById('display');
        var queryEle = document.getElementById('query');
        
        var query = displayEle.value;
        query = query.replace(/\s+/g, ' ');
        var fixedQuery = '';
        var inPhrase = false;
        var terms = new Array();
        var curTerm = '';
        
        for(var i = 0;i < query.length;i++)
        {
          var curChar = query.charAt(i);
          
          if(curChar == '"')
          {
            curTerm += curChar;
            
            if(inPhrase)
            {
              terms.push(curTerm);
              curTerm = '';
            }
            
            inPhrase = !inPhrase;
            
            continue;
          }
          
          if(inPhrase)
          {
            curTerm += curChar;
            
            continue;
          }
          
          if(curChar == ' ' || i == query.length - 1)
          {
            if(i == query.length - 1)
            {
              curTerm += curChar;
            }
            
            if(!curTerm.match(/\s*AND\s*/))
            {
              terms.push(curTerm);
            }
            
            curTerm = '';
            
            continue;
          }
          
          curTerm += curChar;
        }
        
        fixedQuery = terms.join(' AND ');
        
        queryEle.value = fixedQuery;
      }
      
      window.onload = function() {
        var displayEle = document.getElementById('display');
        var queryEle = document.getElementById('query');
        
        queryEle.value = queryEle.value.replace(/\s*AND\s*/g, ' ');
displayEle.value = queryEle.value;
      }
    </script>
  </head>
  <body>
    Search:
    <form method="GET" onsubmit="fixQuery();">
      <p>
        <input id="display" type="text" name="display" value="" />
      </p>
      <spring:bind path="command.query">
        <input id="query" type="hidden" name="query" value="<c:out
value="${status.value}"/>" />
      </spring:bind>
      <p>
      <input type="submit" value="Search" />
      </p>
    </form>
    <c:if test="${! empty searchResults}">
      <p>Search took <c:out value="${searchResults.searchTime}" /> ms</p>
      <table border="2">
        <tr>
          <th>SCORE</th>
          <th>TYPE</th>
          <th>NAME</th>
          <th>ID</th>
          <th>DESCRIPTION</th>
        </tr>
        <c:forEach var="hit" items="${searchResults.hits}">
          <tr>
            <td><fmt:formatNumber type="percent" value="${hit.score}"
/></td>
            <td><c:out value="${hit.alias}" /></td>
            <td><c:out value="${hit.data.name}" /></td>
            <td><c:out value="${hit.data.id}" /></td>
            <td><c:out value="${hit.data.description}" /></td>
          </tr>
        </c:forEach>
      </table>
    </c:if>
  </body>
</html>

Cheers,

Greg


fadhlirahim wrote:
> 
> Hi, thanks man for your tips. This certainly should be place in the
> tutorials.
> 
> However, how do I customize search queries using Appfuse & Compass. Any
> particular pattern you've done?
> 
> 
> -- 
> /fadhli
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Mini-Tutorial%3A-Compass-and-AppFuse-2.0-tf4420567s2369.html#a12628404
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to