-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue #31] (Team4) Keyword Operator #85
Changes from all commits
29bef31
b6affd2
5e64dce
ce33cc3
00f1b4d
4487b20
31f12ed
c103be7
f5f58f6
712bcdd
2d8afe6
18b19b6
7e3619f
17b42d6
5f1f044
ed297d7
eb74d2f
8fb8d92
db4a530
774f5da
b4ec071
7671fbf
05315cb
3b2927c
8ddf519
5ba14f6
1357ac2
9bdf5d0
43d9604
a782b1f
ea5d6c0
11bff36
c0e4ba1
365285e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package edu.uci.ics.textdb.dataflow.common; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import edu.uci.ics.textdb.api.common.Attribute; | ||
import edu.uci.ics.textdb.common.utils.Utils; | ||
import org.apache.lucene.analysis.Analyzer; | ||
import org.apache.lucene.queryparser.classic.MultiFieldQueryParser; | ||
import org.apache.lucene.queryparser.classic.ParseException; | ||
import org.apache.lucene.search.BooleanClause; | ||
import org.apache.lucene.search.BooleanQuery; | ||
import org.apache.lucene.search.Query; | ||
import edu.uci.ics.textdb.api.common.IPredicate; | ||
import edu.uci.ics.textdb.api.common.ITuple; | ||
import edu.uci.ics.textdb.common.exception.DataFlowException; | ||
|
||
/** | ||
* @author prakul | ||
* | ||
*/ | ||
|
||
/** | ||
* This class handles creation of predicate for querying using Keyword Matcher | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add high-level comments to explain the purpose of this class. |
||
public class KeywordPredicate implements IPredicate{ | ||
|
||
private final List<Attribute> attributeList; | ||
private final String[] fields; | ||
private final String query; | ||
private final Query queryObject; | ||
private ArrayList<String> tokens; | ||
private Analyzer analyzer; | ||
|
||
public KeywordPredicate(String query, List<Attribute> attributeList, Analyzer analyzer ) throws DataFlowException{ | ||
try { | ||
this.query = query; | ||
this.attributeList = attributeList; | ||
String[] temp = new String[attributeList.size()]; | ||
|
||
for(int i=0; i < attributeList.size(); i++){ | ||
temp[i] = attributeList.get(i).getFieldName(); | ||
} | ||
this.fields = temp; | ||
this.tokens = Utils.tokenizeQuery(analyzer, this.query); | ||
this.analyzer = analyzer; | ||
this.queryObject = createQueryObject(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw new DataFlowException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean satisfy(ITuple tuple) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a "TODO" here? |
||
|
||
//This method is necessary for the interface implementation, and it's really not used. | ||
return true; | ||
} | ||
|
||
/** | ||
* Creates a Query object as a boolean Query on all attributes. | ||
* Example: For creating a query like | ||
* (TestConstants.DESCRIPTION + ":lin" + " AND " + TestConstants.LAST_NAME + ":lin") | ||
* we provide a list of AttributeFields (Description, Last_name) to search on and a query string (lin) | ||
* | ||
* TODO #88:BooleanQuery() is deprecated. In future a better solution could be worked out in Query builder layer | ||
|
||
* @return QueryObject | ||
* @throws ParseException | ||
*/ | ||
private Query createQueryObject() throws ParseException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use an example to explain the purpose of this function. |
||
BooleanQuery booleanQuery = new BooleanQuery(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My Intellij IDE shows that "BooleanQuery" is deprecated. |
||
MultiFieldQueryParser parser = new MultiFieldQueryParser(this.fields, this.analyzer); | ||
for(String searchToken: this.tokens){ | ||
Query termQuery = parser.parse(searchToken); | ||
booleanQuery.add(termQuery, BooleanClause.Occur.MUST); | ||
} | ||
return booleanQuery; | ||
} | ||
|
||
public String getQuery(){ | ||
return query; | ||
} | ||
|
||
public List<Attribute> getAttributeList() { | ||
return attributeList; | ||
} | ||
public Query getQueryObject(){return this.queryObject;} | ||
|
||
public ArrayList<String> getTokens(){return this.tokens;} | ||
|
||
public Analyzer getAnalyzer(){ | ||
return analyzer; | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we "+1"? Explain in comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do.