Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Improve project search with case insensitive search
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Dec 22, 2013
1 parent e698099 commit 0b49836
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions zanata-war/src/main/java/org/zanata/dao/ProjectDAO.java
@@ -1,21 +1,17 @@
package org.zanata.dao;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.Version;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.search.jpa.FullTextEntityManager;
Expand All @@ -25,7 +21,6 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.zanata.common.ContentState;
import org.zanata.common.EntityStatus;
import org.zanata.hibernate.search.IndexFieldLabels;
import org.zanata.model.HPerson;
Expand Down Expand Up @@ -237,7 +232,7 @@ public int getTotalObsoleteProjectCount() {
}

public List<HProject> searchProjects(@Nonnull String searchQuery,
int maxResult, int firstResult, boolean includeObsolete)
int maxResult, int firstResult, boolean includeObsolete)
throws ParseException {
FullTextQuery query = getTextQuery(searchQuery, includeObsolete);
query.setMaxResults(maxResult).setFirstResult(firstResult)
Expand All @@ -247,14 +242,14 @@ public List<HProject> searchProjects(@Nonnull String searchQuery,
}

public int getQueryProjectSize(@Nonnull String searchQuery,
boolean includeObsolete) {
boolean includeObsolete) throws ParseException {
FullTextQuery query = getTextQuery(searchQuery, includeObsolete);
return query.getResultSize();
}

private FullTextQuery getTextQuery(@Nonnull String searchQuery,
boolean includeObsolete) {
searchQuery = QueryParser.escape(searchQuery);
searchQuery = QueryParser.escape(searchQuery.toLowerCase());

PrefixQuery slugQuery = new PrefixQuery(new Term("slug", searchQuery));
PrefixQuery nameQuery = new PrefixQuery(new Term("name", searchQuery));
Expand Down

0 comments on commit 0b49836

Please sign in to comment.