pingbu.search.TextIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pingbu-search Show documentation
Show all versions of pingbu-search Show documentation
A multiple condition search library
The newest version!
package pingbu.search;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 文本搜索索引
*
* @author pingbu
*/
public class TextIndex implements SearchIndex {
private final Map mIdToValues = new HashMap<>();
private final Map> mValueToIds = new HashMap>();
@Override
public void addItem(final int id, final String value) {
mIdToValues.put(id, value);
List ids = mValueToIds.get(value);
if (ids == null) {
ids = new ArrayList<>();
mValueToIds.put(value, ids);
}
ids.add(id);
}
@Override
public ListIterator iterate(final String value) {
return new ListIterator(mValueToIds.get(value));
}
}