List of usage examples for org.apache.lucene.facet FacetsConfig getDimConfig
public DimConfig getDimConfig(String dimName)
From source file:com.qwazr.search.query.DrillDrownQuery.java
License:Apache License
final static Query facetTermQuery(FacetsConfig facetsConfig, String dim, Set<String> filter_terms) { String indexedField = facetsConfig.getDimConfig(dim).indexFieldName; if (filter_terms.size() == 1) return new org.apache.lucene.search.TermQuery( facetTerm(indexedField, dim, filter_terms.iterator().next())); return new org.apache.lucene.queries.TermsQuery(facetTerms(indexedField, dim, filter_terms)); }
From source file:com.semantic.swing.facet.FacetJTabbedPane.java
public void handleResult(QueryResultEvent event) throws IOException { PlugInManager pluginManager = ApplicationContext.instance().get(ApplicationContext.PLUGIN_MANAGER); IndexManager lucene = ApplicationContext.instance().get(IndexManager.LUCENE_MANAGER); IndexSearcher searcher = event.getCurrentSearcher(); /* facet collector */ FacetsCollector fc = new FacetsCollector(); FacetsConfig cfg = event.getFacetConfig(); FacetsCollector.search(searcher, event.getQuery(), 5, fc); for (IFieldProperty def : pluginManager.allInstances(IFieldProperty.class)) { if (def.hasFacet()) { try { String indexFieldName = cfg.getDimConfig(def.getName()).indexFieldName; Facets facets = new FastTaxonomyFacetCounts(indexFieldName, lucene.getTaxoReader(), cfg, fc); faceted.get(def.getName()).setResult(facets.getTopChildren(5, def.getName()), Collections.emptyList()); } catch (Exception e) { e.printStackTrace();// w w w.ja v a2 s .c om } } } }
From source file:com.semantic.swing.facet.FacetOverview.java
@Override public void handleEvent(QueryResultEvent event) { try {// ww w . j av a 2 s. c o m FacetsConfig cfg = event.getFacetConfig(); Map<IFieldProperty, List<String>> labels = getSelectedLabels(); // DrillDownQuery dq = createDq(cfg); // clean removeAll(); PlugInManager pluginManager = ApplicationContext.instance().get(ApplicationContext.PLUGIN_MANAGER); IndexManager lucene = ApplicationContext.instance().get(IndexManager.LUCENE_MANAGER); IndexSearcher searcher = event.getCurrentSearcher(); // facet collector FacetsCollector fc = new FacetsCollector(); FacetsCollector.search(searcher, event.getQuery(), 5, fc); // DrillSideways.DrillSidewaysResult r = null; // if (dq != null) { // DrillSideways ds = new DrillSideways(searcher, cfg, lucene.getTaxoReader()); // r = ds.search(dq, 5); // } for (IFieldProperty def : pluginManager.allInstances(IFieldProperty.class)) { if (def.hasFacet()) { try { String indexFieldName = cfg.getDimConfig(def.getName()).indexFieldName; // if (r != null) { // System.out.println(r.facets.getTopChildren(5, indexFieldName)); // } Facets facets = new FastTaxonomyFacetCounts(indexFieldName, lucene.getTaxoReader(), cfg, fc); FacetResult result = facets.getTopChildren(5, def.getName()); if (result != null && result.childCount > 0) { FacetFieldPanel facetView = new FacetFieldPanel(def); facetView.setResult(result, labels.containsKey(def) ? labels.get(def) : Collections.emptyList()); add(facetView); } } catch (Exception e) { e.printStackTrace(); } } } repaint(); } catch (IOException ex) { Logger.getLogger(FacetOverview.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.efaps.admin.index.Searcher.java
License:Apache License
/** * Search.// w w w . j a v a 2 s . c o m * * @param _search the search * @return the search result * @throws EFapsException on error */ protected SearchResult executeSearch(final ISearch _search) throws EFapsException { final SearchResult ret = new SearchResult(); try { LOG.debug("Starting search with: {}", _search.getQuery()); final StandardQueryParser queryParser = new StandardQueryParser(Index.getAnalyzer()); queryParser.setAllowLeadingWildcard(true); if (EFapsSystemConfiguration.get().containsAttributeValue(KernelSettings.INDEXDEFAULTOP)) { queryParser.setDefaultOperator(EnumUtils.getEnum(StandardQueryConfigHandler.Operator.class, EFapsSystemConfiguration.get().getAttributeValue(KernelSettings.INDEXDEFAULTOP))); } else { queryParser.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); } final Query query = queryParser.parse(_search.getQuery(), "ALL"); final IndexReader reader = DirectoryReader.open(Index.getDirectory()); Sort sort = _search.getSort(); if (sort == null) { sort = new Sort(new SortField(Key.CREATED.name(), SortField.Type.LONG, true)); } final FacetsConfig facetConfig = Index.getFacetsConfig(); final DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(Index.getTaxonomyDirectory()); final IndexSearcher searcher = new IndexSearcher(reader); final FacetsCollector fc = new FacetsCollector(); final TopFieldDocs topFieldDocs = FacetsCollector.search(searcher, query, _search.getNumHits(), sort, fc); if (_search.getConfigs().contains(SearchConfig.ACTIVATE_DIMENSION)) { final Facets facets = new FastTaxonomyFacetCounts(taxoReader, facetConfig, fc); for (final FacetResult result : facets.getAllDims(1000)) { LOG.debug("FacetResult {}.", result); final DimConfig dimConfig = facetConfig.getDimConfig(result.dim); final Dimension retDim = new Dimension().setKey(result.dim); ret.getDimensions().add(retDim); for (final LabelAndValue labelValue : result.labelValues) { final DimValue dimValue = new DimValue().setLabel(labelValue.label) .setValue(labelValue.value.intValue()); dimValue.setPath(new String[] { retDim.getKey() }); retDim.getValues().add(dimValue); if (dimConfig.hierarchical) { addSubDimension(facets, dimValue, result.dim, labelValue.label); } } } } ret.setHitCount(topFieldDocs.totalHits); if (ret.getHitCount() > 0) { final ScoreDoc[] hits = topFieldDocs.scoreDocs; LOG.debug("Found {} hits.", hits.length); for (int i = 0; i < hits.length; ++i) { final Document doc = searcher.doc(hits[i].doc); final String oid = doc.get(Key.OID.name()); final String text = doc.get(Key.MSGPHRASE.name()); LOG.debug("{}. {}\t {}", i + 1, oid, text); final Instance instance = Instance.get(oid); final List<Instance> list; if (this.typeMapping.containsKey(instance.getType())) { list = this.typeMapping.get(instance.getType()); } else { list = new ArrayList<Instance>(); this.typeMapping.put(instance.getType(), list); } list.add(instance); final Element element = new Element().setOid(oid).setText(text); for (final Entry<String, Collection<String>> entry : _search.getResultFields().entrySet()) { for (final String name : entry.getValue()) { final String value = doc.get(name); if (value != null) { element.addField(name, value); } } } this.elements.put(instance, element); } } reader.close(); checkAccess(); ret.getElements().addAll(this.elements.values()); } catch (final IOException | QueryNodeException e) { LOG.error("Catched Exception", e); } return ret; }