log.debug("No search term found");
return null;
}
String luceneQuery = "";
FullTextQuery query = null;
for (Entry<String, String> entry : requestToField.entrySet())
{
String req = entry.getKey();
if (jsonQuery.containsKey(req))
{
String searchWord = jsonQuery.getString(req);
// remove colons, which can be used to search other fields
searchWord = searchWord.replace(":", "");
if (transformers.containsKey(req))
{
searchWord = (String) transformers.get(req).transform(jsonQuery, userEntityId);
}
// if this is activity content - keep track of it for special content-only handling
if (req.toLowerCase().equals("keywords"))
{
if (searchWord.contains("NOT ") || searchWord.contains("!") || searchWord.contains("-"))
{
// searching content with a NOT component
log.info("User is querying for activity content with:(" + searchWord
+ ") and seems to be using a NOT/!/- component. Lucene doesn't allow "
+ "NOT queries with one component, so I'll add a constant keyword that "
+ "I know is present: " + Activity.CONSTANT_KEYWORD_IN_EVERY_ACTIVITY_CONTENT);
luceneQuery += "+" + entry.getValue() + ":("
+ Activity.CONSTANT_KEYWORD_IN_EVERY_ACTIVITY_CONTENT + " " + searchWord + ") ";
}
else
{
// searching content without NOT component
luceneQuery += "+" + entry.getValue() + ":(" + searchWord + ") ";
}
}
else
{
// searching non-content
luceneQuery += "+" + entry.getValue() + ":(" + searchWord + ") ";
}
}
}
if (luceneQuery.length() == 0)
{
log.debug("Returning all activity");
query = unstemmedRequestBuilder.buildQueryFromNativeSearchString("_hibernate_class:"
+ "org.eurekastreams.server.domain.stream.Activity");
}
else
{
// don't let query parsing throw an exception that bubbles out to the client - it could be from an
// incomplete as-you-type search
try
{
query = searchRequestBuilder.buildQueryFromNativeSearchString(luceneQuery);
}
catch (Exception ex)
{
return new ArrayList<Long>();
}
}
if (jsonQuery.containsKey("sortBy"))
{
query.setSort(new Sort(new SortField(jsonQuery.getString("sortBy"), true)));
}
if (log.isDebugEnabled())
{
log.debug("Native Lucene Query: " + query.toString());
}
searchRequestBuilder.setPaging(query, 0, maxResults);
List<Long> activityIds = query.getResultList();
if (log.isInfoEnabled())
{
log.info("Found " + activityIds.size() + " activities");
}
return activityIds;