How can the schema of solr be integrated with node? - node.js

I have implemented the SOLR schema.xml and it is working good.
But I don't understand why it is not getting integrated with my express app?
Means, the suggesters and filters all which I have defined is not getting applied to the express node app?
I am using solr-client package for this purpose.
`
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">fname</str>
<str name="weightField">price</str>
<str name="suggestAnalyzerFieldType">text</str>
<str name="buildOnStartup">false</str>
</lst>
<lst name="suggester">
<str name="name">altSuggester</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">lname</str>
<str name="weightField">price</str>
<str name="suggestAnalyzerFieldType">text</str>
<str name="buildOnStartup">false</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="solr.SearchHandler"
startup="lazy" >
<lst name="defaults">
<str name="suggest">true</str>
<str name="suggest.dictionary">mySuggester</str>
<str name="suggest.dictionary">altSuggester</str>
<str name="suggest.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>`
This is my suggester which i have applied on table 'fname' and 'lname'.
My doubt is, this suggester works pretty well when I query from solr admin. But when I run client.search.q(query), this suggesters seems not implemented in my express(node) app.

Related

How to colorize Log4j2 output on console in intelliJ?

I've tried to change the config file to like below but still, the output is plain white. How can I change it to any color? Like different color for each level.
Code:
import org.apache.log4j.*;
public class StartUp {
private static final Logger LOGGER = Logger.getLogger(Class.class.getName());
public static void main(String[] args) throws Exception {
LOGGER.trace("Trace Message!");
LOGGER.debug("Debug Message!");
LOGGER.info("Info Message!");
LOGGER.warn("Warn Message!");
LOGGER.error("Error Message!");
LOGGER.fatal("Fatal Message!");
Config file (log4j2.xml):
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{[%d] - %msg%n}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=black, DEBUG=green bold, TRACE=blue}"/>
</Console>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="CONSOLE"/>
</Root>
</Loggers>
</Configuration>
It seems like some default is broken in 2.10.0. By adding disableAnsi options, I could get the colors back with the last release.
<PatternLayout pattern="%highlight{...}" disableAnsi="false"/>
In the docs, it is said to default to false but it doesn't seem the case.
For IntelliJ I can highly recommend the Grep Console Plugin.
It can parse console output for logs and much more without changing the source code.
Use log4j2's stable version 2.9.1 and replace LOGGER initialization with
private static final Logger LOGGER =
LogManager.getLogger(Class.class.getName());
Additional documentation about highlighting your console appender:
https://logging.apache.org/log4j/2.x/manual/layouts.html
I took both the question and the answer and I have created a colored output similar to the default logback.
Config file (log4j2.xml):
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Properties>
<Property name="CLR">{FATAL=bright red, ERROR=red, WARN=bright yellow, INFO=Normal, DEBUG=white, TRACE=black}</Property>
<Property name="LOG_PATTERN">
%highlight{%5p- %d{yy-MM-dd HH:mm:ss.SSS}}${CLR} %clr{${sys:PID}}{magenta}%clr{-}{faint}%clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %highlight{: %m%n%xwEx}${CLR}
</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_PATTERN}" disableAnsi="false"/>
</Console>
</Appenders>
<Loggers>
<logger name="org.springframework.boot.autoconfigure.logging" level="info"/>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
I'll try to accumulate solutions for this issue, I apologize if I repeated.
What should be done to enable the color of the logs in the console (valid only for versions lo4j2 from 2.10, since jansi has been disabled by default)
1) Add jansi dependency:
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.16</version>
</dependency>
2) Add VM option: -Dlog4j.skipJansi=false
3) And don't forget add %highlight inside pattern (yaml example below):
Configuration:
Appenders:
Console:
PatternLayout:
pattern: '%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight{%-5level}{STYLE=Logback} %logger.%M - %msg%n'

Solr Autosuggest & Spell check

I am using solr 3.6. (sorry to say!) and having a hard time implementing autosuggest and spellcheck simultaneously. I am using Suggester for autosuggest and do not want to use IndexBasedSpellChecker for spell checking. Is it possible to configure autosuggest and spellcheck in a single request handler ??
For example: if I search for 'blan', solr suggests 'blanket' and retrieve search results. However if I type 'blantet' or 'blanpet', I get 0 results and no suggestions or spelling corrections. I just need spell correction from 'blantet' to 'blanket' so that I can show 'Did you mean ?' on my page.
Using standard parser.
Thanks in advance.
Not sure about version 3.6, but following configurations working for me on higher version 6.
Solr-config.xml :
<searchComponent name="spellchecktest" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">text</str>
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">name</str>
<str name="classname">solr.DirectSolrSpellChecker</str>
<str name="distanceMeasure">internal</str>
<float name="accuracy">0.5</float>
<str name="payloadField">address</str>
</lst>
<lst name="spellchecker">
<str name="name">wordbreak</str>
<str name="classname">solr.WordBreakSolrSpellChecker</str>
<str name="field">name</str>
<str name="combineWords">true</str>
<str name="breakWords">true</str>
<int name="maxChanges">10</int>
<int name="minBreakLength">2</int>
</lst>
</searchComponent>
<requestHandler name="/selectCheck" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="df">name</str>
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">false</str>
<str name="spellcheck.count">5</str>
<str name="spellcheck.alternativeTermCount">2</str>
<str name="spellcheck.maxResultsForSuggest">5</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.collateExtendedResults">true</str>
<str name="spellcheck.maxCollationTries">5</str>
<str name="spellcheck.maxCollations">3</str>
</lst>
<arr name="last-components">
<str>spellchecktest</str>
</arr>
</requestHandler>
Schema.xml
<field name="name" type="text" indexed="true" stored="true" multiValued="false"/>
<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
Local solr instance example : Letter n is missing in davider
Query :
http://localhost:8983/solr/basic/selectCheck?q=davider
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">40</int>
<lst name="params">
<str name="q">davider</str>
</lst>
</lst>
<result name="response" numFound="0" start="0" />
<lst name="spellcheck">
<lst name="suggestions">
<lst name="davider">
<int name="numFound">1</int>
<int name="startOffset">0</int>
<int name="endOffset">7</int>
<arr name="suggestion">
<str>davinder</str>
</arr>
</lst>
</lst>
<lst name="collations">
<lst name="collation">
<str name="collationQuery">davinder</str>
<int name="hits">1</int>
<lst name="misspellingsAndCorrections">
<str name="davider">davinder</str>
</lst>
</lst>
</lst>
</lst>
</response>

pyuic4 generates wrong layout?

pyuic4 seems to generate a wrong layout based on a .ui file from Qt Designer. The UI file is here:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>348</width>
<height>267</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item alignment="Qt::AlignTop">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>25</height>
</size>
</property>
<property name="text">
<string><html><head/><body><p align="center"><span style=" font-size:14pt;">Some Text</span></p></body></html></string>
</property>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="Line" name="line_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignBottom">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item alignment="Qt::AlignBottom">
<widget class="QPushButton" name="btn_customize">
<property name="text">
<string>Customize</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignBottom">
<widget class="QPushButton" name="btn_done">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
In this layout, I'm trying to align a pair of buttons with the bottom of the dialog window and some text with the top. Running pyuic4 test.ui --preview shows all objects aligned to the center horizontally, instead of to the top and bottom (and displaying this dialog from the actual python program shows the same results). By comparison, pyuic5 test.ui --preview seems to be more along the lines of what I wanted to get.
If it helps, my version of pyuic4 is 4.11.4 and I'm on Ubuntu 16.04.
Any ideas? Am I doing something wrong? Or is there perhaps a newer pyuic4 out there?
There was bug in pyuic that affected the handling of alignment in layouts. This was fixed in PyQt-5.5, which was released on the 17th July 2015. However, PyQt-4.11.4 (which is the current version) was released on the 11th June 2015 - so the fix has not been included, yet. The current development snapshot for PyQt-4.12 does includes the fix, though.
But I don't think this will really fix the issue you have. What you need to do instead is use expanding spacers. Here's how to do this using your example ui file:
Click on the horizontal button layout, and then click Break Layout (this will remove all the current layouts).
Ctrl+click the two buttons, and then click Layout Horizontally.
Click on the Dialog, and then click Layout Vertically.
Drag and drop a Vertical Spacer between the two Line widgets
Giving you this:
If you want to have some other widgets in the central area, you may need to add expanding vertical spacers above and/or below them to get the same results. Then again, if you put something like a text-box or list-widget in there, it should automatically expand to fill the available space - in which case, there wouldn't be any need for any spacers (or layout alignments).

xjc / jaxb2-commons interface binding issue, customization attached to the wrong place

I'm trying to add an interface using the jaxb2-basics artifact from the jaxb2_commons maven group.
My pom.xml contains the following dependencies
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.6.4</version>
</dependency>
and the plugin configuration looks like
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb22-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>jaxb-generate-messages-in</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<specVersion>2.2</specVersion>
<schemaLanguage>XMLSCHEMA</schemaLanguage>
<schemaDirectory>src/main/schema</schemaDirectory>
<schemaIncludes>
<include>MESSAGES-IN.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/binding</bindingDirectory>
<bindingIncludes>
<include>messages-in-binding.xjb</include>
</bindingIncludes>
<episodeFile>${project.build.directory}/generated-sources/messages-in/META-INF/jaxb-messages-in.episode</episodeFile>
<generateDirectory>${project.build.directory}/generated-sources/messages-in</generateDirectory>
<extension>true</extension>
<args>
<arg>-Xinheritance</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
</configuration>
</execution>
<execution>
<id>jaxb-generate-messages-out</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<specVersion>2.2</specVersion>
<schemaLanguage>XMLSCHEMA</schemaLanguage>
<schemaDirectory>src/main/schema</schemaDirectory>
<schemaIncludes>
<include>MESSAGES-OUT.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/binding</bindingDirectory>
<bindingIncludes>
<include>messages-out-binding.xjb</include>
</bindingIncludes>
<episodeFile>${project.build.directory}/generated-sources/messages-out/META-INF/jaxb-messages-out.episode</episodeFile>
<generateDirectory>${project.build.directory}/generated-sources/messages-out</generateDirectory>
</configuration>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
</configuration>
</plugin>
As you can see from the above, there are two invocations of xjc, which both work. Focusing on the first one, my bindings file
<jaxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jaxb:extensionBindingPrefixes="xjc"
version="1.0">
<jaxb:bindings schemaLocation="../schema/MESSAGES-IN.xsd" node="/xs:schema">
<jaxb:globalBindings typesafeEnumMaxMembers="3000">
<jaxb:serializable uid="1"/>
</jaxb:globalBindings>
<jaxb:schemaBindings>
<jaxb:package name="com.whatever.messages.request"/>
</jaxb:schemaBindings>
<jaxb:bindings node="//xs:simpleType[#name='YesOrNo']">
<jaxb:class ref="com.whatever.messages.YesOrNo"/>
</jaxb:bindings>
<jaxb:bindings noade="//xs:complexType[#name='someLogin']">
<jaxb:class name="LoginRequest">
<jaxb:javadoc><![CDATA[A Login request message.]]>
</jaxb:javadoc>
</jaxb:class>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
works like a charm; but, when I attempt to add an interface to 'LoginRequest'...
<jaxb:bindings node="//xs:complexType[#name='someLogin']">
<jaxb:class name="LoginRequest">
<jaxb:javadoc><![CDATA[A Login request message.]]>
</jaxb:javadoc>
</jaxb:class>
<inheritance:implements>com.whatever.messages.Request</inheritance:implements>
</jaxb:bindings>
I receive the error message
Error while parsing schema(s).Location [ file:/C:/Users/justme/Documents/NetBeansProjects/someproject/src/main/binding/messages-in-binding.xjb{19,42}].
com.sun.istack.SAXParseException2; systemId: file:/C:/Users/justme/Documents/NetBeansProjects/someproject/src/main/binding/messsages-in-binding.xjb; lineNumber: 19; columnNumber: 42; compiler was unable to honor this class customization. It is attached to a wrong place, or its inconsistent with other bindings.
which reports that the location was
Error while generating code.Location [ file:/C:/Users/justme/Documents/NetBeansProjects/someproject/src/main/schema/MESSAGES-IN.xsd{106693,54}].
which happens to correspond to
<xs:complexType name="someLogin" mixed="true">
...
</xs:complexType>
Now, I've tried a second directive to bind the interface to the XSD element
<xs:element name="someLogin" type="someLogin" substitutionGroup="externalMethod"/>
But I just get the same error message with the element's line number as the location.
Obviously one wants to attach an interface to a class, and all of the examples look pretty close to my bindings file, but something must be wrong.
My environment is
Apache Maven 3.0.4 (r1232337; 2012-01-17 02:44:56-0600)
Maven home: C:\Program Files\NetBeans 7.2.1\java\maven
Java version: 1.7.0_07, vendor: Oracle Corporation
Java home: C:\Program Files (x86)\Java\jdk1.7.0_07\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
Can someone explain why xjc believes the extension is operating on the wrong XSD type?
In the construction
<jaxb:bindings
node="//Xs:complexType[#name='someLogin">
...
</jaxb:bindings>
the node attribute is expected to be an XPath expression. (Or so it says at Oracle). Try adding the closing square bracket to make it one, and see if that helps.

Compiling multiple schemas into different packages using JAXB 2.1

I have a CommonTypes.xsd which I'm including in my all other XSDs using xs:include. I get
Multiple <schemaBindings> are defined for the target namespace ""
when I try to compile it into different packages using binding files. Please tell me whether there is a way to compile them into different packages. I'm using jaxb 2.1
Yeah, there is a way.
Assuming:
xsd/common/common.xsd
xsd/foo/foo.xsd
In the common directory place common.xjb:
<jxb:schemaBindings>
<jxb:package name="mypkg.common">
</jxb:package>
</jxb:schemaBindings>
In the foo directory place foo.xjb:
<jxb:schemaBindings>
<jxb:package name="mypkg.foo">
</jxb:package>
</jxb:schemaBindings>
In the build.xml file, create one xjc task for each:
<xjc destdir="${app.src}" readOnly="true" package="mypkg.common">
<schema dir="${app.schema}/common" includes="*.xsd" />
<binding dir="${app.schema}/common" includes="*.xjb" />
</xjc>
<xjc destdir="${app.src}" readOnly="true" package="mypkg.foo">
<schema dir="${app.schema}/foo" includes="*.xsd" />
<binding dir="${app.schema}/foo" includes="foo.xjb" />
</xjc>
You need to make sure that common.xsd has a targetNameSpace that is different from foo.xsd's targetNameSpace.
As stated already by Ben there is no way to do that if they have the same namespace.
But how to do it if you do have different namespaces?
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<jxb:bindings namespace="http://www.openapplications.org/oagis/9/unqualifieddatatypes/1.1" schemaLocation="oagi/Common/UNCEFACT/ATG/CoreComponents/UnqualifiedDataTypes.xsd" >
<jxb:schemaBindings>
<jxb:package name="com.test.oagi.udt"/>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings namespace="http://www.openapplications.org/oagis/9/codelists" schemaLocation="oagi/Common/OAGi/Components/CodeLists.xsd" >
<jxb:schemaBindings>
<jxb:package name="com.test.oagi.cl"/>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
but be sure you do not use the command line parameter -p, since that will override your config.
I've meet the same problem and haven't solve it yet, but I'm afraid that it can't be possible to generate XSD into differents packages :
It is not legal to have more than one <jaxb:schemaBindings> per namespace, so it is impossible to have two schemas in the same target namespace compiled into different Java packages
from Compiler Restrictions at the end of this page
but if some one find some work around, just inform us please
I know it is an old post, but, as there is no answer for the exact question, here is my proposal:
As mmoossen explained, the trick is to specify different namespaces for the XSDs.
But, adding a namespace attribute in the jxb:bindings tag doesn't work:
<jxb:bindings namespace="http://www.openapplications.org/oagis/9/unqualifieddatatypes/1.1" schemaLocation="oagi/Common/UNCEFACT/ATG/CoreComponents/UnqualifiedDataTypes.xsd" >
Instead of that, you need to add a targetNamespace attribute to the xs:schema tags of your XSDs:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
targetNamespace="some.namespace"
version="1.0">
Once done, you will be able to have 1 external customization file (.xjb) declaring different schemaBindings, each of them possibly using a different package:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:extensionBindingPrefixes="xjc annox inherit">
<jaxb:bindings schemaLocation="MyFirstXSD.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.a" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="MySecondXSD.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.b" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="MyThirdXSD.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.c" />
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Can be done as mentioned in jaxb maven plugin usage page in case of having Multiple schemas with different configuration.
Separate packages can be configured for each schema.
<packageName>se.west</packageName>
complete example configuration below:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>xjc-schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<!-- Use all XSDs under the west directory for sources here. -->
<sources>
<source>src/main/xsds/west</source>
</sources>
<!-- Package name of the generated sources. -->
<packageName>se.west</packageName>
</configuration>
</execution>
<execution>
<id>xjc-schema2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<!-- Use all XSDs under the east directory for sources here. -->
<sources>
<source>src/main/xsds/east</source>
</sources>
<!-- Package name of the generated sources. -->
<packageName>se.east</packageName>
<!--
Don't clear the output directory before generating the sources.
Clearing the output directory removes the se.west schema from above.
-->
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>

Resources