System.out.println(vocabolario_phrase);
// result = xwconn.getFilteredKeys(vocabolario_phrase.replace('\'', '"'), alias, totResult, orientation, startParam,part);
result = xwconn.getFilteredKeys(vocabolario_phrase.replace('\'', '"'), alias, totResult, orientation, startParam, 1, xwconn.getTotNumDoc(), "", "frequenze|spettrale");
if (result.size() < totResult && orientation.equalsIgnoreCase("down") && multi) {
// System.out.println("ne devo prendere di pi�");
Key key = (Key) result.elementAt(result.size() - 1);
// Vector toAdd=xwconn.getFilteredKeys(vocabolario_phrase.replace('\'', '"'), alias, totResult-result.size(), "up", key.key.toString(),part);
Vector toAdd = xwconn.getFilteredKeys(vocabolario_phrase.replace('\'', '"'), alias, totResult - result.size(), "up", key.key.toString(), 1, xwconn.getTotNumDoc(), "", "frequenze|spettrale");
for (int i = 1; i < toAdd.size(); i++) {
result.addElement(toAdd.elementAt(i));
}
}
} else {
System.out.println("STO IN SINGLEKEY QUANTOVALE startParam:" + startParam);
result = xwconn.getSingleKeys(alias, totResult, orientation, startParam, part);
if (result.size() < totResult && orientation.equalsIgnoreCase("down") && multi) {
// System.out.println("ne devo prendere di pi�");
Key key = (Key) result.elementAt(result.size() - 1);
// System.out.println("parto dalla chiave "+key.key.toString());
Vector toAdd = xwconn.getSingleKeys(alias, totResult - result.size(), "up", key.key.toString(), part);
// System.out.println("e ne aggiungo "+toAdd.size());
for (int i = 1; i < toAdd.size(); i++) {
result.addElement(toAdd.elementAt(i));
}
}
}
totNum += xwconn.getTotNumDoc();
} catch (Exception exception) {
}
if (result != null && result.size() != 0) {
// System.out.println(theArch+" result.size() = "+result.size());
for (int i = 0; i < result.size(); i++) {
Key key = (Key) result.elementAt(i);
originalList.add(key);
// System.out.println(">>>>>>>>>>>> ="+key.key.toString());
if (vocabolarioMap.get(key.toString()) != null) {
Key oldKey = (Key) vocabolarioMap.get(key.toString());
oldKey.frequence = oldKey.frequence + key.frequence;
vocabolarioMap.put(key.toString(), oldKey);
} else {
vocabolarioMap.put(key.toString(), key);
}
}
}
}
// for (Enumeration enumeration = vocabolarioMap.keys(); enumeration.hasMoreElements(); vocabolarioList.addElement(vocabolarioMap.get(enumeration.nextElement())))
// ;
for (Entry<String, Key> entry : vocabolarioMap.entrySet()) {
vocabolarioList.add(vocabolarioMap.get(entry.getKey()));
}
List<String> newResult = new ArrayList<String>();
// System.out.println("vocabolarioList.size() = "+vocabolarioList.size());
for (int i = 0; i < vocabolarioList.size(); i++) {
Key key = (Key) vocabolarioList.get(i);
String keyFreq = key.key.toString() + "~" + Integer.toString(key.frequence);
newResult.add(keyFreq);
}
String vocFirst = "";
String vocLast = "";
try {
vocFirst = ((Key) originalList.get(0)).key.toString();
vocLast = ((Key) originalList.get(originalList.size() - 1)).key.toString();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Object objs[] = newResult.toArray();
// Arrays.sort(objs);
// Arrays.sort(objs,Collator.getInstance(Locale.ITALIAN));
Arrays.sort(objs, new XWComparator());
// newResult.removeAllElements();
newResult.clear();
Map<String, Integer> summKeys = new TreeMap<String, Integer>();
for (int i = 0; i < objs.length; i++) {
String keyString = (String) objs[i];
String sKey = keyString.substring(0, keyString.indexOf("~"));
String sFrequence = keyString.substring(keyString.indexOf("~") + 1, keyString.length());
int laFrequenza = Integer.parseInt(sFrequence);
if (summKeys.get(sKey) != null) {
summKeys.put(sKey, new Integer(((Integer) summKeys.get(sKey)).intValue() + laFrequenza));
} else {
summKeys.put(sKey, new Integer(laFrequenza));
}
}
// String keyH;
// for (Enumeration enumeration2 = summKeys.keys(); enumeration2.hasMoreElements(); newResult.add(keyH + "~" + ((Integer) summKeys.get(keyH)).toString()))
// keyH = (String) enumeration2.nextElement();
for (Entry<String, Integer> entry : summKeys.entrySet()) {
String keyH = entry.getKey();
newResult.add(keyH + "~" + ((Integer) summKeys.get(keyH)).toString());
}
objs = newResult.toArray();
// Arrays.sort(objs);
// Arrays.sort(objs,Collator.getInstance(Locale.ITALIAN));
Arrays.sort(objs, new XWComparator());
// newResult.removeAllElements();
newResult.clear();
List<Key> newResultKey = new ArrayList<Key>();
// newResult = new ArrayList<String>();
// System.out.println("objs.length = "+objs.length);
if (orientation.equalsIgnoreCase("up") || !multi) {
// System.out.println("avanti");
for (int i = 0; i < objs.length; i++) {
String keyString = (String) objs[i];
String sKey = keyString.substring(0, keyString.indexOf("~"));
String sFrequence = keyString.substring(keyString.indexOf("~") + 1, keyString.length());
int laFrequenza = Integer.parseInt(sFrequence);
Key key = new Key(sKey, laFrequenza);
newResultKey.add(key);
if (i == totResult - 1)
break;
}
} else {
if (objs.length >= totResult) {
// System.out.println("indietro toto result"+totResult +" partendo da "+(objs.length-totResult));
int start = 0;
int end = objs.length;
for (int i = 0; i < objs.length; i++) {
String keyString = (String) objs[i];
String sKey = keyString.substring(0, keyString.indexOf("~"));
// System.out.println("sKey = |" + sKey +"| lo comparo con startParam = |"+ startParam+"|");
if (sKey.trim().equalsIgnoreCase(startParam.trim())) {
end = i + 1;
if (i - totResult >= 0) {
start = i - (totResult - 1);
} else {
end = totResult;
}
// System.out.println("ok sono uguali sKey e startParam");
break;
}
}
if (start < 0) {
start = 0;
end = start + totResult;
}
for (int i = start; i < end; i++) {
// for(int i = objs.length-totResult; i < objs.length; i++){
String keyString = (String) objs[i];
String sKey = keyString.substring(0, keyString.indexOf("~"));
System.out.println("le chiavi risultanti sono = " + sKey);
String sFrequence = keyString.substring(keyString.indexOf("~") + 1, keyString.length());
int laFrequenza = Integer.parseInt(sFrequence);
Key key = new Key(sKey, laFrequenza);
newResultKey.add(key);
}
}