我需要查询产品数据库,查询可以包含正斜杠(例如“ 30/20”),但是它总是将查询分为两部分,例如 _text:30和_text:20。
我试图用反斜杠(例如“ 30/20”)转义正斜杠,或者将encodeURI用作“ 30%2F20”,但是它也不起作用。
我应该在数据库中编码/替换正斜杠吗?
我尝试在查询字段中使用(Solr Query not parsing forward slash)后面的引号,例如“ 5/12”,如果数据库中包含“ 12.5 / 12”,则该行不起作用。
有人遇到了这个问题吗? 预先感谢!
答案 0 :(得分:0)
使用不在package listtest;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.DefaultListModel;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class JListSelection{
static int selectedIndex;
static JList<String> serials;
static DefaultListModel<String> model;
static private JPopupMenu editPopup;
static private JTextField editTextField;
public static void main(String[] args) {
JPanel pan = new JPanel(null);
selectedIndex = 0;
serials = new JList<String>();
model = new DefaultListModel<String>();
serials = new JList<String>(model);
for(int i = 0; i < 19; i++) {
model.addElement(" ");
}
serials.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
serials.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedIndex = serials.getSelectedIndex();
System.out.println("in listener: " + serials.getSelectedIndex());
}
});
serials.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
System.out.println("In keypressed: " + e.getKeyCode() + " " + serials.getSelectedIndex());
}
public void keyReleased(KeyEvent e) {
int code = e.getKeyCode();
switch( code ){
case KeyEvent.VK_UP:
System.out.println("UP " + serials.getSelectedIndex());
break;
case KeyEvent.VK_DOWN:
System.out.println("DOWN " + serials.getSelectedIndex());
break;
}
if(e.getKeyCode() >= KeyEvent.VK_A && e.getKeyCode() <= KeyEvent.VK_Z
|| e.getKeyCode() >= KeyEvent.VK_0 && e.getKeyCode() <= KeyEvent.VK_9) {
System.out.println(selectedIndex + " " + serials.getSelectedIndex());
Rectangle r = serials.getCellBounds(selectedIndex, selectedIndex);
if (editPopup == null) {
createEditPopup();
}
editPopup.setPreferredSize(new Dimension(r.width, r.height));
editPopup.show(serials, r.x, r.y);
editTextField.setText(
serials.getSelectedValue().toString().equals(" ") ?
e.getKeyChar()+"" : serials.getSelectedValue().toString());
editTextField.requestFocusInWindow();
}
}
});
serials.setBounds(0, 0, 200, 800);
pan.add(serials);
JDialog di = new JDialog();
di.setContentPane(pan);
di.pack();
di.setLocationRelativeTo(null);
di.setSize(300, 400);
di.setVisible(true);
}
private static void createEditPopup(){
editTextField = new JTextField();
editTextField.setBorder(
UIManager.getBorder("List.focusCellHighlightBorder"));
editTextField.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
DefaultListModel<String> model = (DefaultListModel<String>)
serials.getModel();
model.set(selectedIndex, editTextField.getText());
editPopup.setVisible(false);
}
});
editPopup = new JPopupMenu();
editPopup.setBorder(new EmptyBorder(0, 0, 0, 0));
editPopup.add(editTextField);
}
}
上拆分的其他标记器,例如the WhitespaceTokenizer。这样,/
将被保留为一个单一令牌。
如果您仍然需要支持查询5/12
的用户以提供匹配,则可以由原始字段类型提供服务。如果您还需要支持通过完整令牌的子集进行查询(例如,当值为5 12
时是5/12
),请使用NGramFilter将令牌进一步拆分为覆盖每个组合的子令牌({{1 }},12.5/12
,1
等)。