Changeset 30049 for main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java
- Timestamp:
- 2015-07-21T05:26:46+12:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java
r29731 r30049 22 22 import java.util.ArrayList; 23 23 import java.util.HashMap; 24 import java.util.List; 25 import java.util.Map; 24 26 25 27 import org.apache.log4j.Logger; … … 27 29 import org.greenstone.gsdl3.util.GSXML; 28 30 import org.greenstone.gsdl3.util.XMLConverter; 29 30 31 import org.w3c.dom.Document; 31 32 import org.w3c.dom.Element; … … 92 93 protected boolean advanced_form_search = false; 93 94 protected boolean raw_search = false; 95 //Parameters to get full field with highlighted terms 96 protected String hldocOID = null; 97 //index Field for highlighting 98 protected String indexField = null; 94 99 95 100 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractGS2FieldSearch.class.getName()); … … 591 596 protected Element processAnyQuery(Element request, int query_type) 592 597 { 598 593 599 String service_name = null; 594 600 String empty_query_test_param = null; … … 633 639 634 640 // Process the request parameters 641 635 642 HashMap<String, Serializable> params = GSXML.extractParams(param_list, false); 636 643 //Save as variable to make it accessable from GS2SolrSearch 644 hldocOID = (String) params.get("hldocOID"); 645 //System.out.println("@@@@@Extracted hldocOID is " + hldocOID); 637 646 // Make sure a query has been specified 638 647 String query = (String) params.get(empty_query_test_param); … … 644 653 // If a field hasn't been specified, use the default - for textQuery 645 654 String field = (String) params.get(INDEX_PARAM); 655 //Save as variable to make it accessable from GS2SolrSearch 656 646 657 if (field == null) 647 658 { 648 659 field = default_index; 649 660 } 650 661 indexField = field; 651 662 // set up the appropriate query system 652 663 if (!setUpQueryer(params)) … … 668 679 break; 669 680 } 670 681 671 682 // run the query 672 683 Object query_result = runQuery(query); 673 684 685 // We want highlighted text to be returned right now! 686 if (hldocOID != null && does_full_field_highlighting) 687 { 688 Element nodeContentElement = result_doc.createElement(GSXML.NODE_CONTENT_ELEM); 689 nodeContentElement.setTextContent((String) query_result); 690 result.appendChild(nodeContentElement); 691 return result; 692 } 693 694 674 695 // build up the response 675 696 … … 704 725 } 705 726 706 727 Map<String, Map<String, List<String>>> hlResults = null; 728 if (does_highlight_snippets) 729 { 730 hlResults = getHighlightSnippets(query_result); 731 } 732 707 733 // add a metadata item to specify what actual query was done - eg if stuff was stripped out etc. and then we can use the query later, cos we don't know which parameter was the query 708 734 GSXML.addMetadata(metadata_list, "query", query); … … 711 737 Element document_list = result_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 712 738 result.appendChild(document_list); 739 Element snippet_list = result_doc.createElement(GSXML.HL_SNIPPET_ELEM + GSXML.LIST_MODIFIER); 740 result.appendChild(snippet_list); 713 741 for (int d = 0; d < docs.length; d++) 714 742 { 715 743 String doc_id = internalNum2OID(docs[d]); 716 744 Element doc_node = createDocNode(result_doc, doc_id, doc_ranks[d]); 745 if (hlResults != null && hlResults.get(docs[d]) != null && hlResults.get(docs[d]).get(indexField) != null) { 746 for (String snippet : hlResults.get(docs[d]).get(indexField)){ 747 //remove html tags 748 snippet = snippet.replaceAll("\\<.*?>", ""); 749 //remove truncated tags 750 snippet = snippet.replaceAll(".*>", ""); 751 snippet = snippet.replaceAll("\\<.*", ""); 752 //remove unwanted symbols at start of line 753 snippet = snippet.replaceAll("^[ .,»):;-â]+", ""); 754 //highlighting tags transformation 755 snippet = snippet.replaceAll("<", "<"); 756 snippet = snippet.replaceAll(">", ">"); 757 Element snippet_node = result_doc.createElement(GSXML.HL_SNIPPET_ELEM); 758 snippet_node.setAttribute(GSXML.NODE_ID_ATT, doc_id); 759 snippet_node.setTextContent(snippet); 760 snippet_list.appendChild(snippet_node); 761 } 762 } 717 763 document_list.appendChild(doc_node); 718 764 } … … 756 802 } 757 803 804 758 805 return result; 759 806 … … 778 825 /** get the list of facets */ 779 826 abstract protected ArrayList<FacetWrapper> getFacets(Object query_result); 827 828 /** get the map of highlighting snippets */ 829 abstract protected Map<String, Map<String, List<String>>> getHighlightSnippets(Object query_result); 780 830 781 831 /** add in term info if available */
Note:
See TracChangeset
for help on using the changeset viewer.