/** * Checks to see if we need the spatial support, and if so creates * the necessary context objects. */ private void initSpatial() { // FIXME: for now, we only use geosearch if that's the only way to // find suitable records, since we don't know how to combine // geosearch ranking with normal search ranking. if (config.getLookupProperties().size() != 1) return; Property prop = config.getLookupProperties().iterator().next(); if (!(prop.getComparator() instanceof GeopositionComparator)) return; geoprop = new GeoProperty(prop); }
/** * Tokenizes lookup fields and returns all matching buckets in the * index. */ private List<Bucket> lookup(Record record) { List<Bucket> buckets = new ArrayList(); for (Property p : config.getLookupProperties()) { String propname = p.getName(); Collection<String> values = record.getValues(propname); if (values == null) continue; for (String value : values) { String[] tokens = StringUtils.split(value); for (int ix = 0; ix < tokens.length; ix++) { Bucket b = store.lookupToken(propname, tokens[ix]); if (b == null || b.records == null) continue; long[] ids = b.records; if (DEBUG) System.out.println(propname + ", " + tokens[ix] + ": " + b.nextfree + " (" + b.getScore() + ")"); buckets.add(b); } } } return buckets; }
for (Property prop : config.getLookupProperties()) { String propName = prop.getName(); boolean required = prop.getLookupBehaviour() == Property.Lookup.REQUIRED;
/** * Add the record to the index. */ public void index(Record record) { // FIXME: check if record is already indexed // allocate an ID for this record long id = store.makeNewRecordId(); store.registerRecord(id, record); // go through ID properties and register them for (Property p : config.getIdentityProperties()) for (String extid : record.getValues(p.getName())) store.registerId(id, extid); // go through lookup properties and register those for (Property p : config.getLookupProperties()) { String propname = p.getName(); for (String value : record.getValues(propname)) { String[] tokens = StringUtils.split(value); for (int ix = 0; ix < tokens.length; ix++) store.registerToken(id, propname, tokens[ix]); } } }
for (Property p : config.getLookupProperties()) System.out.println(" " + p.getName()); System.out.println();
/** * Look up potentially matching records. */ public Collection<Record> findCandidateMatches(Record record) { if (directory == null) init(); // if we have a geoprop it means that's the only way to search if (geoprop != null) { String value = record.getValue(geoprop.getName()); if (value != null) { Filter filter = geoprop.geoSearch(value); return maintracker.doQuery(new MatchAllDocsQuery(), filter); } } // ok, we didn't do a geosearch, so proceed as normal. // first we build the combined query for all lookup properties BooleanQuery query = new BooleanQuery(); for (Property prop : config.getLookupProperties()) { Collection<String> values = record.getValues(prop.getName()); if (values == null) continue; for (String value : values) parseTokens(query, prop.getName(), value, prop.getLookupBehaviour() == Property.Lookup.REQUIRED, prop.getHighProbability()); } // do the query return maintracker.doQuery(query); }
/** * Checks to see if we need the spatial support, and if so creates * the necessary context objects. */ private void initSpatial() { // FIXME: for now, we only use geosearch if that's the only way to // find suitable records, since we don't know how to combine // geosearch ranking with normal search ranking. if (config.getLookupProperties().size() != 1) return; Property prop = config.getLookupProperties().iterator().next(); if (!(prop.getComparator() instanceof GeopositionComparator)) return; geoprop = new GeoProperty(prop); } }
/** * Tokenizes lookup fields and returns all matching buckets in the * index. */ private List<Bucket> lookup(Record record) { List<Bucket> buckets = new ArrayList(); for (Property p : config.getLookupProperties()) { String propname = p.getName(); Collection<String> values = record.getValues(propname); if (values == null) continue; for (String value : values) { String[] tokens = StringUtils.split(value); for (int ix = 0; ix < tokens.length; ix++) { Bucket b = store.lookupToken(propname, tokens[ix]); if (b == null || b.records == null) continue; long[] ids = b.records; if (DEBUG) System.out.println(propname + ", " + tokens[ix] + ": " + b.nextfree + " (" + b.getScore() + ")"); buckets.add(b); } } } return buckets; }
/** * Add the record to the index. */ public void index(Record record) { // FIXME: check if record is already indexed // allocate an ID for this record long id = store.makeNewRecordId(); store.registerRecord(id, record); // go through ID properties and register them for (Property p : config.getIdentityProperties()) for (String extid : record.getValues(p.getName())) store.registerId(id, extid); // go through lookup properties and register those for (Property p : config.getLookupProperties()) { String propname = p.getName(); for (String value : record.getValues(propname)) { String[] tokens = StringUtils.split(value); for (int ix = 0; ix < tokens.length; ix++) store.registerToken(id, propname, tokens[ix]); } } }
for (Property p : config.getLookupProperties()) System.out.println(" " + p.getName()); System.out.println();
/** * Look up potentially matching records. */ public Collection<Record> findCandidateMatches(Record record) { // if we have a geoprop it means that's the only way to search if (geoprop != null) { String value = record.getValue(geoprop.getName()); if (value != null) { Filter filter = geoprop.geoSearch(value); return maintracker.doQuery(new MatchAllDocsQuery(), filter); } } // ok, we didn't do a geosearch, so proceed as normal. // first we build the combined query for all lookup properties BooleanQuery query = new BooleanQuery(); for (Property prop : config.getLookupProperties()) { Collection<String> values = record.getValues(prop.getName()); if (values == null) continue; for (String value : values) parseTokens(query, prop.getName(), value, prop.getLookupBehaviour() == Property.Lookup.REQUIRED); } // do the query return maintracker.doQuery(query); }