Skip to content

Commit

Permalink
Make store property configurable in schema for meta-data column
Browse files Browse the repository at this point in the history
  • Loading branch information
yozhao committed Jan 14, 2013
1 parent 3002eb0 commit 3ce72c9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion example/cars/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
default delimiter is ","
-->
<column name="tags" type="string" multi="true" delimiter=","/>
<!-- attributes: indexed,store,termvector are only used when type is text -->
<!-- attributes: indexed,termvector are only used when type is text -->
<column name="contents" type="text" index="ANALYZED" store="YES" termvector="YES" />
</table>

Expand Down
55 changes: 29 additions & 26 deletions sensei-core/src/main/java/com/senseidb/conf/SenseiSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,27 @@ public class SenseiSchema {
public static final String EVENT_TYPE_DELETE = "delete";
public static final String EVENT_TYPE_SKIP = "skip";

private static Logger logger = Logger.getLogger(SenseiSchema.class);
private String _uidField;
private String _deleteField;
private String _skipField;
private String _srcDataStore;
private String _srcDataField;
private static Logger logger = Logger.getLogger(SenseiSchema.class);

private String _uidField;
private String _deleteField;
private String _skipField;
private String _srcDataStore;
private String _srcDataField;
private boolean _compressSrcData;
private List<FacetDefinition> facets = new ArrayList<FacetDefinition>();
public static class FieldDefinition {
public Format formatter;
public boolean isMeta;
public IndexSpec textIndexSpec;
public String fromField;
public boolean isMulti;
public boolean isActivity;
public String delim = ",";
public Class type = null;
}

public static class FieldDefinition {
public Format formatter;
public boolean isMeta;
public IndexSpec textIndexSpec;
public String fromField;
public boolean isMulti;
public boolean isActivity;
public String delim = ",";
public Store store;
public Class type = null;
}

public static class FacetDefinition {
public String name;
Expand Down Expand Up @@ -163,11 +165,15 @@ public static SenseiSchema build(JSONObject schemaObj) throws JSONException,Conf
String n = column.getString("name");
String t = column.getString("type");
String frm = column.optString("from");

String storeString = column.optString("store", "");

FieldDefinition fdef = new FieldDefinition();
fdef.formatter = null;
fdef.fromField = frm.length() > 0 ? frm : n;

fdef.store = storeString.length() > 0 ? DefaultSenseiInterpreter.STORE_VAL_MAP.get(storeString.toUpperCase()) : Store.NO;
if (fdef.store == null) {
throw new ConfigurationException("Invalid indexing parameter specification");
}
fdef.isMeta = true;

fdef.isMulti = column.optBoolean("multi");
Expand Down Expand Up @@ -228,21 +234,18 @@ public static SenseiSchema build(JSONObject schemaObj) throws JSONException,Conf
else if (t.equals("text")){
fdef.isMeta = false;
String idxString = column.optString("index", "");
String storeString = column.optString("store", "");
String tvString = column.optString("termvector", "");
Index idx = idxString.length() == 0? Index.ANALYZED : DefaultSenseiInterpreter.INDEX_VAL_MAP.get(idxString.toUpperCase());
Store store = storeString.length() == 0? Store.NO : DefaultSenseiInterpreter.STORE_VAL_MAP.get(storeString.toUpperCase());
TermVector tv = tvString.length() == 0? TermVector.NO : DefaultSenseiInterpreter.TV_VAL_MAP.get(tvString.toUpperCase());

if (idx==null || store==null || tv==null){
if (idx==null || tv==null || fdef.store==null){
throw new ConfigurationException("Invalid indexing parameter specification");
}

IndexSpec indexingSpec = new IndexSpec();
indexingSpec.store = store;
indexingSpec.store = fdef.store;
indexingSpec.index = idx;
indexingSpec.tv = tv;

fdef.textIndexSpec = indexingSpec;
}

Expand Down Expand Up @@ -382,7 +385,7 @@ else if (t.equals("text")){
indexingSpec.store = store;
indexingSpec.index = idx;
indexingSpec.tv = tv;

fdef.textIndexSpec = indexingSpec;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,12 @@ public CustomIndexingPipeline getCustomIndexingPipeline(){
return _customIndexingPipeline;
}


public void setJsonFilter(JsonFilter jsonFilter){
_jsonFilter = jsonFilter;
}


public static List<String> tokenize(String val, String delim)
{
List<String> result = new ArrayList<String>();
Expand Down Expand Up @@ -289,6 +291,7 @@ public ZoieIndexable convertAndInterpret(JSONObject obj) {
else {
filtered = src;
}

return new AbstractZoieIndexable(){

@Override
Expand Down Expand Up @@ -345,7 +348,7 @@ public IndexingReq[] buildIndexingReqs() {
else{
strVal = String.valueOf(val);
}
Field metaField = new Field(name,strVal,Store.NO,Index.NOT_ANALYZED_NO_NORMS);
Field metaField = new Field(name,strVal,fldDef.store, Index.NOT_ANALYZED_NO_NORMS);
metaField.setOmitNorms(true);
metaField.setIndexOptions(IndexOptions.DOCS_ONLY);
luceneDoc.add(metaField);
Expand Down Expand Up @@ -454,9 +457,7 @@ public byte[] getStoreValue()
public boolean isStorable() {
return true;
}




};
}

Expand Down

0 comments on commit 3ce72c9

Please sign in to comment.